Files
GibSend/apps/web/src/server/public-api/api/emails/update-email.ts
KMKoushik 82b747c033 fixes
2024-11-02 09:00:28 +11:00

62 lines
1.4 KiB
TypeScript

import { createRoute, z } from "@hono/zod-openapi";
import { PublicAPIApp } from "~/server/public-api/hono";
import { getTeamFromToken } from "~/server/public-api/auth";
import { updateEmail } from "~/server/service/email-service";
import { checkIsValidEmailId } from "../../api-utils";
const route = createRoute({
method: "patch",
path: "/v1/emails/{emailId}",
request: {
params: z.object({
emailId: z
.string()
.min(3)
.openapi({
param: {
name: "emailId",
in: "path",
},
example: "cuiwqdj74rygf74",
}),
}),
body: {
required: true,
content: {
"application/json": {
schema: z.object({
scheduledAt: z.string().datetime(),
}),
},
},
},
},
responses: {
200: {
content: {
"application/json": {
schema: z.object({ emailId: z.string().optional() }),
},
},
description: "Retrieve the user",
},
},
});
function updateEmailScheduledAt(app: PublicAPIApp) {
app.openapi(route, async (c) => {
const team = await getTeamFromToken(c);
const emailId = c.req.param("emailId");
await checkIsValidEmailId(emailId, team.id);
await updateEmail(emailId, {
scheduledAt: c.req.valid("json").scheduledAt,
});
return c.json({ emailId });
});
}
export default updateEmailScheduledAt;