eliminar y eliminar id comunidad de administradores

This commit is contained in:
Mariela 2022-08-23 00:32:13 -06:00
parent c5173895fd
commit 49cb71e767
7 changed files with 86 additions and 50 deletions

View File

@ -323,6 +323,11 @@ export class AppController {
) {
return this.appService.saveTenant(community_id, number_house, tenant_id);
}
@Delete('community/deleteCommunity/:id')
deleteCommunity(@Param('id') paramCommunityId: string) {
return this.appService.deleteCommunity(paramCommunityId);
}
// #==== API Common Areas
@Post('commonArea/createCommonArea')
createCommonArea(

View File

@ -407,6 +407,15 @@ export class AppService {
.pipe(map((message: string) => ({ message })));
}
deleteCommunity(id: string) {
const pattern = { cmd: 'removeCommunity' };
const payload = { _id: id };
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== COMMON AREAS ===============================
//POST parameter from API
createCommonArea(

View File

@ -57,6 +57,7 @@ export class CommunitiesService {
}
async remove(id: string) {
await this.removeIdCommunity(id);
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
new: true,
});
@ -119,4 +120,16 @@ export class CommunitiesService {
new: true,
});
}
async removeIdCommunity(community: string) {
const pattern = { cmd: 'removeIdCommunity' };
const payload = { community_id: community};
let callback = await this.clientUserApp
.send<string>(pattern, payload)
.pipe(map((response: string) => ({ response })));
const finalValue = await lastValueFrom(callback);
return finalValue['response'];
}
}

View File

@ -142,6 +142,13 @@ export class UsersController {
user['number_house']);
}
@MessagePattern({ cmd: 'removeIdCommunity' })
removeIdCommunity(@Payload() user: any) {
let community_id = user['community_id'];
return this.userService.removeIdCommunity(community_id);
}
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];

View File

@ -295,5 +295,11 @@ export class UsersService {
map((response: string) => ({ response }))
)
}
async removeIdCommunity(community_id: string){
return this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}});
/*await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": ''}, {"status": '-1'}});
return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": ''}, {"status": '-1'}});*/
}
}

View File

@ -315,10 +315,8 @@ const Communities = () => {
setDeleteCommunitiesDialog(true);
};
const infoCommunity = async (community) => {
await tenantsList(community._id);
setCommunity({ ...community });
setCommunityDialog(true);
};
@ -383,9 +381,8 @@ const Communities = () => {
);
}
const deleteCommunity = () => {
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
cache: 'no-cache',
method: 'DELETE',
headers: {
@ -416,7 +413,6 @@ const Communities = () => {
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
}
);
*/
let _communities = communitiesList.filter((val) => val._id !== community._id);
_communities = _communities.filter(
(val) => val.status != -1,