Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
45 changes: 26 additions & 19 deletions src/models/auditLog.ts
Original file line number Diff line number Diff line change
@@ -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<Action>({
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<AuditLogDocument>({
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<AuditLogDocument>("AuditLog", auditLogSchema);
Expand Down
19 changes: 9 additions & 10 deletions src/services/contentMapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -182,7 +182,7 @@ const getExistingContentTypes = async (req: Request) => {
]!}/content_types`,
headers: {
api_key: stackId,
authtoken : authtoken
authtoken: authtoken,
},
})
);
Expand All @@ -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 };
Expand Down