diff --git a/src/constants/index.ts b/src/constants/index.ts index d3a78616..20556d70 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); diff --git a/src/services/contentMapper.service.ts b/src/services/contentMapper.service.ts index a974b385..0c55fdb1 100644 --- a/src/services/contentMapper.service.ts +++ b/src/services/contentMapper.service.ts @@ -172,8 +172,8 @@ const getExistingContentTypes = async (req: Request) => { token_payload?.region, token_payload?.user_id ); - const project = await ProjectModel.findById(projectId) - const stackId = project?.migration?.modules?.destination_cms?.stack_id + const project = await ProjectModel.findById(projectId); + const stackId = project?.migration?.modules?.destination_cms?.stack_id; const [err, res] = await safePromise( https({ method: "GET", @@ -182,7 +182,7 @@ const getExistingContentTypes = async (req: Request) => { ]!}/content_types`, headers: { api_key: stackId, - authtoken : authtoken + authtoken: authtoken, }, }) ); @@ -193,14 +193,13 @@ const getExistingContentTypes = async (req: Request) => { status: err.response.status, }; - const contentTypes = res.data.content_types.map((singleCT:any)=>{ + const contentTypes = res.data.content_types.map((singleCT: any) => { return { - title : singleCT.title, - uid : singleCT.uid, - schema : singleCT.schema - } - }) - + title: singleCT.title, + uid: singleCT.uid, + schema: singleCT.schema, + }; + }); //Add logic to get Project from DB return { contentTypes };