This commit is contained in:
KMKoushik
2024-11-02 09:00:28 +11:00
parent 4838657cc6
commit 82b747c033
7 changed files with 135 additions and 107 deletions

View File

@@ -25,3 +25,11 @@ export const getContactBook = async (c: Context, teamId: number) => {
return contactBook;
};
export const checkIsValidEmailId = async (emailId: string, teamId: number) => {
const email = await db.email.findUnique({ where: { id: emailId, teamId } });
if (!email) {
throw new UnsendApiError({ code: "NOT_FOUND", message: "Email not found" });
}
};

View File

@@ -2,6 +2,7 @@ import { createRoute, z } from "@hono/zod-openapi";
import { PublicAPIApp } from "~/server/public-api/hono";
import { getTeamFromToken } from "~/server/public-api/auth";
import { cancelEmail } from "~/server/service/email-service";
import { checkIsValidEmailId } from "../../api-utils";
const route = createRoute({
method: "post",
@@ -34,8 +35,9 @@ const route = createRoute({
function cancelScheduledEmail(app: PublicAPIApp) {
app.openapi(route, async (c) => {
await getTeamFromToken(c);
const team = await getTeamFromToken(c);
const emailId = c.req.param("emailId");
await checkIsValidEmailId(emailId, team.id);
await cancelEmail(emailId);

View File

@@ -2,6 +2,7 @@ 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",
@@ -44,9 +45,11 @@ const route = createRoute({
function updateEmailScheduledAt(app: PublicAPIApp) {
app.openapi(route, async (c) => {
await getTeamFromToken(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,
});