Add send email API
This commit is contained in:
52
apps/web/src/server/public-api/api/send_email.ts
Normal file
52
apps/web/src/server/public-api/api/send_email.ts
Normal 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;
|
@@ -1,8 +1,10 @@
|
|||||||
import { getApp } from "./hono";
|
import { getApp } from "./hono";
|
||||||
import getDomains from "./api/get_domains";
|
import getDomains from "./api/get_domains";
|
||||||
|
import sendEmail from "./api/send_email";
|
||||||
|
|
||||||
export const app = getApp();
|
export const app = getApp();
|
||||||
|
|
||||||
getDomains(app);
|
getDomains(app);
|
||||||
|
sendEmail(app);
|
||||||
|
|
||||||
export default app;
|
export default app;
|
||||||
|
@@ -2,6 +2,6 @@ export type EmailContent = {
|
|||||||
to: string;
|
to: string;
|
||||||
from: string;
|
from: string;
|
||||||
subject: string;
|
subject: string;
|
||||||
text: string;
|
text?: string;
|
||||||
html: string;
|
html?: string;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user