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: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"express": "^4.18.2",
"express-validator": "^7.0.1",
"express-winston": "^4.2.0",
"helmet": "^6.0.1",
"helmet": "^7.1.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.0.4",
"winston": "^3.11.0"
Expand Down
16 changes: 16 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type HttpErrorCodes = {
export type ValidationErrors = {
INVALID_EMAIL: string;
EMAIL_LIMIT: string;
LENGTH_LIMIT: string;
STRING_REQUIRED: string;
INVALID_REGION: string;
};
Expand All @@ -30,13 +31,20 @@ export type ConstantType = {
};

export type HttpErrorTexts = {
UNAUTHORIZED: string;
INTERNAL_ERROR: string;
SOMETHING_WENT_WRONG: string;
NO_CS_USER: string;
SUCCESS_LOGIN: string;
TOKEN_ERROR: string;
LOGIN_ERROR: string;
ROUTE_ERROR: string;
NO_PROJECT: string;
MIGRATION_CREATED: string;
MIGRATION_UPDATED: string;
MIGRATION_DELETED: string;
INVALID_ID: string;
MIGRATION_EXISTS: string;
};

export type HttpResponseHeaders = {
Expand All @@ -62,6 +70,7 @@ export const constants: ConstantType = {
UNPROCESSABLE_CONTENT: 422,
},
HTTP_TEXTS: {
UNAUTHORIZED: "You're unauthorized to access this resource.",
INTERNAL_ERROR: "Internal server error, please try again later.",
SOMETHING_WENT_WRONG:
"Something went wrong while processing your request, please try again.",
Expand All @@ -70,6 +79,12 @@ export const constants: ConstantType = {
TOKEN_ERROR: "Error occurred during token generation.",
LOGIN_ERROR: "Error occurred during login",
ROUTE_ERROR: "Sorry, the requested resource is not available.",
NO_PROJECT: "resource not found with the given ID(s).",
MIGRATION_CREATED: "Project's migration created successfully.",
MIGRATION_UPDATED: "Project's migration updated successfully.",
MIGRATION_DELETED: "Project's migration deleted successfully.",
INVALID_ID: "Provided $ ID is invalid.",
MIGRATION_EXISTS: "Project's migration already exists.",
},
HTTP_RESPONSE_HEADERS: {
"Access-Control-Allow-Origin": "*",
Expand All @@ -80,6 +95,7 @@ export const constants: ConstantType = {
VALIDATION_ERRORS: {
INVALID_EMAIL: "Given email ID is invalid.",
EMAIL_LIMIT: "Email's max limit reached.",
LENGTH_LIMIT: "$'s max limit reached.",
STRING_REQUIRED: "Provided $ should be a string.",
INVALID_REGION: "Provided region doesn't exists.",
},
Expand Down
23 changes: 23 additions & 0 deletions src/controllers/org.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Request, Response } from "express";
import { orgService } from "../services/org.service";

const getAllStacks = async (req: Request, res: Response) => {
const resp = await orgService.getAllStacks(req);
res.status(resp?.status).json(resp?.data);
};

const createStack = async (req: Request, res: Response) => {
const resp = await orgService.createStack(req);
res.status(resp.status).json(resp.data);
};

const getLocales = async (req: Request, res: Response) => {
const resp = await orgService.getLocales(req);
res.status(resp.status).json(resp.data);
};

export const orgController = {
getAllStacks,
createStack,
getLocales,
};
16 changes: 8 additions & 8 deletions src/controllers/projects.migrations.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Request, Response } from "express";
import { migrationService } from "../services/projects.migrations.service";

const getMigration = async (req: Request, res: Response): Promise<void> => {
const getMigration = async (req: Request, res: Response) => {
const resp = await migrationService.getMigration(req);
res.status(200).json(resp);
res.status(resp.status).json(resp.data);
};
const createMigration = async (req: Request, res: Response): Promise<void> => {
const createMigration = async (req: Request, res: Response) => {
const resp = await migrationService.createMigration(req);
res.status(201).json(resp);
res.status(resp.status).json(resp.data);
};

const updateMigration = async (req: Request, res: Response): Promise<void> => {
const updateMigration = async (req: Request, res: Response) => {
const resp = await migrationService.updateMigration(req);
res.status(200).json(resp);
res.status(resp.status).json(resp.data);
};

const deleteMigration = async (req: Request, res: Response): Promise<void> => {
const deleteMigration = async (req: Request, res: Response) => {
const resp = await migrationService.deleteMigration(req);
res.status(200).json(resp);
res.status(resp.status).json(resp.data);
};

export const migrationController = {
Expand Down
36 changes: 22 additions & 14 deletions src/models/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ interface Modules {
}

interface Migration {
_id: Schema.Types.ObjectId;
name: string;
description: string;
created_at: Date;
updated_at: Date;
modules: Modules;
}

Expand All @@ -35,7 +38,7 @@ interface ProjectDocument extends Document {
name: string;
description: string;
status: boolean;
migration: Migration;
migration: [Migration];
execution_log: ExecutionLog;
}

Expand All @@ -48,21 +51,26 @@ const projectSchema = new Schema<ProjectDocument>(
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 },
migration: [
{
_id: Schema.Types.ObjectId,
name: { type: String },
description: { type: String },
created_at: { type: Date },
updated_at: { type: Date },
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 },
},
Expand Down
8 changes: 8 additions & 0 deletions src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ export interface LoginServiceType {
data: any;
status: number;
}

export interface MigrationQueryType {
_id: string;
"migration._id"?: string;
org_id: string;
region: string;
owner: string;
}
21 changes: 21 additions & 0 deletions src/routes/org.routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import express from "express";
import { orgController } from "../controllers/org.controller";
import { asyncRouter } from "../utils/async-router.utils";
import validator from "../validators";

const router = express.Router({ mergeParams: true });

// GET all org stacks route
router.get("/stacks", asyncRouter(orgController.getAllStacks));

// Create a new stack route
router.post(
"/stacks",
validator("project"),
asyncRouter(orgController.createStack)
);

// GET all contentstack locales route
router.get("/locales", asyncRouter(orgController.getLocales));

export default router;
13 changes: 11 additions & 2 deletions src/routes/projects.migrations.routes.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import express from "express";
import { migrationController } from "../controllers/projects.migrations.controller";
import { asyncRouter } from "../utils/async-router.utils";
import validator from "../validators";

const router = express.Router({ mergeParams: true });

// GET project's migration route
router.get("/", asyncRouter(migrationController.getMigration));

// Create a new project's migration route
router.post("/", asyncRouter(migrationController.createMigration));
router.post(
"/",
validator("project"),
asyncRouter(migrationController.createMigration)
);

// Update project's migration route
router.put("/:migrationId", asyncRouter(migrationController.updateMigration));
router.put(
"/:migrationId",
validator("project"),
asyncRouter(migrationController.updateMigration)
);

// Delete project's migration route
router.delete(
Expand Down
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import helmet from "helmet";
import authRoutes from "./routes/auth.routes";
import userRoutes from "./routes/user.routes";
import projectRoutes from "./routes/projects.routes";
import orgRoutes from "./routes/org.routes";
import { errorMiddleware } from "./middlewares/error.middleware";
import loggerMiddleware from "./middlewares/logger.middleware";
import connectToDatabase from "./database";
Expand All @@ -31,6 +32,7 @@ try {
// Routes
app.use("/v2/auth", authRoutes);
app.use("/v2/user", authenticateUser, userRoutes);
app.use("/v2/org/:orgId", authenticateUser, orgRoutes);
app.use("/v2/org/:orgId/project", authenticateUser, projectRoutes);

//For unmatched route patterns
Expand Down
2 changes: 0 additions & 2 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import AuthenticationModel from "../models/authentication";

const login = async (req: Request): Promise<LoginServiceType> => {
//TODO: 1. request validation
const userData = req?.body;

const [err, res] = await safePromise(
Expand Down Expand Up @@ -78,7 +77,6 @@ const login = async (req: Request): Promise<LoginServiceType> => {
};

const requestSms = async (req: Request): Promise<LoginServiceType> => {
//TODO: 1. request validation
const userData = req?.body;

try {
Expand Down
Loading