shellphone.app/app/onboarding/mutations/set-twilio-api-fields.ts
2021-08-06 01:14:19 +08:00

31 lines
691 B
TypeScript

import { resolver } from "blitz";
import { z } from "zod";
import db from "../../../db";
import getCurrentUser from "../../users/queries/get-current-user";
const Body = z.object({
twilioAccountSid: z.string(),
twilioAuthToken: z.string(),
});
export default resolver.pipe(
resolver.zod(Body),
resolver.authorize(),
async ({ twilioAccountSid, twilioAuthToken }, context) => {
const user = await getCurrentUser(null, context);
if (!user) {
return;
}
const organizationId = user.memberships[0]!.id;
await db.organization.update({
where: { id: organizationId },
data: {
twilioAccountSid: twilioAccountSid,
twilioAuthToken: twilioAuthToken,
},
});
},
);