Skip to content

Commit

Permalink
feat: implement email receiver api service
Browse files Browse the repository at this point in the history
- initialize types, api routes, and service methods for email receivers

Signed-off-by: Ryan Hopper-Lowe <[email protected]>
  • Loading branch information
ryanhopperlowe committed Jan 7, 2025
1 parent ce837ac commit 71e4f9c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ui/admin/app/lib/model/email-receivers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EntityMeta } from "~/lib/model/primitives";

type EmailReceiverBase = {
name: string;
description: string;
alias?: string;
workflow: string;
allowedSenders?: string[];
};

export type EmailReceiver = EntityMeta & EmailReceiverBase;

export type CreateEmailReceiver = EmailReceiverBase;
export type UpdateEmailReceiver = EmailReceiverBase;
8 changes: 8 additions & 0 deletions ui/admin/app/lib/routers/apiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ export const ApiRoutes = {
updateCronJob: (cronJobId: string) =>
buildUrl(`/cronjobs/${cronJobId}`),
},
emailReceivers: {
getEmailReceivers: () => buildUrl("/email-receivers"),
getEmailReceiverById: (id: string) =>
buildUrl(`/email-receivers/${id}`),
createEmailReceiver: () => buildUrl(`/email-receivers`),
updateEmailReceiver: (id: string) => buildUrl(`/email-receivers/${id}`),
deleteEmailReceiver: (id: string) => buildUrl(`/email-receivers/${id}`),
},
version: () => buildUrl("/version"),
};

Expand Down
72 changes: 72 additions & 0 deletions ui/admin/app/lib/service/api/EmailRecieverApiService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {
CreateEmailReceiver,
EmailReceiver,
UpdateEmailReceiver,
} from "~/lib/model/email-receivers";
import { EntityList } from "~/lib/model/primitives";
import { ApiRoutes } from "~/lib/routers/apiRoutes";
import { request } from "~/lib/service/api/primitives";

async function getEmailReceivers() {
const { data } = await request<EntityList<EmailReceiver>>({
url: ApiRoutes.emailReceivers.getEmailReceivers().url,
});

return data ?? [];
}
getEmailReceivers.key = () => ({
url: ApiRoutes.emailReceivers.getEmailReceivers().url,
});

async function getEmailReceiverById(id: string) {
const { data } = await request<EmailReceiver>({
url: ApiRoutes.emailReceivers.getEmailReceiverById(id).url,
});

return data;
}
getEmailReceiverById.key = (id: Nullish<string>) => {
if (!id) return null;

return {
url: ApiRoutes.emailReceivers.getEmailReceiverById(id).url,
};
};

async function createEmailReceiver(emailReceiver: CreateEmailReceiver) {
const { data } = await request<EmailReceiver>({
url: ApiRoutes.emailReceivers.createEmailReceiver().url,
method: "POST",
data: emailReceiver,
});

return data;
}

async function updateEmailReceiver(
id: string,
emailReceiver: UpdateEmailReceiver
) {
const { data } = await request<EmailReceiver>({
url: ApiRoutes.emailReceivers.updateEmailReceiver(id).url,
method: "PUT",
data: emailReceiver,
});

return data;
}

async function deleteEmailReceiver(id: string) {
await request({
url: ApiRoutes.emailReceivers.deleteEmailReceiver(id).url,
method: "DELETE",
});
}

export const EmailReceiverApiService = {
getEmailReceivers,
getEmailReceiverById,
createEmailReceiver,
updateEmailReceiver,
deleteEmailReceiver,
};

0 comments on commit 71e4f9c

Please sign in to comment.