From 2fc80006acfb5bc4dffac2db944d4e2fe0185b71 Mon Sep 17 00:00:00 2001 From: hanoak20 Date: Wed, 31 Jan 2024 17:15:14 +0530 Subject: [PATCH] chore: updated the auditLog Schema. --- src/constants/index.ts | 8 ++++++++ src/models/auditLog.ts | 45 ++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/constants/index.ts b/src/constants/index.ts index 2132d3ed..ba6549bd 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -1,5 +1,13 @@ export const constants = { CS_REGIONS: ["US", "EU", "AZURE_NA", "AZURE_EU"], + MODULES: [ + "Project", + "Migration", + "Content Mapping", + "Legacy CMS", + "Destination Stack", + ], + MODULES_ACTIONS: ["Create", "Update", "Delete"], AXIOS_TIMEOUT: 60 * 1000, HTTP_CODES: { OK: 200, diff --git a/src/models/auditLog.ts b/src/models/auditLog.ts index 5f04fde7..c63ff2b5 100644 --- a/src/models/auditLog.ts +++ b/src/models/auditLog.ts @@ -1,35 +1,42 @@ +import { constants } from "../constants"; import { Schema, model, Document } from "mongoose"; interface Action { - date: string; + date: Date; user_id: string; - user_name: string; + user_first_name: string; + user_last_name: string; module: string; action: string; } -// Disabling this error until API's being implemented -// eslint-disable-next-line @typescript-eslint/no-unused-vars -interface AuditLog { - project_id: string; - actions: Action[]; -} interface AuditLogDocument extends Document { - project_id: string; + project_id: Schema.Types.ObjectId; actions: Action[]; } -const actionSchema = new Schema({ - date: { type: String, required: true }, - user_id: { type: String, required: true }, - user_name: { type: String, required: true }, - module: { type: String, required: true }, - action: { type: String, required: true }, -}); - const auditLogSchema = new Schema({ - project_id: { type: String, required: true }, - actions: { type: [actionSchema], required: true }, + project_id: { + type: Schema.Types.ObjectId, + ref: "Project", + }, + actions: { + type: [ + { + date: { type: Date, required: true }, + user_id: { type: String, required: true }, + user_first_name: { type: String, required: true }, + user_last_name: { type: String, required: true }, + module: { type: String, required: true, enum: constants.MODULES }, + action: { + type: String, + required: true, + enum: constants.MODULES_ACTIONS, + }, + }, + ], + required: true, + }, }); const AuditLogModel = model("AuditLog", auditLogSchema);