make app usable without account, remove extra stuff
This commit is contained in:
@ -1,51 +0,0 @@
|
||||
import { MembershipRole } from "@prisma/client";
|
||||
|
||||
import { Queue } from "~/utils/queue.server";
|
||||
import db from "~/utils/db.server";
|
||||
import logger from "~/utils/logger.server";
|
||||
import { deleteOrganizationEntities } from "~/utils/organization.server";
|
||||
|
||||
type Payload = {
|
||||
userId: string;
|
||||
};
|
||||
|
||||
export default Queue<Payload>("delete user data", async ({ data }) => {
|
||||
const { userId } = data;
|
||||
const user = await db.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: {
|
||||
memberships: {
|
||||
include: { organization: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
user.memberships.map(async (membership) => {
|
||||
switch (membership.role) {
|
||||
case MembershipRole.OWNER: {
|
||||
await deleteOrganizationEntities(membership.organization);
|
||||
break;
|
||||
}
|
||||
case MembershipRole.USER: {
|
||||
await db.membership.delete({ where: { id: membership.id } });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
try {
|
||||
await db.user.delete({ where: { id: user.id } });
|
||||
} catch (error: any) {
|
||||
if (error.code === "P2025") {
|
||||
logger.warn("Could not delete user because it has already been deleted");
|
||||
return;
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
});
|
@ -1,4 +1,3 @@
|
||||
import deleteUserDataQueue from "./delete-user-data.server";
|
||||
import fetchPhoneCallsQueue from "./fetch-phone-calls.server";
|
||||
import insertPhoneCallsQueue from "./insert-phone-calls.server";
|
||||
import fetchMessagesQueue from "./fetch-messages.server";
|
||||
@ -7,7 +6,6 @@ import setTwilioWebhooksQueue from "./set-twilio-webhooks.server";
|
||||
import setTwilioApiKeyQueue from "./set-twilio-api-key.server";
|
||||
|
||||
export default [
|
||||
deleteUserDataQueue,
|
||||
fetchPhoneCallsQueue,
|
||||
insertPhoneCallsQueue,
|
||||
fetchMessagesQueue,
|
||||
|
@ -16,15 +16,7 @@ export default Queue<Payload>("notify incoming message", async ({ data }) => {
|
||||
where: { id: phoneNumberId },
|
||||
select: {
|
||||
twilioAccount: {
|
||||
include: {
|
||||
organization: {
|
||||
select: {
|
||||
memberships: {
|
||||
select: { notificationSubscription: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
include: { notificationSubscriptions: true },
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -32,10 +24,7 @@ export default Queue<Payload>("notify incoming message", async ({ data }) => {
|
||||
logger.warn(`No phone number found with id=${phoneNumberId}`);
|
||||
return;
|
||||
}
|
||||
const subscriptions = phoneNumber.twilioAccount.organization.memberships.flatMap(
|
||||
(membership) => membership.notificationSubscription,
|
||||
);
|
||||
|
||||
const subscriptions = phoneNumber.twilioAccount.notificationSubscriptions;
|
||||
const twilioClient = getTwilioClient(phoneNumber.twilioAccount);
|
||||
const message = await twilioClient.messages.get(messageSid).fetch();
|
||||
const payload = buildMessageNotificationPayload(message);
|
||||
|
@ -8,13 +8,12 @@ import { decrypt } from "~/utils/encryption";
|
||||
|
||||
type Payload = {
|
||||
phoneNumberId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
|
||||
export default Queue<Payload>("set twilio webhooks", async ({ data }) => {
|
||||
const { phoneNumberId, organizationId } = data;
|
||||
const { phoneNumberId } = data;
|
||||
const phoneNumber = await db.phoneNumber.findFirst({
|
||||
where: { id: phoneNumberId, twilioAccount: { organizationId } },
|
||||
where: { id: phoneNumberId },
|
||||
include: {
|
||||
twilioAccount: {
|
||||
select: { accountSid: true, twimlAppSid: true, authToken: true },
|
||||
@ -33,7 +32,7 @@ export default Queue<Payload>("set twilio webhooks", async ({ data }) => {
|
||||
|
||||
await Promise.all([
|
||||
db.twilioAccount.update({
|
||||
where: { organizationId },
|
||||
where: { accountSid: twilioAccount.accountSid },
|
||||
data: { twimlAppSid },
|
||||
}),
|
||||
twilioClient.incomingPhoneNumbers.get(phoneNumber.id).update({
|
||||
|
Reference in New Issue
Block a user