deleteTenant function community

This commit is contained in:
Mariela 2022-08-22 15:06:44 -06:00
parent 9e7ac1d91f
commit 456d9ce4d0
2 changed files with 10 additions and 4 deletions

View File

@ -63,4 +63,13 @@ export class CommunitiesController {
let number_house = body['number_house']; let number_house = body['number_house'];
return this.communitiesService.saveTenant(id, number_house, tenant_id); return this.communitiesService.saveTenant(id, number_house, tenant_id);
} }
@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);
}
} }

View File

@ -111,15 +111,12 @@ export class CommunitiesService {
await community.houses.map(house => { await community.houses.map(house => {
if (house.number_house == number_house && if (house.number_house == number_house &&
house.tenants.tenant_id == tenant_id) { house.tenants.tenant_id == tenant_id) {
house.tenants = null; house.tenants.tenant_id = "";
house.state = "desocupada" house.state = "desocupada"
} }
return house; return house;
}) })
console.log(community.houses)
return await this.communityModel.findOneAndUpdate({ _id: id }, community, { return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true, new: true,
}); });