Misc fixes (#5988)
* Address reports * Clean up * remove activeOn in where Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Bailey Pumfleet <bailey@pumfleet.co.uk>pull/6001/head
parent
8849d1148c
commit
8f48ecafec
|
@ -456,8 +456,14 @@ export const eventTypesRouter = router({
|
||||||
users,
|
users,
|
||||||
id,
|
id,
|
||||||
hashedLink,
|
hashedLink,
|
||||||
|
// Extract this from the input so it doesn't get saved in the db
|
||||||
|
// eslint-disable-next-line
|
||||||
|
userId,
|
||||||
|
// eslint-disable-next-line
|
||||||
|
teamId,
|
||||||
...rest
|
...rest
|
||||||
} = input;
|
} = input;
|
||||||
|
|
||||||
const data: Prisma.EventTypeUpdateInput = {
|
const data: Prisma.EventTypeUpdateInput = {
|
||||||
...rest,
|
...rest,
|
||||||
metadata: rest.metadata === null ? Prisma.DbNull : rest.metadata,
|
metadata: rest.metadata === null ? Prisma.DbNull : rest.metadata,
|
||||||
|
@ -500,11 +506,20 @@ export const eventTypesRouter = router({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (schedule) {
|
if (schedule) {
|
||||||
data.schedule = {
|
// Check that the schedule belongs to the user
|
||||||
connect: {
|
const userScheduleQuery = await ctx.prisma.schedule.findFirst({
|
||||||
|
where: {
|
||||||
|
userId: ctx.user.id,
|
||||||
id: schedule,
|
id: schedule,
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
|
if (userScheduleQuery) {
|
||||||
|
data.schedule = {
|
||||||
|
connect: {
|
||||||
|
id: schedule,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (users) {
|
if (users) {
|
||||||
|
|
|
@ -926,6 +926,32 @@ export const workflowsRouter = router({
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { eventTypeId, workflowId } = input;
|
const { eventTypeId, workflowId } = input;
|
||||||
|
|
||||||
|
// Check that workflow & event type belong to the user
|
||||||
|
const userEventType = await ctx.prisma.eventType.findFirst({
|
||||||
|
where: {
|
||||||
|
id: eventTypeId,
|
||||||
|
users: {
|
||||||
|
some: {
|
||||||
|
id: ctx.user.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!userEventType)
|
||||||
|
throw new TRPCError({ code: "UNAUTHORIZED", message: "This event type does not belong to the user" });
|
||||||
|
|
||||||
|
// Check that the workflow belongs to the user
|
||||||
|
const eventTypeWorkflow = await ctx.prisma.workflow.findFirst({
|
||||||
|
where: {
|
||||||
|
id: workflowId,
|
||||||
|
userId: ctx.user.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!eventTypeWorkflow)
|
||||||
|
throw new TRPCError({ code: "UNAUTHORIZED", message: "This event type does not belong to the user" });
|
||||||
|
|
||||||
// NOTE: This was unused
|
// NOTE: This was unused
|
||||||
// const eventType = await ctx.prisma.eventType.findFirst({
|
// const eventType = await ctx.prisma.eventType.findFirst({
|
||||||
// where: {
|
// where: {
|
||||||
|
|
Loading…
Reference in New Issue