From ff16f98b8dac8cfda5cae89a513f240738988647 Mon Sep 17 00:00:00 2001 From: Wilson Wong Date: Mon, 16 Dec 2024 11:57:35 -0800 Subject: [PATCH] Rename migration, address review comments --- ...gging.ts => 20241216000000_017-ches-logging.ts} | 0 app/src/db/prisma/schema.prisma | 2 +- app/src/services/email.ts | 14 +++++++------- app/src/types/EmailLog.ts | 2 +- app/tests/unit/services/email.spec.ts | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) rename app/src/db/migrations/{20241206000000_016-ches-logging.ts => 20241216000000_017-ches-logging.ts} (100%) diff --git a/app/src/db/migrations/20241206000000_016-ches-logging.ts b/app/src/db/migrations/20241216000000_017-ches-logging.ts similarity index 100% rename from app/src/db/migrations/20241206000000_016-ches-logging.ts rename to app/src/db/migrations/20241216000000_017-ches-logging.ts diff --git a/app/src/db/prisma/schema.prisma b/app/src/db/prisma/schema.prisma index f545a22e..c3e94bee 100644 --- a/app/src/db/prisma/schema.prisma +++ b/app/src/db/prisma/schema.prisma @@ -511,10 +511,10 @@ model draft_code { model email_log { email_id String @id @db.Uuid + http_status Int? msg_id String? @db.Uuid to String? tx_id String? @db.Uuid - http_status Int? created_by String? @default("00000000-0000-0000-0000-000000000000") created_at DateTime? @default(now()) @db.Timestamptz(6) updated_by String? diff --git a/app/src/services/email.ts b/app/src/services/email.ts index fcbad5ea..1907c289 100644 --- a/app/src/services/email.ts +++ b/app/src/services/email.ts @@ -11,7 +11,7 @@ type Message = { to: Array; }; -type Email_data = { +type EmailData = { messages: Array; txId: string; }; @@ -100,19 +100,19 @@ const service = { /** * @function logEmail * Logs CHES email api calls - * @param {Email_data | null} data Object containing CHES response, or null on error + * @param {EmailData | null} data Object containing CHES response, or null on error * @param {Array} recipients Array of email strings * @param {status} status Http status of CHES response * @returns null */ - logEmail: async (data: Email_data | null, recipients: Array, status: number) => { + logEmail: async (data: EmailData | null, recipients: Array, status: number) => { return await prisma.$transaction(async (trx) => { return await trx.email_log.createMany({ - data: recipients.map((x) => ({ + data: recipients.map((recipient) => ({ email_id: uuidv4(), - msg_id: data?.messages?.[0].msgId ?? null, - to: x, - tx_id: data?.txId ?? null, + msg_id: data?.messages?.[0].msgId, + to: recipient, + tx_id: data?.txId, http_status: status })) }); diff --git a/app/src/types/EmailLog.ts b/app/src/types/EmailLog.ts index 4e8058d9..d4b7f8d8 100644 --- a/app/src/types/EmailLog.ts +++ b/app/src/types/EmailLog.ts @@ -1,7 +1,7 @@ import { IStamps } from '../interfaces/IStamps'; export type EmailLog = { - emailId?: string; // Primary Key + emailId: string; // Primary Key httpStatus: number; msgId?: string; to?: string; diff --git a/app/tests/unit/services/email.spec.ts b/app/tests/unit/services/email.spec.ts index b4cd67e6..834311cf 100644 --- a/app/tests/unit/services/email.spec.ts +++ b/app/tests/unit/services/email.spec.ts @@ -7,12 +7,12 @@ type Message = { to: Array; }; -type Email_data = { +type EmailData = { messages: Array; txId: string; }; -const chesResponse: Email_data = { +const chesResponse: EmailData = { messages: [{ msgId: '9c50c187-4f89-463b-afea-ededc889dd31', to: [] }], txId: '508a1f8f-b5a1-4d37-a8c9-f7d7c0a86c00' };