fixes
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
};
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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,
|
||||
});
|
||||
|
Reference in New Issue
Block a user