From 566bcb892fac26e6ac4f9f86243a093e4659f16f Mon Sep 17 00:00:00 2001 From: Somnath Chattaraj Date: Thu, 10 Oct 2024 09:28:50 +0530 Subject: [PATCH] Fix docker error --- backend/Dockerfile | 1 + backend/dist/controllers/routeControllers.js | 16 ++++++++------ backend/dist/controllers/userControllers.js | 5 +++++ backend/dist/index.js | 3 +++ backend/dist/validation/registerSchema.js | 23 ++++++++++++++++++++ backend/package-lock.json | 14 ++---------- backend/package.json | 4 +--- backend/tsconfig.tsbuildinfo | 1 + 8 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 backend/dist/validation/registerSchema.js create mode 100644 backend/tsconfig.tsbuildinfo diff --git a/backend/Dockerfile b/backend/Dockerfile index f35890a..191473f 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -9,6 +9,7 @@ COPY package*.json ./ # Install dependencies RUN npm install +RUN npm install typescript # Copy the rest of the application code COPY . . diff --git a/backend/dist/controllers/routeControllers.js b/backend/dist/controllers/routeControllers.js index 05155ad..2de55a5 100644 --- a/backend/dist/controllers/routeControllers.js +++ b/backend/dist/controllers/routeControllers.js @@ -17,13 +17,8 @@ const express_async_handler_1 = __importDefault(require("express-async-handler") const prisma_1 = __importDefault(require("../lib/prisma")); const searchRoom = (0, express_async_handler_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () { // @ts-ignore - const userId = req.user.user_id; + const user_id = req.user.user_id; const rooms = yield prisma_1.default.chatRoom.findMany({ - where: { - users: { - some: { user_id: userId } - } - }, select: { id: true, users: { @@ -34,6 +29,13 @@ const searchRoom = (0, express_async_handler_1.default)((req, res) => __awaiter( } } }); - res.status(200).json(rooms); + const updateArray = rooms.map(room => { + const otherUsers = room.users.filter(user => user.user_id != user_id); + return { + roomId: room.id, + usernames: otherUsers.map(user => user.username) + }; + }); + res.status(200).json(updateArray); })); exports.searchRoom = searchRoom; diff --git a/backend/dist/controllers/userControllers.js b/backend/dist/controllers/userControllers.js index b19dd2c..2c35679 100644 --- a/backend/dist/controllers/userControllers.js +++ b/backend/dist/controllers/userControllers.js @@ -20,6 +20,7 @@ const bcrypt_1 = __importDefault(require("bcrypt")); const sendMail_1 = __importDefault(require("../mail/sendMail")); const academic_email_verifier_1 = require("academic-email-verifier"); const checkAcademic_1 = __importDefault(require("../mail/checkAcademic")); +const registerSchema_1 = require("../validation/registerSchema"); const googleSignInOrSignUp = (0, express_async_handler_1.default)( //@ts-ignore (req, res) => __awaiter(void 0, void 0, void 0, function* () { @@ -131,6 +132,10 @@ const registerUser = (0, express_async_handler_1.default)((req, res) => __awaite res.status(400).json({ message: "Please provide all fields" }); return; } + if (registerSchema_1.registerSchema.safeParse(req.body).success === false) { + res.status(400).json({ message: registerSchema_1.registerSchema.safeParse(req.body).error }); + return; + } const userExists = yield prisma_1.default.user.findFirst({ where: { OR: [{ email: email }, { username: username }], diff --git a/backend/dist/index.js b/backend/dist/index.js index a2f5d10..477d762 100644 --- a/backend/dist/index.js +++ b/backend/dist/index.js @@ -37,6 +37,9 @@ app.use("/api/chat", chatRoutes_1.default); // Use the chat routes app.use("/api/post", postsRoutes_1.default); app.use('/api/room', roomRoutes_1.default); // app.get("/api/post/communities", getCommunities); +app.get('/api/logout', (req, res) => { + res.clearCookie('Authorization').json({ message: 'Logged out successfully' }); +}); app.get("/", (req, res) => { res.send("Backend is running"); }); diff --git a/backend/dist/validation/registerSchema.js b/backend/dist/validation/registerSchema.js new file mode 100644 index 0000000..2aa20ad --- /dev/null +++ b/backend/dist/validation/registerSchema.js @@ -0,0 +1,23 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.registerSchema = void 0; +const zod_1 = __importDefault(require("zod")); +exports.registerSchema = zod_1.default.object({ + email: zod_1.default.string().email({ message: "Invalid email address " }), + username: zod_1.default + .string() + .min(3, { message: "Username must be at least 3 characters long " }), + password: zod_1.default + .string() + .min(6, { message: "Password must be at least 6 characters long. " }) + .regex(/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$/, { + message: "Password must contain at least one uppercase letter, one lowercase letter, one digit, and one special character ", + }), + collegeName: zod_1.default.string().optional(), + courseName: zod_1.default.string().optional(), + isOnline: zod_1.default.boolean(), + location: zod_1.default.string().optional(), +}); diff --git a/backend/package-lock.json b/backend/package-lock.json index 1fef492..7f209f7 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -29,15 +29,13 @@ "nodemailer": "^6.9.14", "nodemon": "^3.1.4", "prettier": "^3.3.3", - "tsc": "^2.0.4", "ws": "^8.18.0", "zod": "^3.23.8" }, "devDependencies": { "@types/express": "^4.17.21", "prisma": "^5.20.0", - "ts-node": "^10.9.2", - "typescript": "^5.6.3" + "ts-node": "^10.9.2" } }, "node_modules/@cspotcode/source-map-support": { @@ -2817,15 +2815,6 @@ } } }, - "node_modules/tsc": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/tsc/-/tsc-2.0.4.tgz", - "integrity": "sha512-fzoSieZI5KKJVBYGvwbVZs/J5za84f2lSTLPYf6AGiIf43tZ3GNrI1QzTLcjtyDDP4aLxd46RTZq1nQxe7+k5Q==", - "license": "MIT", - "bin": { - "tsc": "bin/tsc" - } - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", @@ -2855,6 +2844,7 @@ "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/backend/package.json b/backend/package.json index a988bdd..3aa09c8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -40,14 +40,12 @@ "nodemailer": "^6.9.14", "nodemon": "^3.1.4", "prettier": "^3.3.3", - "tsc": "^2.0.4", "ws": "^8.18.0", "zod": "^3.23.8" }, "devDependencies": { "@types/express": "^4.17.21", "prisma": "^5.20.0", - "ts-node": "^10.9.2", - "typescript": "^5.6.3" + "ts-node": "^10.9.2" } } diff --git a/backend/tsconfig.tsbuildinfo b/backend/tsconfig.tsbuildinfo new file mode 100644 index 0000000..a640289 --- /dev/null +++ b/backend/tsconfig.tsbuildinfo @@ -0,0 +1 @@ +{"root":["./src/index.ts","./src/seed.ts","./src/server.ts","./src/controllers/chatcontrollers.ts","./src/controllers/postcontroller.ts","./src/controllers/ratingcontroller.ts","./src/controllers/reviewcontrollers.ts","./src/controllers/routecontrollers.ts","./src/controllers/usercontrollers.ts","./src/lib/convertor.ts","./src/lib/prisma.ts","./src/mail/checkacademic.ts","./src/mail/sendmail.ts","./src/mail/sort.ts","./src/middleware/checkauth.ts","./src/middleware/moderation.ts","./src/routes/chatroutes.ts","./src/routes/mruote.ts","./src/routes/postsroutes.ts","./src/routes/ratingroute.ts","./src/routes/reviewroutes.ts","./src/routes/roomroutes.ts","./src/routes/userroutes.ts","./src/validation/registerschema.ts"],"version":"5.6.3"} \ No newline at end of file