Skip to content

Commit 6932652

Browse files
committed
feat: minor improvements in share update procedure
1 parent 88d5eeb commit 6932652

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/trpc/routers/update/procedures/share-update.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
type UpdateSharePayloadType,
55
} from "@/jobs/share-update-email";
66
import { encode } from "@/lib/jwt";
7+
import { UpdateStatusEnum } from "@/prisma/enums";
78
import { ShareRecipientSchema } from "@/schema/contacts";
9+
import { checkMembership } from "@/server/auth";
810
import { withAuth } from "@/trpc/api/trpc";
911
import { z } from "zod";
1012

@@ -19,7 +21,9 @@ export const shareUpdateProcedure = withAuth
1921
.mutation(async ({ ctx, input }) => {
2022
const { session, db } = ctx;
2123
const { updateId, others, selectedContacts } = input;
22-
const { name: senderName, email: senderEmail, companyId } = session.user;
24+
const { name: senderName, email: senderEmail } = session.user;
25+
26+
const { companyId } = await checkMembership({ session, tx: db });
2327

2428
const update = await db.update.findUniqueOrThrow({
2529
where: {
@@ -33,7 +37,7 @@ export const shareUpdateProcedure = withAuth
3337
});
3438

3539
if (!update) {
36-
throw new Error("Data room not found");
40+
throw new Error("Update found");
3741
}
3842

3943
const company = update.company;
@@ -100,18 +104,21 @@ export const shareUpdateProcedure = withAuth
100104
};
101105

102106
await upsertManyRecipients();
103-
await db.update.update({
104-
where: {
105-
id: updateId,
106-
},
107-
data: {
108-
status: "PRIVATE",
109-
},
110-
});
107+
108+
if (update.status === UpdateStatusEnum.DRAFT) {
109+
await db.update.update({
110+
where: {
111+
id: updateId,
112+
},
113+
data: {
114+
status: "PRIVATE",
115+
},
116+
});
117+
}
111118

112119
return {
113120
success: true,
114-
message: "Data room successfully shared!",
121+
message: "Update successfully shared!",
115122
};
116123
});
117124

0 commit comments

Comments
 (0)