Files
GibSend/apps/web/src/server/public-api/api/emails/send-email.ts
KM Koushik 3fe96b477f add batch email api (#149)
* add bulk email

* add bulk email api

* add batch email sdk changes
2025-04-19 21:45:17 +10:00

49 lines
1.1 KiB
TypeScript

import { createRoute, z } from "@hono/zod-openapi";
import { PublicAPIApp } from "~/server/public-api/hono";
import { getTeamFromToken } from "~/server/public-api/auth";
import { sendEmail } from "~/server/service/email-service";
import { emailSchema } from "../../schemas/email-schema";
const route = createRoute({
method: "post",
path: "/v1/emails",
request: {
body: {
required: true,
content: {
"application/json": {
schema: emailSchema,
},
},
},
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({ emailId: z.string().optional() }),
},
},
description: "Retrieve the user",
},
},
});
function send(app: PublicAPIApp) {
app.openapi(route, async (c) => {
const team = await getTeamFromToken(c);
const email = await sendEmail({
...c.req.valid("json"),
teamId: team.id,
apiKeyId: team.apiKeyId,
text: c.req.valid("json").text ?? undefined,
html: c.req.valid("json").html ?? undefined,
});
return c.json({ emailId: email?.id });
});
}
export default send;