diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 3884c89a..5d2b9f92 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -128,6 +128,14 @@ export class AppController { return this.appService.deleteAdminSystem(id); } + @Post('user/changeStatus') + changeStatusUser( + @Body('id') pId: string, + @Body('status') pStatus: string, + ) { + return this.appService.changeStatusUser(pId, pStatus); + } + // #==== API Communities @Post('community/createCommunity') createCommunity( @@ -174,11 +182,11 @@ export class AppController { return this.appService.findCommunityAdmin(community_id); } @Post('community/changeStatus') - changeStatus( + changeStatusCommunity( @Body('id') pId: string, @Body('status') pStatus: string, ) { - return this.appService.changeStatus(pId, pStatus); + return this.appService.changeStatusCommunity(pId, pStatus); } // #==== API Common Areas @Post('commonArea/createCommonArea') diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 1ac8513c..e1199d79 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -18,7 +18,7 @@ export class AppService { @Inject('SERVICIO_REPORTES') private readonly clientReportApp: ClientProxy, @Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy, - ) {} + ) { } // ====================== USERS =============================== @@ -79,7 +79,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - + createAdminCommunity(dni: string, name: string, last_name: string, email: string, phone: number , user_type: string, status: string, date_entry: Date, community_id: string) { const pattern = { cmd: 'createAdminCommunity' }; @@ -128,7 +128,7 @@ export class AppService { map((message: string) => ({ message })), ); } - + //GET parameter from API findUser(paramUserDNI: string) { @@ -179,17 +179,10 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - changeStatus(pId: string, pStatus: string) { - const pattern = { cmd: 'changeStatus' }; - const payload = { id: pId, status: pStatus }; - return this.clientCommunityApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } - //GET parameter from API - findUserById(id: string) { + //GET parameter from API + findUserById(id: string) { const pattern = { cmd: 'findById' }; const payload = { id: id }; return this.clientUserApp @@ -197,8 +190,23 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + changeStatusUser(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientUserApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + // ====================== COMMUNITIES =============================== + changeStatusCommunity(pId: string, pStatus: string) { + const pattern = { cmd: 'changeStatus' }; + const payload = { id: pId, status: pStatus }; + return this.clientCommunityApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } //POST parameter from API createCommunity(name: string, province: string, canton: string, district: string @@ -286,8 +294,8 @@ export class AppService { } - //GET parameter from API - findByCommunity(paramCommunityId: string) { + //GET parameter from API + findByCommunity(paramCommunityId: string) { const pattern = { cmd: 'findByCommunity' }; const payload = { community_id: paramCommunityId }; return this.clientCommonAreaApp @@ -296,14 +304,14 @@ export class AppService { } - //DELETE parameter from API - deleteCommonArea(paramCommonAreaId: string) { - const pattern = { cmd: 'removeCommonArea' }; - const payload = { id: paramCommonAreaId }; - return this.clientCommonAreaApp - .send(pattern, payload) - .pipe(map((message: string) => ({ message }))); - } + //DELETE parameter from API + deleteCommonArea(paramCommonAreaId: string) { + const pattern = { cmd: 'removeCommonArea' }; + const payload = { id: paramCommonAreaId }; + return this.clientCommonAreaApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } // ====================== GUESTS =============================== diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index bd875b12..a32d265d 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -6,7 +6,7 @@ import { MongoExceptionFilter } from 'src/MongoExceptionFilter'; @Controller() export class UsersController { - constructor(private readonly userService: UsersService) {} + constructor(private readonly userService: UsersService) { } @MessagePattern({ cmd: 'createUser' }) create(@Payload() user: UserDocument) { @@ -117,6 +117,11 @@ export class UsersController { return this.userService.deleteAdminSystem(user['id']); } - + @MessagePattern({ cmd: 'changeStatus' }) + changeStatus(@Payload() body: string) { + let pid = body['id']; + let pstatus = body['status']; + return this.userService.changeStatus(pid, pstatus); + } } diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 268ab49a..2015ef45 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -223,5 +223,10 @@ export class UsersService { return num_house; } + async changeStatus(id: string, status: string) { + return this.userModel.findOneAndUpdate({ _id: id }, {status: status}, { + new: true, + }); + } } diff --git a/web-ui/web-react/src/components/AdministradoresSistema.js b/web-ui/web-react/src/components/AdministradoresSistema.js index 6b609bcf..40529fc6 100644 --- a/web-ui/web-react/src/components/AdministradoresSistema.js +++ b/web-ui/web-react/src/components/AdministradoresSistema.js @@ -11,7 +11,7 @@ import { faUserAlt } from '@fortawesome/free-solid-svg-icons'; import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons'; import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; -import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; +import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons'; const AdministradoresSistema = () => { const [administrators, setAdministrators] = useState([]); @@ -27,6 +27,10 @@ const AdministradoresSistema = () => { const toast = useRef(null); const dt = useRef(null); + const [changeStatusAdminSystemDialog, setChangeStatusAdminSystemDialog] = useState(false); + const [changeStatusAdminsSystemDialog, setChangeStatusAdminsSystemDialog] = + useState(false); + let emptySysAdmin = { _id: null, dni: '', @@ -37,14 +41,24 @@ const AdministradoresSistema = () => { password: '', user_type: '1', status: '1', + status_text: '', }; async function fetchP() { let nombres = await fetch(urlFetch, { method: 'GET' }); let adminRes = await nombres.json(); + let data = await adminRes.message.filter( + (val) => val.status != -1, + ) + await data.map((item) => { + if (item.status == '1') { + item.status_text = 'Activo'; + } else if (item.status == '0') { + item.status_text = 'Inactivo'; + } + }) setAdministrators(adminRes.message); - console.log(administrators); } useEffect(() => { fetchP(); @@ -63,7 +77,6 @@ const AdministradoresSistema = () => { status: "1" }; setSysAdmin(data) - // console.log(data); fetch('http://localhost:4000/user/createAdminSystem/', { cache: 'no-cache', @@ -94,6 +107,51 @@ const AdministradoresSistema = () => { ); } + const cambiarStatusUser = () => { + if (sysadmin.status == '1') { + sysadmin.status = '0'; + sysadmin.status_text = 'Inactivo'; + + } else if (sysadmin.status == '0') { + sysadmin.status = '1'; + sysadmin.status_text = 'Activo'; + } + var data = { + id: sysadmin._id, + status: sysadmin.status, + }; + fetch('http://localhost:4000/user/changeStatus', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }) + .then( + function (response) { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + } + ) + .then( + function (response) { + setChangeStatusAdminSystemDialog(false); + toast.current.show({ + severity: 'success', + summary: 'Éxito', + detail: 'Administrador del Sistema Actualizado', + life: 3000, + }); + } + ) + .catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } + const confirmDeleteAdminSystem = (sysAdmin) => { setSysAdmin(sysAdmin); setDeleteAdminSystemDialog(true); @@ -111,6 +169,14 @@ const AdministradoresSistema = () => { setDeleteAdminsSystemDialog(false); }; + const hideChangeStatusAdminDialog = () => { + setChangeStatusAdminSystemDialog(false); + }; + + const confirmChangeStatusAdminSystem = (sysAdmin) => { + setSysAdmin(sysAdmin); + setChangeStatusAdminSystemDialog(true); + }; const deleteSysAdmin = () => { fetch('http://localhost:4000/user/deleteAdminSystem/' + sysadmin._id, { @@ -127,8 +193,9 @@ const AdministradoresSistema = () => { }) .then(function (response) { let _sysadmin = administrators.filter( - (val) => val._id !== sysadmin._id, + (val) => (val._id !== sysadmin._id || val.status != -1), ); + setAdministrators(_sysadmin); setDeleteAdminSystemDialog(false); setSysAdmin(emptySysAdmin); @@ -152,7 +219,7 @@ const AdministradoresSistema = () => { const deleteSelectedAdminsSystem = () => { let _administrators = administrators.filter( - (val) => !selectedAdministrators.includes(val), + (val) => (!selectedAdministrators.includes(val)), ); selectedAdministrators.map((item) => { fetch('http://localhost:4000/user/deleteAdminSystem/' + item._id, { @@ -163,6 +230,9 @@ const AdministradoresSistema = () => { }, }); }); + _administrators = _administrators.filter( + (val) => val.status != -1, + ) setAdministrators(_administrators); setDeleteAdminsSystemDialog(false); setSelectedAdministrators(null); @@ -174,13 +244,33 @@ const AdministradoresSistema = () => { }); }; + + const actionsAdmin = (rowData) => { + let icono = ''; + let text = ''; + if (rowData.status == '0') { + icono = "pi pi-eye"; + text = "Activar Administrador" + } else if (rowData.status == '1') { + icono = "pi pi-eye-slash"; + text = "Inactivar Administrador" + + } + return (
+
); @@ -264,6 +354,23 @@ const AdministradoresSistema = () => { ); + const changeStatusAdminSystemDialogFooter = ( + <> +