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 @@
"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/*"
}
}
......@@ -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;
}
}
......
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(
class UserRouter {
constructor(authController, userController) {
this.authController = authController;
this.userController = userController;
this.router = express.Router();
this.initializeRoutes();
}
initializeRoutes() {
this.router.get(
"/friends",
authController.checkUserSession,
userController.getFriendsList
this.authController.checkUserSession,
this.userController.getFriendsList
);
userRouter.get(
this.router.get(
"/profile",
authController.checkUserSession,
userController.getProfile
this.authController.checkUserSession,
this.userController.getProfile
);
userRouter.post(
this.router.post(
"/addFriend",
authController.checkUserSession,
userController.addFriend
this.authController.checkUserSession,
this.userController.addFriend
);
userRouter.post(
this.router.post(
"/updateProfile",
authController.checkUserSession,
userController.updateProfile
this.authController.checkUserSession,
this.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(
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",
authController.checkUserSession,
userController.findAllUser
this.authController.checkUserSession,
this.userController.findAllUser
);
}
getRouter() {
return this.router;
}
}
module.exports = userRouter;
module.exports = UserRouter;
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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment