eliminar y eliminar id comunidad de administradores
This commit is contained in:
parent
c5173895fd
commit
49cb71e767
|
@ -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(
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
|||
|
||||
@Controller()
|
||||
export class CommunitiesController {
|
||||
constructor(private readonly communitiesService: CommunitiesService) {}
|
||||
constructor(private readonly communitiesService: CommunitiesService) { }
|
||||
|
||||
@MessagePattern({ cmd: 'createCommunity' })
|
||||
create(@Payload() community: CommunityDocument) {
|
||||
|
@ -46,17 +46,17 @@ export class CommunitiesController {
|
|||
return this.communitiesService.remove(_id);
|
||||
}
|
||||
|
||||
//cambiar de estado
|
||||
@MessagePattern({ cmd: 'changeStatus' })
|
||||
changeStatus(@Payload() body: string) {
|
||||
let pid = body['id'];
|
||||
let pstatus = body['status'];
|
||||
return this.communitiesService.changeStatus(pid,pstatus);
|
||||
}
|
||||
//cambiar de estado
|
||||
@MessagePattern({ cmd: 'changeStatus' })
|
||||
changeStatus(@Payload() body: string) {
|
||||
let pid = body['id'];
|
||||
let pstatus = body['status'];
|
||||
return this.communitiesService.changeStatus(pid, pstatus);
|
||||
}
|
||||
|
||||
|
||||
@MessagePattern({ cmd: 'saveTenant' })
|
||||
saveTenant(@Payload() body: string) {
|
||||
@MessagePattern({ cmd: 'saveTenant' })
|
||||
saveTenant(@Payload() body: string) {
|
||||
|
||||
let id = body['_id'];
|
||||
let tenant_id = body['tenant_id'];
|
||||
|
@ -66,9 +66,9 @@ export class CommunitiesController {
|
|||
|
||||
@MessagePattern({ cmd: 'deleteTenant' })
|
||||
deleteTenant(@Payload() body: string) {
|
||||
let id = body['_id'];
|
||||
let tenant_id = body['tenant_id'];
|
||||
let number_house = body['number_house'];
|
||||
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
||||
}
|
||||
let id = body['_id'];
|
||||
let tenant_id = body['tenant_id'];
|
||||
let number_house = body['number_house'];
|
||||
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -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'}});*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -315,10 +315,8 @@ const Communities = () => {
|
|||
setDeleteCommunitiesDialog(true);
|
||||
};
|
||||
|
||||
|
||||
const infoCommunity = async (community) => {
|
||||
await tenantsList(community._id);
|
||||
|
||||
setCommunity({ ...community });
|
||||
setCommunityDialog(true);
|
||||
};
|
||||
|
@ -383,40 +381,38 @@ const Communities = () => {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
const deleteCommunity = () => {
|
||||
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
||||
cache: 'no-cache',
|
||||
method: 'DELETE',
|
||||
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) {
|
||||
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
||||
cache: 'no-cache',
|
||||
method: 'DELETE',
|
||||
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) {
|
||||
|
||||
let _community = communities.filter(val => val._id !== community._id);
|
||||
setCommunities(_community);
|
||||
setDeleteCommunityDialog(false);
|
||||
setCommunity(emptyCommunity);
|
||||
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
err => {
|
||||
console.log('Ocurrió un error con el fetch', err)
|
||||
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
|
||||
}
|
||||
);
|
||||
*/
|
||||
let _community = communities.filter(val => val._id !== community._id);
|
||||
setCommunities(_community);
|
||||
setDeleteCommunityDialog(false);
|
||||
setCommunity(emptyCommunity);
|
||||
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
||||
}
|
||||
)
|
||||
.catch(
|
||||
err => {
|
||||
console.log('Ocurrió un error con el fetch', err)
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue