From c1c3fa06a39654521021cf6ec46e8f89db9038b2 Mon Sep 17 00:00:00 2001 From: m5r Date: Sun, 22 May 2022 01:18:06 +0200 Subject: [PATCH] fix /twilio/authorize --- app/routes/twilio.authorize.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/routes/twilio.authorize.ts b/app/routes/twilio.authorize.ts index 554ab0e..fa978b4 100644 --- a/app/routes/twilio.authorize.ts +++ b/app/routes/twilio.authorize.ts @@ -24,9 +24,18 @@ export const loader: LoaderFunction = async ({ request }) => { const twilioMainAccount = await twilioClient.api.accounts(twilioMainAccountSid).fetch(); console.log("twilioSubAccount", twilioSubAccount); console.log("twilioAccount", twilioMainAccount); - const twilioAccount = await db.twilioAccount.update({ + const twilioAccount = await db.twilioAccount.upsert({ where: { organizationId: organization.id }, - data: { + create: { + organization: { + connect: { id: organization.id }, + }, + subAccountSid: twilioSubAccount.sid, + subAccountAuthToken: encrypt(twilioSubAccount.authToken), + accountSid: twilioMainAccount.sid, + accountAuthToken: encrypt(twilioMainAccount.authToken), + }, + update: { subAccountSid: twilioSubAccount.sid, subAccountAuthToken: encrypt(twilioSubAccount.authToken), accountSid: twilioMainAccount.sid,