2021-07-31 15:57:43 +00:00
|
|
|
import { resolver } from "blitz";
|
|
|
|
import { z } from "zod";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
2021-07-31 15:57:43 +00:00
|
|
|
import db from "../../../db";
|
2021-08-05 17:07:15 +00:00
|
|
|
import getCurrentUser from "../../users/queries/get-current-user";
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
const Body = z.object({
|
|
|
|
twilioAccountSid: z.string(),
|
|
|
|
twilioAuthToken: z.string(),
|
2021-07-31 15:57:43 +00:00
|
|
|
});
|
2021-07-31 14:33:18 +00:00
|
|
|
|
|
|
|
export default resolver.pipe(
|
|
|
|
resolver.zod(Body),
|
|
|
|
resolver.authorize(),
|
|
|
|
async ({ twilioAccountSid, twilioAuthToken }, context) => {
|
2021-08-05 17:07:15 +00:00
|
|
|
const user = await getCurrentUser(null, context);
|
|
|
|
if (!user) {
|
2021-08-02 10:02:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-05 17:07:15 +00:00
|
|
|
const organizationId = user.memberships[0]!.id;
|
|
|
|
await db.organization.update({
|
|
|
|
where: { id: organizationId },
|
2021-07-31 14:33:18 +00:00
|
|
|
data: {
|
2021-08-05 17:07:15 +00:00
|
|
|
twilioAccountSid: twilioAccountSid,
|
|
|
|
twilioAuthToken: twilioAuthToken,
|
2021-07-31 14:33:18 +00:00
|
|
|
},
|
2021-07-31 15:57:43 +00:00
|
|
|
});
|
2021-08-01 12:04:04 +00:00
|
|
|
},
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|