Add send email API

This commit is contained in:
KMKoushik
2024-04-10 07:13:15 +10:00
parent c34d219561
commit dab3d7ad25
3 changed files with 56 additions and 2 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -2,6 +2,6 @@ export type EmailContent = {
to: string;
from: string;
subject: string;
text: string;
html: string;
text?: string;
html?: string;
};