fix filter stuff
This commit is contained in:
@@ -11,30 +11,42 @@ const route = createRoute({
|
||||
required: true,
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({
|
||||
to: z.string().or(z.array(z.string())),
|
||||
from: z.string(),
|
||||
subject: z.string().optional().openapi({ description: 'Optional when templateId is provided' }),
|
||||
templateId: z.string().optional().openapi({ description: 'ID of a template from the dashboard' }),
|
||||
variables: z.record(z.string()).optional(),
|
||||
replyTo: 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(),
|
||||
text: z.string().optional(),
|
||||
html: z.string().optional(),
|
||||
attachments: z
|
||||
.array(
|
||||
z.object({
|
||||
filename: z.string(),
|
||||
content: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
scheduledAt: z.string().datetime().optional(),
|
||||
}).refine(
|
||||
data => !!data.subject || !!data.templateId,
|
||||
'Either subject or templateId should be passed.',
|
||||
),
|
||||
schema: z
|
||||
.object({
|
||||
to: z.string().or(z.array(z.string())),
|
||||
from: z.string(),
|
||||
subject: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({
|
||||
description: "Optional when templateId is provided",
|
||||
}),
|
||||
templateId: z
|
||||
.string()
|
||||
.optional()
|
||||
.openapi({
|
||||
description: "ID of a template from the dashboard",
|
||||
}),
|
||||
variables: z.record(z.string()).optional(),
|
||||
replyTo: 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(),
|
||||
text: z.string().optional(),
|
||||
html: z.string().optional(),
|
||||
attachments: z
|
||||
.array(
|
||||
z.object({
|
||||
filename: z.string(),
|
||||
content: z.string(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
scheduledAt: z.string().datetime().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => !!data.subject || !!data.templateId,
|
||||
"Either subject or templateId should be passed."
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -58,6 +70,7 @@ function send(app: PublicAPIApp) {
|
||||
const email = await sendEmail({
|
||||
...c.req.valid("json"),
|
||||
teamId: team.id,
|
||||
apiKeyId: team.apiKeyId,
|
||||
});
|
||||
|
||||
return c.json({ emailId: email?.id });
|
||||
|
@@ -64,7 +64,7 @@ export const getTeamFromToken = async (c: Context) => {
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
return team;
|
||||
return { ...team, apiKeyId: apiKey.id };
|
||||
};
|
||||
|
||||
const checkRateLimit = (token: string) => {
|
||||
|
@@ -46,7 +46,7 @@ export const replaceVariables = (
|
||||
Send transactional email
|
||||
*/
|
||||
export async function sendEmail(
|
||||
emailContent: EmailContent & { teamId: number }
|
||||
emailContent: EmailContent & { teamId: number; apiKeyId?: number }
|
||||
) {
|
||||
const {
|
||||
to,
|
||||
@@ -62,6 +62,7 @@ export async function sendEmail(
|
||||
cc,
|
||||
bcc,
|
||||
scheduledAt,
|
||||
apiKeyId,
|
||||
} = emailContent;
|
||||
let subject = subjectFromApiCall;
|
||||
let html = htmlFromApiCall;
|
||||
@@ -122,6 +123,7 @@ export async function sendEmail(
|
||||
attachments: attachments ? JSON.stringify(attachments) : undefined,
|
||||
scheduledAt: scheduledAtDate,
|
||||
latestStatus: scheduledAtDate ? "SCHEDULED" : "QUEUED",
|
||||
apiId: apiKeyId,
|
||||
},
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user