feat(backend) criação da controler que retorna todos usuarios pelo profile

adriano 2023-10-23 09:09:14 -03:00
parent f9594aa114
commit df9d468700
1 changed files with 42 additions and 33 deletions

View File

@ -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<Response> => {
profile
});
if (req.user.profile !== 'master') {
if (req.user.profile !== "master") {
let auxUsers: Array<object> = [];
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<Response> => {
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<object> = [];
// let auxUsers: Array<object> = [];
// 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<Response> => {
const { profile } = req.query as IndexQuery;
const users = await ListUser({
profile
});
return res.json({ users });
};
export const store = async (req: Request, res: Response): Promise<Response> => {
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<Response> => {
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<Response> => {
return res.status(200).json(user);
};
export const logoutUser = async (req: Request, res: Response): Promise<Response> => {
export const logoutUser = async (
req: Request,
res: Response
): Promise<Response> => {
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<Response>
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" });