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);
|
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
|
// #==== API Common Areas
|
||||||
@Post('commonArea/createCommonArea')
|
@Post('commonArea/createCommonArea')
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
|
|
@ -407,6 +407,15 @@ export class AppService {
|
||||||
.pipe(map((message: string) => ({ message })));
|
.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 ===============================
|
// ====================== COMMON AREAS ===============================
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class CommunitiesController {
|
export class CommunitiesController {
|
||||||
constructor(private readonly communitiesService: CommunitiesService) {}
|
constructor(private readonly communitiesService: CommunitiesService) { }
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'createCommunity' })
|
@MessagePattern({ cmd: 'createCommunity' })
|
||||||
create(@Payload() community: CommunityDocument) {
|
create(@Payload() community: CommunityDocument) {
|
||||||
|
@ -46,17 +46,17 @@ export class CommunitiesController {
|
||||||
return this.communitiesService.remove(_id);
|
return this.communitiesService.remove(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//cambiar de estado
|
//cambiar de estado
|
||||||
@MessagePattern({ cmd: 'changeStatus' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
changeStatus(@Payload() body: string) {
|
changeStatus(@Payload() body: string) {
|
||||||
let pid = body['id'];
|
let pid = body['id'];
|
||||||
let pstatus = body['status'];
|
let pstatus = body['status'];
|
||||||
return this.communitiesService.changeStatus(pid,pstatus);
|
return this.communitiesService.changeStatus(pid, pstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'saveTenant' })
|
@MessagePattern({ cmd: 'saveTenant' })
|
||||||
saveTenant(@Payload() body: string) {
|
saveTenant(@Payload() body: string) {
|
||||||
|
|
||||||
let id = body['_id'];
|
let id = body['_id'];
|
||||||
let tenant_id = body['tenant_id'];
|
let tenant_id = body['tenant_id'];
|
||||||
|
@ -66,9 +66,9 @@ export class CommunitiesController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'deleteTenant' })
|
@MessagePattern({ cmd: 'deleteTenant' })
|
||||||
deleteTenant(@Payload() body: string) {
|
deleteTenant(@Payload() body: string) {
|
||||||
let id = body['_id'];
|
let id = body['_id'];
|
||||||
let tenant_id = body['tenant_id'];
|
let tenant_id = body['tenant_id'];
|
||||||
let number_house = body['number_house'];
|
let number_house = body['number_house'];
|
||||||
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string) {
|
async remove(id: string) {
|
||||||
|
await this.removeIdCommunity(id);
|
||||||
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
@ -119,4 +120,16 @@ export class CommunitiesService {
|
||||||
new: true,
|
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']);
|
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' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
changeStatus(@Payload() body: string) {
|
changeStatus(@Payload() body: string) {
|
||||||
let pid = body['id'];
|
let pid = body['id'];
|
||||||
|
|
|
@ -295,5 +295,11 @@ export class UsersService {
|
||||||
map((response: string) => ({ response }))
|
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);
|
setDeleteCommunitiesDialog(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const infoCommunity = async (community) => {
|
const infoCommunity = async (community) => {
|
||||||
await tenantsList(community._id);
|
await tenantsList(community._id);
|
||||||
|
|
||||||
setCommunity({ ...community });
|
setCommunity({ ...community });
|
||||||
setCommunityDialog(true);
|
setCommunityDialog(true);
|
||||||
};
|
};
|
||||||
|
@ -383,40 +381,38 @@ const Communities = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const deleteCommunity = () => {
|
const deleteCommunity = () => {
|
||||||
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
if (response.status != 201)
|
if (response.status != 201)
|
||||||
console.log('Ocurrió un error con el servicio: ' + response.status);
|
console.log('Ocurrió un error con el servicio: ' + response.status);
|
||||||
else
|
else
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
|
|
||||||
let _community = communities.filter(val => val._id !== community._id);
|
let _community = communities.filter(val => val._id !== community._id);
|
||||||
setCommunities(_community);
|
setCommunities(_community);
|
||||||
setDeleteCommunityDialog(false);
|
setDeleteCommunityDialog(false);
|
||||||
setCommunity(emptyCommunity);
|
setCommunity(emptyCommunity);
|
||||||
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch(
|
.catch(
|
||||||
err => {
|
err => {
|
||||||
console.log('Ocurrió un error con el fetch', 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 });
|
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);
|
let _communities = communitiesList.filter((val) => val._id !== community._id);
|
||||||
_communities = _communities.filter(
|
_communities = _communities.filter(
|
||||||
(val) => val.status != -1,
|
(val) => val.status != -1,
|
||||||
|
|
Loading…
Reference in New Issue