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
2 changes: 2 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ConfigType = {
APP_TOKEN_EXP: string;
APP_TOKEN_KEY: string;
PORT: string;
APP_ENV: string;
MONGODB_URI: string;
CS_API: {
US: string;
Expand All @@ -23,6 +24,7 @@ export type ConfigType = {
export const config: ConfigType = {
APP_TOKEN_EXP: "1d",
PORT: process.env.PORT!,
APP_ENV: process.env.NODE_ENV!,
APP_TOKEN_KEY: process.env.APP_TOKEN_KEY!,
MONGODB_URI: process.env.MONGODB_URI!,
...(process.env.NODE_ENV === "production" ? prodConfig : devConfig),
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type HttpErrorCodes = {
SERVER_ERROR: number;
};
export type ConstantType = {
CS_REGIONS: Array<string>;
AXIOS_TIMEOUT: number;
HTTP_CODES: HttpErrorCodes;
HTTP_TEXTS: HttpErrorTexts;
Expand All @@ -35,6 +36,7 @@ export type HttpResponseHeaders = {
};

export const constants: ConstantType = {
CS_REGIONS: ["US", "EU", "AZURE_NA", "AZURE_EU"],
AXIOS_TIMEOUT: 60 * 1000,
HTTP_CODES: {
OK: 200,
Expand Down
10 changes: 6 additions & 4 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
import mongoose from "mongoose";
import { config } from "./config";
import logger from "./utils/logger";
import MigrationModel from "./models/migration";
import AuthenticationModel from "./models/authenticationLog";
import ProjectModel from "./models/project";
import AuthenticationModel from "./models/authentication";
import AuditLogModel from "./models/auditLog";

const connectToDatabase = async () => {
try {
await mongoose.connect(config.MONGODB_URI);
await mongoose.connect(config.MONGODB_URI, {
...(config.APP_ENV === "production" ? { autoIndex: false } : {}),
});

logger.info("Connected to MongoDB");

// Create the collection's if it doesn't exist
await MigrationModel.init();
await ProjectModel.init();
await AuthenticationModel.init();
await AuditLogModel.init();
} catch (error) {
Expand Down
26 changes: 26 additions & 0 deletions src/models/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// src/models/Authentication.ts

import { Schema, model, Document } from "mongoose";
import { constants } from "../constants";

interface AuthenticationDocument extends Document {
user_id: string;
region: string;
authtoken: string;
}

const authenticationSchema = new Schema<AuthenticationDocument>(
{
user_id: { type: String, required: true },
region: { type: String, required: true, enum: constants.CS_REGIONS },
authtoken: { type: String, required: true },
},
{ timestamps: { createdAt: "created_at", updatedAt: "updated_at" } }
);

const AuthenticationModel = model<AuthenticationDocument>(
"Authentication",
authenticationSchema
);

export default AuthenticationModel;
36 changes: 0 additions & 36 deletions src/models/authenticationLog.ts

This file was deleted.

79 changes: 0 additions & 79 deletions src/models/migration.ts

This file was deleted.

75 changes: 75 additions & 0 deletions src/models/project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Schema, model, Document } from "mongoose";
import { constants } from "../constants";

interface LegacyCMS {
cms: string;
file_format: string;
import_data: string;
}

interface DestinationCMS {
stack_id: string;
org_id: string;
}

interface Modules {
legacy_cms: LegacyCMS;
destination_cms: DestinationCMS;
}

interface Migration {
name: string;
description: string;
modules: Modules;
}

interface ExecutionLog {
log_url: string;
}

interface ProjectDocument extends Document {
region: string;
org_id: string;
owner: string;
created_by: string;
name: string;
description: string;
status: boolean;
migration: Migration;
execution_log: ExecutionLog;
}

const projectSchema = new Schema<ProjectDocument>(
{
region: { type: String, required: true, enum: constants.CS_REGIONS },
org_id: { type: String, required: true },
owner: { type: String, required: true },
created_by: { type: String, required: true },
name: { type: String, required: true },
description: { type: String, required: true },
status: { type: Boolean, default: true },
migration: {
name: { type: String },
description: { type: String },
modules: {
legacy_cms: {
cms: { type: String },
file_format: { type: String },
import_data: { type: String },
},
destination_cms: {
stack_id: { type: String },
org_id: { type: String },
},
},
},
execution_log: {
log_url: { type: String },
},
},
{ timestamps: { createdAt: "created_at", updatedAt: "updated_at" } }
);

const ProjectModel = model<ProjectDocument>("Project", projectSchema);

export default ProjectModel;