fix: correctly use eventTriggers parsed and use Array.from (#13193)

Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
sean-brydon 2024-01-13 00:19:40 +13:00 committed by GitHub
parent 619ccf4065
commit fbc3f7b51f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -69,7 +69,12 @@ import { schemaWebhookEditBodyParams, schemaWebhookReadPublic } from "~/lib/vali
export async function patchHandler(req: NextApiRequest) {
const { prisma, query, userId, isAdmin } = req;
const { id } = schemaQueryIdAsString.parse(query);
const { eventTypeId, userId: bodyUserId, ...data } = schemaWebhookEditBodyParams.parse(req.body);
const {
eventTypeId,
userId: bodyUserId,
eventTriggers,
...data
} = schemaWebhookEditBodyParams.parse(req.body);
const args: Prisma.WebhookUpdateArgs = { where: { id }, data };
if (eventTypeId) {
@ -88,7 +93,8 @@ export async function patchHandler(req: NextApiRequest) {
}
if (args.data.eventTriggers) {
args.data.eventTriggers = [...new Set(args.data.eventTriggers)];
const eventTriggersSet = new Set(eventTriggers);
args.data.eventTriggers = Array.from(eventTriggersSet);
}
const result = await prisma.webhook.update(args);

View File

@ -66,7 +66,12 @@ import { schemaWebhookCreateBodyParams, schemaWebhookReadPublic } from "~/lib/va
*/
async function postHandler(req: NextApiRequest) {
const { userId, isAdmin, prisma } = req;
const { eventTypeId, userId: bodyUserId, ...body } = schemaWebhookCreateBodyParams.parse(req.body);
const {
eventTypeId,
userId: bodyUserId,
eventTriggers,
...body
} = schemaWebhookCreateBodyParams.parse(req.body);
const args: Prisma.WebhookCreateArgs = { data: { id: uuidv4(), ...body } };
// If no event type, we assume is for the current user. If admin we run more checks below...
@ -88,7 +93,8 @@ async function postHandler(req: NextApiRequest) {
}
if (args.data.eventTriggers) {
args.data.eventTriggers = [...new Set(args.data.eventTriggers)];
const eventTriggersSet = new Set(eventTriggers);
args.data.eventTriggers = Array.from(eventTriggersSet);
}
const data = await prisma.webhook.create(args);