From df9d468700ecf6477d4296939b750f260b0a7892 Mon Sep 17 00:00:00 2001 From: adriano Date: Mon, 23 Oct 2023 09:09:14 -0300 Subject: [PATCH] =?UTF-8?q?feat(backend)=20cria=C3=A7=C3=A3o=20da=20contro?= =?UTF-8?q?ler=20que=20retorna=20todos=20usuarios=20pelo=20profile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/controllers/UserController.ts | 75 +++++++++++++---------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/backend/src/controllers/UserController.ts b/backend/src/controllers/UserController.ts index c41b912..239a3eb 100644 --- a/backend/src/controllers/UserController.ts +++ b/backend/src/controllers/UserController.ts @@ -10,11 +10,15 @@ import UpdateUserService from "../services/UserServices/UpdateUserService"; import ShowUserService from "../services/UserServices/ShowUserService"; import DeleteUserService from "../services/UserServices/DeleteUserService"; -import ListUserParamiterService from "../services/UserServices/ListUserParamiterService" +import ListUserParamiterService from "../services/UserServices/ListUserParamiterService"; import User from "../models/User"; -import { startWhoIsOnlineMonitor, stopWhoIsOnlineMonitor } from "../helpers/WhoIsOnlineMonitor" -import UserOnlineTIme from '../models/UserOnlineTime' +import { + startWhoIsOnlineMonitor, + stopWhoIsOnlineMonitor +} from "../helpers/WhoIsOnlineMonitor"; +import UserOnlineTIme from "../models/UserOnlineTime"; +import ListUser from "../services/UserServices/ListUserParamiterService"; type IndexQuery = { searchParam: string; @@ -31,13 +35,12 @@ export const index = async (req: Request, res: Response): Promise => { profile }); - if (req.user.profile !== 'master') { - + if (req.user.profile !== "master") { let auxUsers: Array = []; for (var user of users) { - if (user.profile !== 'master') { - auxUsers.push(user) + if (user.profile !== "master") { + auxUsers.push(user); } } @@ -46,34 +49,44 @@ export const index = async (req: Request, res: Response): Promise => { return res.json({ users, count, hasMore }); - - // const { users, count, hasMore } = await ListUsersService({ // searchParam, // pageNumber // }); - // if(req.user.profile!=='master'){ + // if(req.user.profile!=='master'){ - // let auxUsers: Array = []; + // let auxUsers: Array = []; - // for (var user of users) { + // for (var user of users) { // if(user.profile!=='master'){ // auxUsers.push(user) - // } - // } + // } + // } - // return res.json({ users: auxUsers, count, hasMore }); - // } + // return res.json({ users: auxUsers, count, hasMore }); + // } // return res.json({ users, count, hasMore }); }; +export const all = async (req: Request, res: Response): Promise => { + const { profile } = req.query as IndexQuery; + + const users = await ListUser({ + profile + }); + + return res.json({ users }); +}; export const store = async (req: Request, res: Response): Promise => { const { email, password, name, profile, queueIds } = req.body; - if (req.url === "/signup" && (await CheckSettingsHelper("userCreation")) === "disabled") { + if ( + req.url === "/signup" && + (await CheckSettingsHelper("userCreation")) === "disabled" + ) { throw new AppError("ERR_USER_CREATION_DISABLED", 403); } else if (req.url !== "/signup" && req.user.profile !== "master") { throw new AppError("ERR_NO_PERMISSION", 403); @@ -93,9 +106,8 @@ export const store = async (req: Request, res: Response): Promise => { user }); - // await stopWhoIsOnlineMonitor() - await startWhoIsOnlineMonitor() + await startWhoIsOnlineMonitor(); return res.status(200).json(user); }; @@ -108,17 +120,18 @@ export const show = async (req: Request, res: Response): Promise => { return res.status(200).json(user); }; - -export const logoutUser = async (req: Request, res: Response): Promise => { +export const logoutUser = async ( + req: Request, + res: Response +): Promise => { const { userId } = req.params; - - await stopWhoIsOnlineMonitor() + await stopWhoIsOnlineMonitor(); let onlineTime = { userId: userId, - status: 'logout...' - } + status: "logout..." + }; const io = getIO(); io.emit("onlineStatus", { @@ -126,13 +139,12 @@ export const logoutUser = async (req: Request, res: Response): Promise userOnlineTime: onlineTime }); - await startWhoIsOnlineMonitor() + await startWhoIsOnlineMonitor(); // return res.status(200).json({}); }; - export const update = async ( req: Request, res: Response @@ -165,26 +177,23 @@ export const remove = async ( throw new AppError("ERR_NO_PERMISSION", 403); } - await DeleteUserService(userId); - const io = getIO(); io.emit("user", { action: "delete", userId }); - - //test del - await stopWhoIsOnlineMonitor() + //test del + await stopWhoIsOnlineMonitor(); io.emit("onlineStatus", { action: "delete", userOnlineTime: userId }); - await startWhoIsOnlineMonitor() + await startWhoIsOnlineMonitor(); // return res.status(200).json({ message: "User deleted" });