Skip to content

Commit ef3ff9b

Browse files
committed
fix: typesafety issues with sender vs uploaderName
1 parent 7492d8b commit ef3ff9b

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

src/jobs/esign-email.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const sendEsignEmail = async (payload: ExtendedEsignPayloadType) => {
3838
const html = await render(
3939
EsignEmail({
4040
signingLink: `${baseUrl}/esign/${token}`,
41+
sender,
4142
...rest,
4243
}),
4344
);

src/jobs/esign-pdf.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export type EsignPdfPayloadType = {
3030
bucketKey: string;
3131
templateName: string;
3232
companyId: string;
33-
uploaderName: string;
3433
recipients: { email: string; name?: string | null }[];
34+
sender: { email: string; name?: string | null };
3535
};
3636

3737
export class EsignPdfJob extends BaseJob<EsignPdfPayloadType> {
@@ -47,7 +47,7 @@ export class EsignPdfJob extends BaseJob<EsignPdfPayloadType> {
4747
templateName,
4848
requestIp,
4949
userAgent,
50-
uploaderName,
50+
sender,
5151
templateId,
5252
recipients,
5353
company,
@@ -73,7 +73,7 @@ export class EsignPdfJob extends BaseJob<EsignPdfPayloadType> {
7373
requestIp,
7474
templateId,
7575
templateName,
76-
uploaderName,
76+
uploaderName: sender.name || "Captable",
7777
userAgent,
7878
});
7979
});
@@ -87,7 +87,8 @@ export class EsignPdfJob extends BaseJob<EsignPdfPayloadType> {
8787
documentName: templateName,
8888
recipient,
8989
company,
90-
senderName: uploaderName,
90+
senderName: sender.name || "Captable",
91+
senderEmail: sender.email as string,
9192
},
9293
}));
9394

src/trpc/routers/document-router/procedures/create-document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { generatePublicId } from "@/common/id";
22
import { Audit } from "@/server/audit";
33
import { checkMembership } from "@/server/auth";
4-
import { type TPrismaOrTransaction } from "@/server/db";
4+
import type { TPrismaOrTransaction } from "@/server/db";
55
import { withAuth, type withAuthTrpcContextType } from "@/trpc/api/trpc";
66
import {
77
type TypeZodCreateDocumentMutationSchema,

src/trpc/routers/template-router/procedures/sign-template.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const signTemplateProcedure = withoutAuth
2828
const bucketKey = template.bucket.key;
2929
const companyId = template.companyId;
3030
const templateName = template.name;
31+
const sender = template.uploader.user;
3132

3233
const totalGroups = new Set(
3334
template.fields.map((item) => item.recipientId),
@@ -106,7 +107,9 @@ export const signTemplateProcedure = withoutAuth
106107
},
107108
});
108109

109-
const data = values.reduce<Record<string, string>>((prev, curr) => {
110+
const data: Record<string, string> = values.reduce<
111+
Record<string, string>
112+
>((prev, curr) => {
110113
prev[curr.id] = curr.prefilledValue ?? "";
111114

112115
return prev;
@@ -133,7 +136,6 @@ export const signTemplateProcedure = withoutAuth
133136
companyId,
134137
templateName,
135138
fields: template.fields,
136-
uploaderName: "Captable, Inc.",
137139
data,
138140
templateId: template.id,
139141
db: tx,
@@ -144,6 +146,8 @@ export const signTemplateProcedure = withoutAuth
144146
email: item.email,
145147
name: item.name,
146148
})),
149+
sender,
150+
uploaderName: sender.name || "Captable",
147151
});
148152
}
149153
} else {
@@ -168,19 +172,20 @@ export const signTemplateProcedure = withoutAuth
168172
companyId,
169173
templateName,
170174
fields: template.fields,
171-
uploaderName: recipient.name ?? "unknown signer",
172175
data: input.data,
173176
templateId: template.id,
174177
db: tx,
175178
requestIp,
176179
userAgent,
180+
sender,
177181
recipients: [
178182
{
179183
email: recipient.email,
180184
name: recipient.name,
181185
},
182186
],
183187
company: template.company,
188+
uploaderName: sender.name || "Captable",
184189
});
185190
}
186191

@@ -203,9 +208,6 @@ export const signTemplateProcedure = withoutAuth
203208
});
204209
const email = nextDelivery.email;
205210

206-
const uploader = template.uploader.user;
207-
const uploaderName = uploader.name;
208-
209211
await EsignAudit.create(
210212
{
211213
action: "document.email.sent",
@@ -215,7 +217,7 @@ export const signTemplateProcedure = withoutAuth
215217
ip: ctx.requestIp,
216218
location: "",
217219
userAgent: ctx.userAgent,
218-
summary: `${uploaderName ? uploaderName : ""} sent "${
220+
summary: `${sender.name ? sender.name : ""} sent "${
219221
template.name
220222
}" to ${
221223
recipient.name ? recipient.name : ""
@@ -227,11 +229,11 @@ export const signTemplateProcedure = withoutAuth
227229
await new EsignNotificationEmailJob().emit({
228230
email,
229231
token,
232+
sender,
230233
message: template.message,
231234
documentName: template.name,
232235
recipient: nextDelivery,
233236
company: template.company,
234-
sender: uploader,
235237
});
236238
}
237239
}
@@ -249,6 +251,7 @@ interface TSignPdfOptions
249251
name: string;
250252
logo?: string | null;
251253
};
254+
sender: { name: string | null; email: string | null };
252255
recipients: { name: string | null; email: string }[];
253256
}
254257

@@ -261,7 +264,7 @@ async function signPdf({
261264
templateName,
262265
data,
263266
fields,
264-
uploaderName,
267+
sender,
265268
templateId,
266269
recipients,
267270
company,
@@ -278,9 +281,9 @@ async function signPdf({
278281
requestIp,
279282
templateId,
280283
templateName,
281-
uploaderName,
282284
userAgent,
283285
recipients,
286+
sender: sender as { email: string; name: string },
284287
company,
285288
},
286289
{ singletonKey: `esign-${templateId}`, useSingletonQueue: true },

0 commit comments

Comments
 (0)