Merge branch 'US-09-Activar-DesactivarAdministradoresdeSistema' into US-43-Activar-DesactivarInquilinos

This commit is contained in:
Mariela 2022-08-02 22:36:10 -06:00
commit a82ad4ff07
7 changed files with 303 additions and 142 deletions

View File

@ -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')

View File

@ -18,7 +18,7 @@ export class AppService {
@Inject('SERVICIO_REPORTES') private readonly clientReportApp: ClientProxy,
@Inject('SERVICIO_NOTIFICACIONES')
private readonly clientNotificationtApp: ClientProxy,
) {}
) { }
// ====================== USERS ===============================
@ -179,17 +179,10 @@ export class AppService {
.send<string>(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<string>(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<string>(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<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
//POST parameter from API
createCommunity(name: string, province: string, canton: string, district: string
@ -285,8 +293,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
@ -295,14 +303,14 @@ export class AppService {
}
//DELETE parameter from API
deleteCommonArea(paramCommonAreaId: string) {
const pattern = { cmd: 'removeCommonArea' };
const payload = { id: paramCommonAreaId };
return this.clientCommonAreaApp
.send<string>(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<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== GUESTS ===============================

View File

@ -51,8 +51,6 @@ export class CommunitiesController {
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
console.log(pid);
console.log(pstatus);
return this.communitiesService.changeStatus(pid,pstatus);
}
}

View File

@ -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) {
@ -118,5 +118,10 @@ export class UsersController {
}
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.userService.changeStatus(pid, pstatus);
}
}

View File

@ -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,
});
}
}

View File

@ -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 (
<div className="actions">
<Button
icon={`${icono}`}
className={`p-button-rounded p-button-warning mt-2 mx-2`}
onClick={() => confirmChangeStatusAdminSystem(rowData)}
title={`${text}`}
/>
<Button
icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2"
className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmDeleteAdminSystem(rowData)}
title="Eliminar Administrador"
/>
</div>
);
@ -264,6 +354,23 @@ const AdministradoresSistema = () => {
</>
);
const changeStatusAdminSystemDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideChangeStatusAdminDialog}
/>
<Button
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarStatusUser}
/>
</>
);
const headerName = (
<>
<p>
@ -312,6 +419,26 @@ const AdministradoresSistema = () => {
</p>
</>
);
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '}
Estado
</p>
</>
)
const statusBodyTemplate = (rowData) => {
return (
<>
<span
className={`status status-${rowData.status}`}
>
{rowData.status_text}
</span>
</>
);
};
return (
<div className="grid">
@ -401,9 +528,16 @@ const AdministradoresSistema = () => {
wordBreak: 'break-word',
}}
></Column>
<Column
field="status"
sortable
header={headerStatus}
body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column>
<Column
style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }}
style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }}
body={actionsAdmin}
></Column>
</DataTable>
@ -448,6 +582,26 @@ const AdministradoresSistema = () => {
)}
</div>
</Dialog>
<Dialog
visible={changeStatusAdminSystemDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={changeStatusAdminSystemDialogFooter}
onHide={hideChangeStatusAdminDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{sysadmin && (
<span>
¿Estás seguro que desea cambiar estado a <b>{sysadmin.name}</b>?
</span>
)}
</div>
</Dialog>
</div>
</div>
<div className="col-12">

View File

@ -12,8 +12,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons';
import { faMapLocationDot } from '@fortawesome/free-solid-svg-icons';
import { faPhoneAlt } from '@fortawesome/free-solid-svg-icons';
import { faEllipsis } from '@fortawesome/free-solid-svg-icons';
import { faHashtag } from '@fortawesome/free-solid-svg-icons';
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
const Communities = () => {
let emptyCommunity = {
@ -25,6 +25,7 @@ const Communities = () => {
phone: '',
num_houses: 0,
status: '1',
status_text: '',
date_entry: new Date(),
houses: [],
};
@ -161,7 +162,17 @@ const Communities = () => {
let pList = await getProvinces();
let cList = await getCantons();
let dList = await getDistricts();
await resJson.message.map((item) => {
let data = await resJson.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';
} else {
item.status_text = 'Eliminado';
}
item.province = pList.find((p) => p.code === item.province).name;
item.canton = cList.find((p) => p.code === item.canton).name;
item.district = dList.find((p) => p.code === item.district).name;
@ -169,7 +180,7 @@ const Communities = () => {
item.name_admin = 'Sin Administrador';
}
});
setCommunitiesList(await resJson.message);
setCommunitiesList(await data);
}
useEffect(() => {
@ -181,6 +192,9 @@ const Communities = () => {
.then((response) => response.json())
.then(data => data.message)
.then(data => {
data = data.filter(
(val) => val.status != -1,
)
setTenants(data)
});
}
@ -265,10 +279,9 @@ const Communities = () => {
if (tenant_id == '') {
name = 'Sin inquilino';
} else {
let tenant = tenants.find(t => t._id == tenant_id )
let tenant = tenants.find(t => t._id == tenant_id)
name = tenant['name'] + ' ' + tenant['last_name'];
}
console.log(name);
return name;
}
@ -323,14 +336,21 @@ const Communities = () => {
setCommunity(community);
setEditCommunityDialog(true);
};
//desactivar o activar una comunidad
const cambiarDesactivarEstadoCommunity = () => {
const cambiarEstadoCommunity = () => {
if (community.status == '1') {
community.status = '0';
community.status_text = 'Inactivo';
} else if (community.status == '0') {
community.status = '1';
community.status_text = 'Activo';
}
var data = {
id: community._id,
status: "0",
status: community.status,
};
console.log(data);
fetch('http://localhost:4000/community/changeStatus', {
cache: 'no-cache',
method: 'POST',
@ -362,44 +382,6 @@ const Communities = () => {
err => console.log('Ocurrió un error con el fetch', err)
);
}
//desactivar o activar una comunidad
const cambiarActivarEstadoCommunity = () => {
var data = {
id: community._id,
status: "1",
};
console.log(data);
fetch('http://localhost:4000/community/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) {
setEditCommunityDialog(false);
toast.current.show({
severity: 'success',
summary: 'Éxito',
detail: 'Comunidad de Viviendas Actualizada',
life: 3000,
});
}
)
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
}
const deleteCommunity = () => {
@ -435,8 +417,11 @@ const Communities = () => {
}
);
*/
let _community = communitiesList.filter((val) => val._id !== community._id);
setCommunitiesList(_community);
let _communities = communitiesList.filter((val) => val._id !== community._id);
_communities = _communities.filter(
(val) => val.status != -1,
)
setCommunitiesList(_communities);
setDeleteCommunityDialog(false);
setCommunity(emptyCommunity);
toast.current.show({
@ -460,6 +445,9 @@ const Communities = () => {
}
})
})*/
_communities = _communities.filter(
(val) => val.status != -1,
)
setCommunitiesList(_communities);
setDeleteCommunitiesDialog(false);
setSelectedCommunities(null);
@ -472,23 +460,26 @@ const Communities = () => {
};
const actionsCommunity = (rowData) => {
let icono = '';
if (rowData.status == '0') {
icono = "pi pi-eye";
} else if (rowData.status == '1') {
icono = "pi pi-eye-slash";
}
return (
<div className="actions">
<Button
icon="pi pi-eye"
className="p-button-rounded p-button-success mt-2 mx-2"
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-eye-slash"
className="p-button-rounded p-button-danger mt-2 mx-2"
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-exclamation-circle"
className="p-button-rounded p-button-primary mt-2 mx-2"
className="p-button-rounded p-button-info mt-2 mx-2"
onClick={() => infoCommunity(rowData)}
/>
<Button
icon={`${icono}`}
className={`p-button-rounded p-button-warning mt-2 mx-2`}
onClick={() => confirmEditCommunity(rowData)}
/>
<Button
icon="pi pi-trash"
className="p-button-rounded p-button-danger mt-2 mx-2"
@ -528,7 +519,7 @@ const Communities = () => {
const header = (
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
<h5 className="m-0">Comunidade de Viviendas</h5>
<h5 className="m-0">Comunidades de Viviendas</h5>
<span className="block mt-2 md:mt-0 p-input-icon-left">
<i className="pi pi-search" />
<InputText
@ -585,7 +576,7 @@ const Communities = () => {
/>
</>
);
const editDesactivarCommunityDialogFooter = (
const editEstadoCommunityDialogFooter = (
<>
<Button
label="No"
@ -597,27 +588,12 @@ const Communities = () => {
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarDesactivarEstadoCommunity}
onClick={cambiarEstadoCommunity}
/>
</>
);
const editActivarCommunityDialogFooter = (
<>
<Button
label="No"
icon="pi pi-times"
className="p-button-text"
onClick={hideEditCommunityDialog}
/>
<Button
label="Yes"
icon="pi pi-check"
className="p-button-text"
onClick={cambiarActivarEstadoCommunity}
/>
</>
);
const headerName = (
<>
@ -697,6 +673,15 @@ const Communities = () => {
</>
);
const headerStatus = (
<>
<p> {' '}
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#D7A86E" }} />{' '}
Estado
</p>
</>
)
//ver perfil comunidad
const headerTenant = (
<>
@ -709,14 +694,24 @@ const Communities = () => {
</>
);
const statusBodyTemplate = (rowData) => {
return (
<>
<span
className={`status status-${rowData.status}`}
>
{rowData.status_text}
</span>
</>
);
};
const tenantsBodyTemplate = (rowData) => {
let tenants = rowData.tenants;
let name = findNameTenant(tenants.tenant_id);
console.log(name);
return (
<>
{name}
{name}
</>
)
};
@ -796,9 +791,16 @@ const Communities = () => {
style={{ flexGrow: 1, flexBasis: '180px' }}
></Column>
<Column
body={actionsCommunity}
style={{ flexGrow: 1, flexBasis: '180px' }}
></Column>
field="status"
sortable
header={headerStatus}
body={statusBodyTemplate}
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
</Column>
<Column
body={actionsCommunity}
style={{ flexGrow: 1, flexBasis: '100px' }}
></Column>
</DataTable>
@ -927,32 +929,13 @@ const Communities = () => {
</div>
</Dialog>
<Dialog
visible={editCommunityDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={editActivarCommunityDialogFooter}
onHide={hideEditCommunityDialog}
>
<div className="flex align-items-center justify-content-center">
<i
className="pi pi-exclamation-triangle mr-3"
style={{ fontSize: '2rem' }}
/>
{community && (
<span>
¿Estás seguro que desea cambiar estado a <b>{community.name}</b>?
</span>
)}
</div>
</Dialog>
<Dialog
visible={editCommunityDialog}
style={{ width: '450px' }}
header="Confirmar"
modal
footer={editDesactivarCommunityDialogFooter}
footer={editEstadoCommunityDialogFooter}
onHide={hideEditCommunityDialog}
>
<div className="flex align-items-center justify-content-center">