Add schedule api (#60)
This commit is contained in:
46
apps/web/src/server/public-api/api/emails/cancel-email.ts
Normal file
46
apps/web/src/server/public-api/api/emails/cancel-email.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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";
|
||||
|
||||
const route = createRoute({
|
||||
method: "post",
|
||||
path: "/v1/emails/{emailId}/cancel",
|
||||
request: {
|
||||
params: z.object({
|
||||
emailId: z
|
||||
.string()
|
||||
.min(3)
|
||||
.openapi({
|
||||
param: {
|
||||
name: "emailId",
|
||||
in: "path",
|
||||
},
|
||||
example: "cuiwqdj74rygf74",
|
||||
}),
|
||||
}),
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
content: {
|
||||
"application/json": {
|
||||
schema: z.object({ emailId: z.string().optional() }),
|
||||
},
|
||||
},
|
||||
description: "Retrieve the user",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
function cancelScheduledEmail(app: PublicAPIApp) {
|
||||
app.openapi(route, async (c) => {
|
||||
await getTeamFromToken(c);
|
||||
const emailId = c.req.param("emailId");
|
||||
|
||||
await cancelEmail(emailId);
|
||||
|
||||
return c.json({ emailId });
|
||||
});
|
||||
}
|
||||
|
||||
export default cancelScheduledEmail;
|
@@ -28,6 +28,7 @@ const route = createRoute({
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
scheduledAt: z.string().datetime().optional(),
|
||||
}),
|
||||
},
|
||||
},
|
||||
|
58
apps/web/src/server/public-api/api/emails/update-email.ts
Normal file
58
apps/web/src/server/public-api/api/emails/update-email.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
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";
|
||||
|
||||
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) => {
|
||||
await getTeamFromToken(c);
|
||||
const emailId = c.req.param("emailId");
|
||||
|
||||
await updateEmail(emailId, {
|
||||
scheduledAt: c.req.valid("json").scheduledAt,
|
||||
});
|
||||
|
||||
return c.json({ emailId });
|
||||
});
|
||||
}
|
||||
|
||||
export default updateEmailScheduledAt;
|
@@ -5,6 +5,8 @@ import getEmail from "./api/emails/get-email";
|
||||
import addContact from "./api/contacts/add-contact";
|
||||
import updateContactInfo from "./api/contacts/update-contact";
|
||||
import getContact from "./api/contacts/get-contact";
|
||||
import updateEmailScheduledAt from "./api/emails/update-email";
|
||||
import cancelScheduledEmail from "./api/emails/cancel-email";
|
||||
|
||||
export const app = getApp();
|
||||
|
||||
@@ -14,6 +16,8 @@ getDomains(app);
|
||||
/**Email related APIs */
|
||||
getEmail(app);
|
||||
sendEmail(app);
|
||||
updateEmailScheduledAt(app);
|
||||
cancelScheduledEmail(app);
|
||||
|
||||
/**Contact related APIs */
|
||||
addContact(app);
|
||||
|
Reference in New Issue
Block a user