diff --git a/apps/web/src/server/public-api/api/send_email.ts b/apps/web/src/server/public-api/api/send_email.ts new file mode 100644 index 0000000..0aac629 --- /dev/null +++ b/apps/web/src/server/public-api/api/send_email.ts @@ -0,0 +1,52 @@ +import { createRoute, z } from "@hono/zod-openapi"; +import { DomainSchema } from "~/lib/zod/domain-schema"; +import { PublicAPIApp } from "../hono"; +import { db } from "../../db"; +import { getTeamFromToken } from "../auth"; +import { sendEmail } from "~/server/service/email-service"; + +const route = createRoute({ + method: "post", + path: "/v1/emails", + request: { + body: { + required: true, + content: { + "application/json": { + schema: z.object({ + to: z.string().email(), + from: z.string().email(), + subject: z.string(), + text: z.string().optional(), + html: z.string().optional(), + }), + }, + }, + }, + }, + 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, + }); + + return c.json({ emailId: email?.id }); + }); +} + +export default send; diff --git a/apps/web/src/server/public-api/index.ts b/apps/web/src/server/public-api/index.ts index 99cdccc..1bbd431 100644 --- a/apps/web/src/server/public-api/index.ts +++ b/apps/web/src/server/public-api/index.ts @@ -1,8 +1,10 @@ import { getApp } from "./hono"; import getDomains from "./api/get_domains"; +import sendEmail from "./api/send_email"; export const app = getApp(); getDomains(app); +sendEmail(app); export default app; diff --git a/apps/web/src/types/index.ts b/apps/web/src/types/index.ts index b84cf73..85ae5b7 100644 --- a/apps/web/src/types/index.ts +++ b/apps/web/src/types/index.ts @@ -2,6 +2,6 @@ export type EmailContent = { to: string; from: string; subject: string; - text: string; - html: string; + text?: string; + html?: string; };