Connect user to new event type

pull/9078/head
Joe Au-Yeung 2022-10-03 14:26:00 -04:00
parent d14c8404e7
commit 362d8ca769
1 changed files with 22 additions and 2 deletions

View File

@ -98,12 +98,32 @@ async function createOrlistAllEventTypes(
return; return;
} }
if (!isAdmin) { if (!isAdmin) {
const data = await prisma.eventType.create({ data: { ...safe.data, userId } }); const data = await prisma.eventType.create({
data: {
...safe.data,
userId,
users: {
connect: {
id: userId,
},
},
},
});
const event_type = schemaEventTypeReadPublic.parse(data); const event_type = schemaEventTypeReadPublic.parse(data);
if (data) res.status(201).json({ event_type, message: "EventType created successfully" }); if (data) res.status(201).json({ event_type, message: "EventType created successfully" });
} else { } else {
// if admin don't re-set userId from input // if admin don't re-set userId from input
const data = await prisma.eventType.create({ data: { ...safe.data } }); const data = await prisma.eventType.create({
data: {
...safe.data,
...(!safe.data.userId && { userId }),
users: {
connect: {
id: safe.data.userId || userId,
},
},
},
});
const event_type = schemaEventTypeReadPublic.parse(data); const event_type = schemaEventTypeReadPublic.parse(data);
if (data) res.status(201).json({ event_type, message: "EventType created successfully" }); if (data) res.status(201).json({ event_type, message: "EventType created successfully" });
} }