fix: correctly use eventTriggers parsed and use Array.from (#13193)
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
This commit is contained in:
parent
619ccf4065
commit
fbc3f7b51f
|
@ -69,7 +69,12 @@ import { schemaWebhookEditBodyParams, schemaWebhookReadPublic } from "~/lib/vali
|
||||||
export async function patchHandler(req: NextApiRequest) {
|
export async function patchHandler(req: NextApiRequest) {
|
||||||
const { prisma, query, userId, isAdmin } = req;
|
const { prisma, query, userId, isAdmin } = req;
|
||||||
const { id } = schemaQueryIdAsString.parse(query);
|
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 };
|
const args: Prisma.WebhookUpdateArgs = { where: { id }, data };
|
||||||
|
|
||||||
if (eventTypeId) {
|
if (eventTypeId) {
|
||||||
|
@ -88,7 +93,8 @@ export async function patchHandler(req: NextApiRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.data.eventTriggers) {
|
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);
|
const result = await prisma.webhook.update(args);
|
||||||
|
|
|
@ -66,7 +66,12 @@ import { schemaWebhookCreateBodyParams, schemaWebhookReadPublic } from "~/lib/va
|
||||||
*/
|
*/
|
||||||
async function postHandler(req: NextApiRequest) {
|
async function postHandler(req: NextApiRequest) {
|
||||||
const { userId, isAdmin, prisma } = req;
|
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 } };
|
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...
|
// 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) {
|
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);
|
const data = await prisma.webhook.create(args);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user