4
4
type UpdateSharePayloadType ,
5
5
} from "@/jobs/share-update-email" ;
6
6
import { encode } from "@/lib/jwt" ;
7
+ import { UpdateStatusEnum } from "@/prisma/enums" ;
7
8
import { ShareRecipientSchema } from "@/schema/contacts" ;
9
+ import { checkMembership } from "@/server/auth" ;
8
10
import { withAuth } from "@/trpc/api/trpc" ;
9
11
import { z } from "zod" ;
10
12
@@ -19,7 +21,9 @@ export const shareUpdateProcedure = withAuth
19
21
. mutation ( async ( { ctx, input } ) => {
20
22
const { session, db } = ctx ;
21
23
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 } ) ;
23
27
24
28
const update = await db . update . findUniqueOrThrow ( {
25
29
where : {
@@ -33,7 +37,7 @@ export const shareUpdateProcedure = withAuth
33
37
} ) ;
34
38
35
39
if ( ! update ) {
36
- throw new Error ( "Data room not found" ) ;
40
+ throw new Error ( "Update found" ) ;
37
41
}
38
42
39
43
const company = update . company ;
@@ -100,18 +104,21 @@ export const shareUpdateProcedure = withAuth
100
104
} ;
101
105
102
106
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
+ }
111
118
112
119
return {
113
120
success : true ,
114
- message : "Data room successfully shared!" ,
121
+ message : "Update successfully shared!" ,
115
122
} ;
116
123
} ) ;
117
124
0 commit comments