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";
|
|
|
|
import getCurrentCustomer from "../../customers/queries/get-current-customer";
|
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-07-31 15:57:43 +00:00
|
|
|
const customer = await getCurrentCustomer(null, context);
|
|
|
|
const customerId = customer!.id;
|
2021-07-31 14:33:18 +00:00
|
|
|
await db.customer.update({
|
|
|
|
where: { id: customerId },
|
|
|
|
data: {
|
|
|
|
accountSid: twilioAccountSid,
|
|
|
|
authToken: twilioAuthToken,
|
|
|
|
},
|
2021-07-31 15:57:43 +00:00
|
|
|
});
|
2021-07-31 14:33:18 +00:00
|
|
|
}
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|