multi tenancy stuff

This commit is contained in:
m5r
2021-08-06 01:07:15 +08:00
parent b54f9ef43c
commit d20eeb0617
51 changed files with 907 additions and 2542 deletions

View File

@ -4,15 +4,25 @@ import type { CallInstance } from "twilio/lib/rest/api/v2010/account/call";
import db, { Direction, CallStatus } from "../../../../db";
type Payload = {
customerId: string;
organizationId: string;
phoneNumberId: string;
calls: CallInstance[];
};
const insertCallsQueue = Queue<Payload>("api/queue/insert-calls", async ({ calls, customerId }) => {
const insertCallsQueue = Queue<Payload>("api/queue/insert-calls", async ({ calls, organizationId, phoneNumberId }) => {
const phoneNumber = await db.phoneNumber.findFirst({
where: { id: phoneNumberId, organizationId },
include: { organization: true },
});
if (!phoneNumber) {
return;
}
const phoneCalls = calls
.map((call) => ({
customerId,
twilioSid: call.sid,
organizationId,
phoneNumberId,
id: call.sid,
from: call.from,
to: call.to,
direction: translateDirection(call.direction),