From 9ec9c0edb2cc752b0eb545b89c55fe90b39d7b95 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Mon, 28 Oct 2024 17:55:53 +0800 Subject: [PATCH 1/4] Shift code into src --- backend/user-service/package.json | 4 ++-- backend/user-service/{ => src}/app.ts | 0 backend/user-service/{ => src}/config/firebase.ts | 0 backend/user-service/{ => src}/config/multer.ts | 0 backend/user-service/{ => src}/config/redis.ts | 0 .../user-service/{ => src}/controller/auth-controller.ts | 0 .../user-service/{ => src}/controller/user-controller.ts | 0 .../{ => src}/middleware/basic-access-control.ts | 0 backend/user-service/{ => src}/model/repository.ts | 0 backend/user-service/{ => src}/model/user-model.ts | 0 backend/user-service/{ => src}/routes/auth-routes.ts | 0 backend/user-service/{ => src}/routes/user-routes.ts | 0 backend/user-service/{ => src}/scripts/seed.ts | 0 backend/user-service/{ => src}/server.ts | 2 +- backend/user-service/{ => src}/types/request.d.ts | 0 backend/user-service/{ => src}/utils/constants.ts | 0 backend/user-service/{ => src}/utils/mailer.ts | 0 backend/user-service/{ => src}/utils/utils.ts | 0 backend/user-service/{ => src}/utils/validators.ts | 0 backend/user-service/tests/authRoutes.spec.ts | 4 ++-- backend/user-service/tests/setup.ts | 2 +- backend/user-service/tests/userRoutes.spec.ts | 6 +++--- 22 files changed, 9 insertions(+), 9 deletions(-) rename backend/user-service/{ => src}/app.ts (100%) rename backend/user-service/{ => src}/config/firebase.ts (100%) rename backend/user-service/{ => src}/config/multer.ts (100%) rename backend/user-service/{ => src}/config/redis.ts (100%) rename backend/user-service/{ => src}/controller/auth-controller.ts (100%) rename backend/user-service/{ => src}/controller/user-controller.ts (100%) rename backend/user-service/{ => src}/middleware/basic-access-control.ts (100%) rename backend/user-service/{ => src}/model/repository.ts (100%) rename backend/user-service/{ => src}/model/user-model.ts (100%) rename backend/user-service/{ => src}/routes/auth-routes.ts (100%) rename backend/user-service/{ => src}/routes/user-routes.ts (100%) rename backend/user-service/{ => src}/scripts/seed.ts (100%) rename backend/user-service/{ => src}/server.ts (92%) rename backend/user-service/{ => src}/types/request.d.ts (100%) rename backend/user-service/{ => src}/utils/constants.ts (100%) rename backend/user-service/{ => src}/utils/mailer.ts (100%) rename backend/user-service/{ => src}/utils/utils.ts (100%) rename backend/user-service/{ => src}/utils/validators.ts (100%) diff --git a/backend/user-service/package.json b/backend/user-service/package.json index 4c192f9dc3..0cdabebd0f 100644 --- a/backend/user-service/package.json +++ b/backend/user-service/package.json @@ -5,8 +5,8 @@ "main": "app.ts", "type": "module", "scripts": { - "start": "tsx server.ts", - "dev": "tsx watch server.ts", + "start": "tsx ./src/server.ts", + "dev": "tsx watch ./src/server.ts", "lint": "eslint .", "test": "cross-env NODE_ENV=test jest --detectOpenHandles", "test:watch": "cross-env NODE_ENV=test jest --watch --detectOpenHandles" diff --git a/backend/user-service/app.ts b/backend/user-service/src/app.ts similarity index 100% rename from backend/user-service/app.ts rename to backend/user-service/src/app.ts diff --git a/backend/user-service/config/firebase.ts b/backend/user-service/src/config/firebase.ts similarity index 100% rename from backend/user-service/config/firebase.ts rename to backend/user-service/src/config/firebase.ts diff --git a/backend/user-service/config/multer.ts b/backend/user-service/src/config/multer.ts similarity index 100% rename from backend/user-service/config/multer.ts rename to backend/user-service/src/config/multer.ts diff --git a/backend/user-service/config/redis.ts b/backend/user-service/src/config/redis.ts similarity index 100% rename from backend/user-service/config/redis.ts rename to backend/user-service/src/config/redis.ts diff --git a/backend/user-service/controller/auth-controller.ts b/backend/user-service/src/controller/auth-controller.ts similarity index 100% rename from backend/user-service/controller/auth-controller.ts rename to backend/user-service/src/controller/auth-controller.ts diff --git a/backend/user-service/controller/user-controller.ts b/backend/user-service/src/controller/user-controller.ts similarity index 100% rename from backend/user-service/controller/user-controller.ts rename to backend/user-service/src/controller/user-controller.ts diff --git a/backend/user-service/middleware/basic-access-control.ts b/backend/user-service/src/middleware/basic-access-control.ts similarity index 100% rename from backend/user-service/middleware/basic-access-control.ts rename to backend/user-service/src/middleware/basic-access-control.ts diff --git a/backend/user-service/model/repository.ts b/backend/user-service/src/model/repository.ts similarity index 100% rename from backend/user-service/model/repository.ts rename to backend/user-service/src/model/repository.ts diff --git a/backend/user-service/model/user-model.ts b/backend/user-service/src/model/user-model.ts similarity index 100% rename from backend/user-service/model/user-model.ts rename to backend/user-service/src/model/user-model.ts diff --git a/backend/user-service/routes/auth-routes.ts b/backend/user-service/src/routes/auth-routes.ts similarity index 100% rename from backend/user-service/routes/auth-routes.ts rename to backend/user-service/src/routes/auth-routes.ts diff --git a/backend/user-service/routes/user-routes.ts b/backend/user-service/src/routes/user-routes.ts similarity index 100% rename from backend/user-service/routes/user-routes.ts rename to backend/user-service/src/routes/user-routes.ts diff --git a/backend/user-service/scripts/seed.ts b/backend/user-service/src/scripts/seed.ts similarity index 100% rename from backend/user-service/scripts/seed.ts rename to backend/user-service/src/scripts/seed.ts diff --git a/backend/user-service/server.ts b/backend/user-service/src/server.ts similarity index 92% rename from backend/user-service/server.ts rename to backend/user-service/src/server.ts index 78b033c119..606e155603 100644 --- a/backend/user-service/server.ts +++ b/backend/user-service/src/server.ts @@ -1,7 +1,7 @@ import http from "http"; import index from "./app.ts"; import dotenv from "dotenv"; -import { connectToDB } from "./model/repository"; +import { connectToDB } from "./model/repository.ts"; import { seedAdminAccount } from "./scripts/seed.ts"; import { connectRedis } from "./config/redis.ts"; diff --git a/backend/user-service/types/request.d.ts b/backend/user-service/src/types/request.d.ts similarity index 100% rename from backend/user-service/types/request.d.ts rename to backend/user-service/src/types/request.d.ts diff --git a/backend/user-service/utils/constants.ts b/backend/user-service/src/utils/constants.ts similarity index 100% rename from backend/user-service/utils/constants.ts rename to backend/user-service/src/utils/constants.ts diff --git a/backend/user-service/utils/mailer.ts b/backend/user-service/src/utils/mailer.ts similarity index 100% rename from backend/user-service/utils/mailer.ts rename to backend/user-service/src/utils/mailer.ts diff --git a/backend/user-service/utils/utils.ts b/backend/user-service/src/utils/utils.ts similarity index 100% rename from backend/user-service/utils/utils.ts rename to backend/user-service/src/utils/utils.ts diff --git a/backend/user-service/utils/validators.ts b/backend/user-service/src/utils/validators.ts similarity index 100% rename from backend/user-service/utils/validators.ts rename to backend/user-service/src/utils/validators.ts diff --git a/backend/user-service/tests/authRoutes.spec.ts b/backend/user-service/tests/authRoutes.spec.ts index 0951730310..044d45f900 100644 --- a/backend/user-service/tests/authRoutes.spec.ts +++ b/backend/user-service/tests/authRoutes.spec.ts @@ -1,8 +1,8 @@ import bcrypt from "bcrypt"; import { faker } from "@faker-js/faker"; import supertest from "supertest"; -import app from "../app"; -import UserModel from "../model/user-model"; +import app from "../src/app"; +import UserModel from "../src/model/user-model"; jest.setTimeout(10000); diff --git a/backend/user-service/tests/setup.ts b/backend/user-service/tests/setup.ts index a85ae2e02f..2916bfcd4b 100644 --- a/backend/user-service/tests/setup.ts +++ b/backend/user-service/tests/setup.ts @@ -1,5 +1,5 @@ import mongoose from "mongoose"; -import redisClient from "../config/redis"; +import redisClient from "../src/config/redis"; beforeAll(async () => { const mongoUri = diff --git a/backend/user-service/tests/userRoutes.spec.ts b/backend/user-service/tests/userRoutes.spec.ts index 9ff12dc3ea..81cdad43da 100644 --- a/backend/user-service/tests/userRoutes.spec.ts +++ b/backend/user-service/tests/userRoutes.spec.ts @@ -2,8 +2,8 @@ import bcrypt from "bcrypt"; import mongoose from "mongoose"; import { faker } from "@faker-js/faker"; import supertest from "supertest"; -import app from "../app"; -import UserModel from "../model/user-model"; +import app from "../src/app"; +import UserModel from "../src/model/user-model"; const request = supertest(app); @@ -13,7 +13,7 @@ faker.seed(0); const mockSendMail = jest.fn(); -jest.mock("../middleware/basic-access-control", () => ({ +jest.mock("../src/middleware/basic-access-control", () => ({ verifyAccessToken: jest.fn((req, res, next) => { req.user = { id: new mongoose.Types.ObjectId().toHexString(), From 5d72e9f843e74d7763b228e943a83285f1747ad9 Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Mon, 28 Oct 2024 18:04:13 +0800 Subject: [PATCH 2/4] Shift code into src --- backend/question-service/package.json | 4 ++-- backend/question-service/{ => src}/app.ts | 2 +- backend/question-service/{ => src}/config/db.ts | 0 backend/question-service/{ => src}/config/firebase.ts | 0 backend/question-service/{ => src}/config/multer.ts | 0 .../question-service/src/controllers/questionController.ts | 2 +- backend/question-service/src/scripts/seed.ts | 2 +- backend/question-service/{ => src}/server.ts | 0 backend/question-service/src/utils/utils.ts | 6 ++++-- backend/question-service/tests/questionRoutes.spec.ts | 2 +- 10 files changed, 10 insertions(+), 8 deletions(-) rename backend/question-service/{ => src}/app.ts (96%) rename backend/question-service/{ => src}/config/db.ts (100%) rename backend/question-service/{ => src}/config/firebase.ts (100%) rename backend/question-service/{ => src}/config/multer.ts (100%) rename backend/question-service/{ => src}/server.ts (100%) diff --git a/backend/question-service/package.json b/backend/question-service/package.json index 9bdfda8e2e..16bd165501 100644 --- a/backend/question-service/package.json +++ b/backend/question-service/package.json @@ -5,8 +5,8 @@ "type": "module", "scripts": { "seed": "tsx src/scripts/seed.ts", - "start": "tsx server.ts", - "dev": "tsx watch server.ts", + "start": "tsx src/server.ts", + "dev": "tsx watch src/server.ts", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/question-service/app.ts b/backend/question-service/src/app.ts similarity index 96% rename from backend/question-service/app.ts rename to backend/question-service/src/app.ts index 594545818f..86066cbe45 100644 --- a/backend/question-service/app.ts +++ b/backend/question-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import fs from "fs"; import cors from "cors"; -import questionRoutes from "./src/routes/questionRoutes.ts"; +import questionRoutes from "./routes/questionRoutes.ts"; dotenv.config(); diff --git a/backend/question-service/config/db.ts b/backend/question-service/src/config/db.ts similarity index 100% rename from backend/question-service/config/db.ts rename to backend/question-service/src/config/db.ts diff --git a/backend/question-service/config/firebase.ts b/backend/question-service/src/config/firebase.ts similarity index 100% rename from backend/question-service/config/firebase.ts rename to backend/question-service/src/config/firebase.ts diff --git a/backend/question-service/config/multer.ts b/backend/question-service/src/config/multer.ts similarity index 100% rename from backend/question-service/config/multer.ts rename to backend/question-service/src/config/multer.ts diff --git a/backend/question-service/src/controllers/questionController.ts b/backend/question-service/src/controllers/questionController.ts index 1d01443cbc..10ece6e04e 100644 --- a/backend/question-service/src/controllers/questionController.ts +++ b/backend/question-service/src/controllers/questionController.ts @@ -17,7 +17,7 @@ import { MONGO_OBJ_ID_MALFORMED_MESSAGE, } from "../utils/constants.ts"; -import { upload } from "../../config/multer"; +import { upload } from "../config/multer.ts"; import { uploadFileToFirebase } from "../utils/utils"; export const createQuestion = async ( diff --git a/backend/question-service/src/scripts/seed.ts b/backend/question-service/src/scripts/seed.ts index 16929ab792..a2cf05e2f7 100644 --- a/backend/question-service/src/scripts/seed.ts +++ b/backend/question-service/src/scripts/seed.ts @@ -1,5 +1,5 @@ import { exit } from "process"; -import connectDB from "../../config/db"; +import connectDB from "../config/db"; import Question from "../models/Question"; export async function seedQuestions() { diff --git a/backend/question-service/server.ts b/backend/question-service/src/server.ts similarity index 100% rename from backend/question-service/server.ts rename to backend/question-service/src/server.ts diff --git a/backend/question-service/src/utils/utils.ts b/backend/question-service/src/utils/utils.ts index f0f5286f64..8e93776d23 100644 --- a/backend/question-service/src/utils/utils.ts +++ b/backend/question-service/src/utils/utils.ts @@ -1,7 +1,7 @@ import mongoose from "mongoose"; import { v4 as uuidv4 } from "uuid"; -import { bucket } from "../../config/firebase"; +import { bucket } from "../config/firebase"; import Question from "../models/Question"; @@ -50,5 +50,7 @@ export const uploadFileToFirebase = async ( }; export const sortAlphabetically = (arr: string[]) => { - return [...arr].sort((a, b) => a.localeCompare(b, undefined, { sensitivity: 'base' })); + return [...arr].sort((a, b) => + a.localeCompare(b, undefined, { sensitivity: "base" }), + ); }; diff --git a/backend/question-service/tests/questionRoutes.spec.ts b/backend/question-service/tests/questionRoutes.spec.ts index e538f57458..5e59c20ccd 100644 --- a/backend/question-service/tests/questionRoutes.spec.ts +++ b/backend/question-service/tests/questionRoutes.spec.ts @@ -1,7 +1,7 @@ import { NextFunction, Request, Response } from "express"; import { faker } from "@faker-js/faker"; import supertest from "supertest"; -import app from "../app"; +import app from "../src/app"; import Question from "../src/models/Question"; import { DUPLICATE_QUESTION_MESSAGE, From d9190c46aeb71f91121bf2b02ce3c1d34f1bc4ee Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Mon, 28 Oct 2024 18:14:41 +0800 Subject: [PATCH 3/4] Shift code into src --- backend/matching-service/package.json | 4 ++-- backend/matching-service/{ => src}/app.ts | 2 +- backend/matching-service/{ => src}/config/rabbitmq.ts | 6 +++--- backend/matching-service/src/handlers/matchHandler.ts | 2 +- backend/matching-service/src/handlers/websocketHandler.ts | 2 +- backend/matching-service/{ => src}/server.ts | 2 +- backend/matching-service/src/utils/mq_utils.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename backend/matching-service/{ => src}/app.ts (93%) rename backend/matching-service/{ => src}/config/rabbitmq.ts (90%) rename backend/matching-service/{ => src}/server.ts (91%) diff --git a/backend/matching-service/package.json b/backend/matching-service/package.json index eff673d2ff..c3648f2f53 100644 --- a/backend/matching-service/package.json +++ b/backend/matching-service/package.json @@ -4,8 +4,8 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx server.ts", - "dev": "tsx watch server.ts", + "start": "tsx src/server.ts", + "dev": "tsx watch src/server.ts", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/matching-service/app.ts b/backend/matching-service/src/app.ts similarity index 93% rename from backend/matching-service/app.ts rename to backend/matching-service/src/app.ts index 7ebe04c04e..8eb5924f6b 100644 --- a/backend/matching-service/app.ts +++ b/backend/matching-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import fs from "fs"; import cors from "cors"; -import matchingRoutes from "./src/routes/matchingRoutes.ts"; +import matchingRoutes from "./routes/matchingRoutes.ts"; dotenv.config(); diff --git a/backend/matching-service/config/rabbitmq.ts b/backend/matching-service/src/config/rabbitmq.ts similarity index 90% rename from backend/matching-service/config/rabbitmq.ts rename to backend/matching-service/src/config/rabbitmq.ts index 03a84d8f15..9841e3808b 100644 --- a/backend/matching-service/config/rabbitmq.ts +++ b/backend/matching-service/src/config/rabbitmq.ts @@ -1,8 +1,8 @@ import amqplib, { Connection } from "amqplib"; import dotenv from "dotenv"; -import { matchUsers } from "../src/utils/mq_utils"; -import { MatchRequestItem } from "../src/handlers/matchHandler"; -import { Complexities, Categories, Languages } from "../src/utils/constants"; +import { matchUsers } from "../utils/mq_utils"; +import { MatchRequestItem } from "../handlers/matchHandler"; +import { Complexities, Categories, Languages } from "../utils/constants"; dotenv.config(); diff --git a/backend/matching-service/src/handlers/matchHandler.ts b/backend/matching-service/src/handlers/matchHandler.ts index e80b1748fb..2174fdea6c 100644 --- a/backend/matching-service/src/handlers/matchHandler.ts +++ b/backend/matching-service/src/handlers/matchHandler.ts @@ -1,5 +1,5 @@ import { v4 as uuidv4 } from "uuid"; -import { sendToQueue } from "../../config/rabbitmq"; +import { sendToQueue } from "../config/rabbitmq"; import { sendMatchFound } from "./websocketHandler"; interface Match { diff --git a/backend/matching-service/src/handlers/websocketHandler.ts b/backend/matching-service/src/handlers/websocketHandler.ts index 4f705777a9..47843f26dd 100644 --- a/backend/matching-service/src/handlers/websocketHandler.ts +++ b/backend/matching-service/src/handlers/websocketHandler.ts @@ -8,7 +8,7 @@ import { MatchUser, getMatchByUid, } from "./matchHandler"; -import { io } from "../../server"; +import { io } from "../server"; import { v4 as uuidv4 } from "uuid"; enum MatchEvents { diff --git a/backend/matching-service/server.ts b/backend/matching-service/src/server.ts similarity index 91% rename from backend/matching-service/server.ts rename to backend/matching-service/src/server.ts index fdc1933659..fc627d78ca 100644 --- a/backend/matching-service/server.ts +++ b/backend/matching-service/src/server.ts @@ -1,6 +1,6 @@ import http from "http"; import app, { allowedOrigins } from "./app.ts"; -import { handleWebsocketMatchEvents } from "./src/handlers/websocketHandler.ts"; +import { handleWebsocketMatchEvents } from "./handlers/websocketHandler.ts"; import { Server } from "socket.io"; import { connectToRabbitMq } from "./config/rabbitmq.ts"; diff --git a/backend/matching-service/src/utils/mq_utils.ts b/backend/matching-service/src/utils/mq_utils.ts index f1082a935e..457c4bd04e 100644 --- a/backend/matching-service/src/utils/mq_utils.ts +++ b/backend/matching-service/src/utils/mq_utils.ts @@ -1,4 +1,4 @@ -import { getPendingRequests } from "../../config/rabbitmq"; +import { getPendingRequests } from "../config/rabbitmq"; import { createMatch, MatchRequestItem } from "../handlers/matchHandler"; import { isActiveRequest, isUserConnected } from "../handlers/websocketHandler"; From 7df047d442618cf9ecfd28e0e575db86cfabfd2d Mon Sep 17 00:00:00 2001 From: Nicole Lim Date: Mon, 28 Oct 2024 18:23:29 +0800 Subject: [PATCH 4/4] Shift code into src --- backend/collab-service/package.json | 4 ++-- backend/collab-service/{ => src}/app.ts | 2 +- backend/collab-service/{ => src}/config/redis.ts | 0 backend/collab-service/src/handlers/websocketHandler.ts | 4 ++-- backend/collab-service/{ => src}/server.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename backend/collab-service/{ => src}/app.ts (94%) rename backend/collab-service/{ => src}/config/redis.ts (100%) rename backend/collab-service/{ => src}/server.ts (89%) diff --git a/backend/collab-service/package.json b/backend/collab-service/package.json index 9a3bf330e0..8660a0f62b 100644 --- a/backend/collab-service/package.json +++ b/backend/collab-service/package.json @@ -4,8 +4,8 @@ "main": "server.ts", "type": "module", "scripts": { - "start": "tsx server.ts", - "dev": "tsx watch server.ts", + "start": "tsx src/server.ts", + "dev": "tsx watch src/server.ts", "test": "cross-env NODE_ENV=test && jest", "test:watch": "cross-env NODE_ENV=test && jest --watch", "lint": "eslint ." diff --git a/backend/collab-service/app.ts b/backend/collab-service/src/app.ts similarity index 94% rename from backend/collab-service/app.ts rename to backend/collab-service/src/app.ts index 0ccce35d8a..9aaff3af65 100644 --- a/backend/collab-service/app.ts +++ b/backend/collab-service/src/app.ts @@ -5,7 +5,7 @@ import yaml from "yaml"; import swaggerUi from "swagger-ui-express"; import cors from "cors"; -import collabRoutes from "./src/routes/collabRoutes.ts"; +import collabRoutes from "./routes/collabRoutes.ts"; dotenv.config(); diff --git a/backend/collab-service/config/redis.ts b/backend/collab-service/src/config/redis.ts similarity index 100% rename from backend/collab-service/config/redis.ts rename to backend/collab-service/src/config/redis.ts diff --git a/backend/collab-service/src/handlers/websocketHandler.ts b/backend/collab-service/src/handlers/websocketHandler.ts index 3a109d07f4..5a806a70d4 100644 --- a/backend/collab-service/src/handlers/websocketHandler.ts +++ b/backend/collab-service/src/handlers/websocketHandler.ts @@ -1,6 +1,6 @@ import { Socket } from "socket.io"; -import { io } from "../../server"; -import redisClient from "../../config/redis"; +import { io } from "../server"; +import redisClient from "../config/redis"; enum CollabEvents { // Receive diff --git a/backend/collab-service/server.ts b/backend/collab-service/src/server.ts similarity index 89% rename from backend/collab-service/server.ts rename to backend/collab-service/src/server.ts index c8ac91418f..d16a00c6ec 100644 --- a/backend/collab-service/server.ts +++ b/backend/collab-service/src/server.ts @@ -1,6 +1,6 @@ import http from "http"; import app, { allowedOrigins } from "./app.ts"; -import { handleWebsocketCollabEvents } from "./src/handlers/websocketHandler"; +import { handleWebsocketCollabEvents } from "./handlers/websocketHandler.ts"; import { Server } from "socket.io"; import { connectRedis } from "./config/redis.ts";