allow text to be nullable (#142)
This commit is contained in:
@@ -15,24 +15,18 @@ const route = createRoute({
|
|||||||
.object({
|
.object({
|
||||||
to: z.string().or(z.array(z.string())),
|
to: z.string().or(z.array(z.string())),
|
||||||
from: z.string(),
|
from: z.string(),
|
||||||
subject: z
|
subject: z.string().optional().openapi({
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.openapi({
|
|
||||||
description: "Optional when templateId is provided",
|
description: "Optional when templateId is provided",
|
||||||
}),
|
}),
|
||||||
templateId: z
|
templateId: z.string().optional().openapi({
|
||||||
.string()
|
|
||||||
.optional()
|
|
||||||
.openapi({
|
|
||||||
description: "ID of a template from the dashboard",
|
description: "ID of a template from the dashboard",
|
||||||
}),
|
}),
|
||||||
variables: z.record(z.string()).optional(),
|
variables: z.record(z.string()).optional(),
|
||||||
replyTo: z.string().or(z.array(z.string())).optional(),
|
replyTo: z.string().or(z.array(z.string())).optional(),
|
||||||
cc: z.string().or(z.array(z.string())).optional(),
|
cc: z.string().or(z.array(z.string())).optional(),
|
||||||
bcc: z.string().or(z.array(z.string())).optional(),
|
bcc: z.string().or(z.array(z.string())).optional(),
|
||||||
text: z.string().optional(),
|
text: z.string().optional().nullable(),
|
||||||
html: z.string().optional(),
|
html: z.string().optional().nullable(),
|
||||||
attachments: z
|
attachments: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
@@ -71,6 +65,8 @@ function send(app: PublicAPIApp) {
|
|||||||
...c.req.valid("json"),
|
...c.req.valid("json"),
|
||||||
teamId: team.id,
|
teamId: team.id,
|
||||||
apiKeyId: team.apiKeyId,
|
apiKeyId: team.apiKeyId,
|
||||||
|
text: c.req.valid("json").text ?? undefined,
|
||||||
|
html: c.req.valid("json").html ?? undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
return c.json({ emailId: email?.id });
|
return c.json({ emailId: email?.id });
|
||||||
|
@@ -99,6 +99,13 @@ export async function sendEmail(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!text && !html) {
|
||||||
|
throw new UnsendApiError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: "Either text or html is required",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const scheduledAtDate = scheduledAt ? new Date(scheduledAt) : undefined;
|
const scheduledAtDate = scheduledAt ? new Date(scheduledAt) : undefined;
|
||||||
const delay = scheduledAtDate
|
const delay = scheduledAtDate
|
||||||
? Math.max(0, scheduledAtDate.getTime() - Date.now())
|
? Math.max(0, scheduledAtDate.getTime() - Date.now())
|
||||||
|
Reference in New Issue
Block a user