Skip to content
Snippets Groups Projects
Commit accd68bc authored by DongJae Oh's avatar DongJae Oh
Browse files

feat(user): refactoring

parent a43bd19a
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"imports": { "imports": {
"#dongception": "./src/common/dongpring/dongception.js" "#dongception": "./src/common/dongpring/dongception.js",
"#module/*": "./src/modules/*",
"#repository/*": "./src/repositories/*",
"#common/*": "./src/common/*"
} }
} }
...@@ -146,6 +146,13 @@ class ChatService { ...@@ -146,6 +146,13 @@ class ChatService {
return []; return [];
} }
response.nextId = response.messages[response.messages.length - 1].id; 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; return response;
} }
} }
......
const express = require("express"); const express = require("express");
const UserService = require("./user.service");
const UserController = require("./user.controller"); class UserRouter {
const UserRepository = require("../../repositories/user.repository"); constructor(authController, userController) {
const db = require("../../common/database"); this.authController = authController;
const userRepository = new UserRepository(db); this.userController = userController;
const userService = new UserService(userRepository); this.router = express.Router();
const userController = new UserController(userService); this.initializeRoutes();
}
const AuthController = require("./../auth/auth.controller");
const AuthService = require("./../auth/auth.service"); initializeRoutes() {
const AuthRepository = require("./../../repositories/auth.repository"); this.router.get(
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", "/friends",
authController.checkUserSession, this.authController.checkUserSession,
userController.getFriendsList this.userController.getFriendsList
); );
userRouter.get(
this.router.get(
"/profile", "/profile",
authController.checkUserSession, this.authController.checkUserSession,
userController.getProfile this.userController.getProfile
); );
userRouter.post(
this.router.post(
"/addFriend", "/addFriend",
authController.checkUserSession, this.authController.checkUserSession,
userController.addFriend this.userController.addFriend
); );
userRouter.post(
this.router.post(
"/updateProfile", "/updateProfile",
authController.checkUserSession, this.authController.checkUserSession,
userController.updateProfile this.userController.updateProfile
); );
userRouter.get("/searchUser", userController.searchUser);
userRouter.post("/addUser", userController.addUser); this.router.get("/searchUser", this.userController.searchUser);
userRouter.post("/deleteUser/:userId", userController.deleteUser); this.router.post("/addUser", this.userController.addUser);
userRouter.get("/findUser", userController.findUserByEmail); this.router.post("/deleteUser/:userId", this.userController.deleteUser);
userRouter.get( this.router.get("/findUser", this.userController.findUserByEmail);
this.router.get(
"/findAll", "/findAll",
authController.checkUserSession, this.authController.checkUserSession,
userController.findAllUser this.userController.findAllUser
); );
}
getRouter() {
return this.router;
}
}
module.exports = userRouter; module.exports = UserRouter;
const express = require("express"); 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(); const router = express.Router();
router.use("/auth", authRouter); router.use("/auth", authRouter);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment