diff --git a/package.json b/package.json index 433cd8e102f72ec8a7df960cff07a988a630047e..2e2ef0fd416963d781354bf00b37ac33b3859b55 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,9 @@ "author": "", "license": "ISC", "imports": { - "#dongception": "./src/common/dongpring/dongception.js" + "#dongception": "./src/common/dongpring/dongception.js", + "#module/*": "./src/modules/*", + "#repository/*": "./src/repositories/*", + "#common/*": "./src/common/*" } } diff --git a/src/modules/chat/chat.service.js b/src/modules/chat/chat.service.js index 0990c0540cccee7f4ceb00bf0bda587077c4535d..a745e3172d38a141b1eaf2b925d2fc1263d073c6 100644 --- a/src/modules/chat/chat.service.js +++ b/src/modules/chat/chat.service.js @@ -146,6 +146,13 @@ class ChatService { return []; } response.nextId = response.messages[response.messages.length - 1].id; + response.messages.sort((a, b) => { + // 두 객체 모두에서 timestamp가 null이거나 undefined인 경우를 처리 + if (!a.timestamp) return 1; // a가 null이거나 undefined면 b를 앞으로 + if (!b.timestamp) return -1; // b가 null이거나 undefined면 a를 앞으로 + + return new Date(a.timestamp) - new Date(b.timestamp); + }); return response; } } diff --git a/src/modules/user/user.routes.js b/src/modules/user/user.routes.js index 1fb6bf789bf4351355025b2d6537d4c39ad1cc81..73589673e011622dae8e133b1dfe0f0fdc47d901 100644 --- a/src/modules/user/user.routes.js +++ b/src/modules/user/user.routes.js @@ -1,51 +1,53 @@ const express = require("express"); -const UserService = require("./user.service"); -const UserController = require("./user.controller"); -const UserRepository = require("../../repositories/user.repository"); -const db = require("../../common/database"); -const userRepository = new UserRepository(db); -const userService = new UserService(userRepository); -const userController = new UserController(userService); - -const AuthController = require("./../auth/auth.controller"); -const AuthService = require("./../auth/auth.service"); -const AuthRepository = require("./../../repositories/auth.repository"); -const jwtController = require("./../../common/jwt/jwt.controller"); - -const authRepository = new AuthRepository(db); -const authService = new AuthService(authRepository, jwtController); -const authController = new AuthController(authService); - -const userRouter = express.Router(); - -userRouter.get( - "/friends", - authController.checkUserSession, - userController.getFriendsList -); -userRouter.get( - "/profile", - authController.checkUserSession, - userController.getProfile -); -userRouter.post( - "/addFriend", - authController.checkUserSession, - userController.addFriend -); -userRouter.post( - "/updateProfile", - authController.checkUserSession, - userController.updateProfile -); -userRouter.get("/searchUser", userController.searchUser); -userRouter.post("/addUser", userController.addUser); -userRouter.post("/deleteUser/:userId", userController.deleteUser); -userRouter.get("/findUser", userController.findUserByEmail); -userRouter.get( - "/findAll", - authController.checkUserSession, - userController.findAllUser -); - -module.exports = userRouter; + +class UserRouter { + constructor(authController, userController) { + this.authController = authController; + this.userController = userController; + this.router = express.Router(); + this.initializeRoutes(); + } + + initializeRoutes() { + this.router.get( + "/friends", + this.authController.checkUserSession, + this.userController.getFriendsList + ); + + this.router.get( + "/profile", + this.authController.checkUserSession, + this.userController.getProfile + ); + + this.router.post( + "/addFriend", + this.authController.checkUserSession, + this.userController.addFriend + ); + + this.router.post( + "/updateProfile", + this.authController.checkUserSession, + this.userController.updateProfile + ); + + this.router.get("/searchUser", this.userController.searchUser); + this.router.post("/addUser", this.userController.addUser); + this.router.post("/deleteUser/:userId", this.userController.deleteUser); + this.router.get("/findUser", this.userController.findUserByEmail); + + this.router.get( + "/findAll", + this.authController.checkUserSession, + this.userController.findAllUser + ); + } + + getRouter() { + return this.router; + } +} + +module.exports = UserRouter; diff --git a/src/route.js b/src/route.js index 9c4c825538169b1b0ae0ed277e746a8d69d4252a..b7b7442ff026526b5e54211e306ea2398ad412ae 100644 --- a/src/route.js +++ b/src/route.js @@ -1,8 +1,27 @@ const express = require("express"); -const authRouter = require("./modules/auth/auth.routes"); -const userRouter = require("./modules/user/user.routes"); -const chatRouter = require("./modules/chat/chat.routes"); +const UserService = require("#module/user/user.service.js"); +const UserController = require("#module/user/user.controller.js"); +const UserRepository = require("#repository/user.repository.js"); +const db = require("#common/database/index.js"); +const userRepository = new UserRepository(db); +const userService = new UserService(userRepository); +const userController = new UserController(userService); + +const AuthController = require("#module/auth/auth.controller.js"); +const AuthService = require("#module/auth/auth.service.js"); +const AuthRepository = require("#repository/auth.repository.js"); +const jwtController = require("#common/jwt/jwt.controller.js"); + +const authRepository = new AuthRepository(db); +const authService = new AuthService(authRepository, jwtController); +const authController = new AuthController(authService); + +const authRouter = require("#module/auth/auth.routes.js"); +const UserRouter = require("#module/user/user.routes.js"); +const chatRouter = require("#module/chat/chat.routes.js"); + +const userRouter = new UserRouter(authController, userController).getRouter(); const router = express.Router(); router.use("/auth", authRouter);