finalizar eliminar inquilino
This commit is contained in:
parent
456d9ce4d0
commit
a9c02244a8
|
@ -2,7 +2,7 @@ import { Controller, Get, Post, Put, Body, Param, Delete } from '@nestjs/common'
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
@Controller()
|
@Controller()
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) { }
|
||||||
// #==== API Users
|
// #==== API Users
|
||||||
@Post('user/createAdminSystem')
|
@Post('user/createAdminSystem')
|
||||||
createAdminSystem(
|
createAdminSystem(
|
||||||
|
@ -33,7 +33,7 @@ export class AppController {
|
||||||
@Body('community_id') community_id: string,
|
@Body('community_id') community_id: string,
|
||||||
) {
|
) {
|
||||||
return this.appService.createGuard(dni, name, last_name, email, phone,
|
return this.appService.createGuard(dni, name, last_name, email, phone,
|
||||||
user_type, status, date_entry,community_id);
|
user_type, status, date_entry, community_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('user/createAdminCommunity')
|
@Post('user/createAdminCommunity')
|
||||||
|
@ -47,10 +47,10 @@ export class AppController {
|
||||||
@Body('user_type') user_type: string,
|
@Body('user_type') user_type: string,
|
||||||
@Body('status') status: string,
|
@Body('status') status: string,
|
||||||
@Body('date_entry') date_entry: Date,
|
@Body('date_entry') date_entry: Date,
|
||||||
@Body('community_id') community_id:string
|
@Body('community_id') community_id: string
|
||||||
) {
|
) {
|
||||||
return this.appService.createAdminCommunity(dni, name, last_name, email, phone,
|
return this.appService.createAdminCommunity(dni, name, last_name, email, phone,
|
||||||
user_type, status, date_entry,community_id);
|
user_type, status, date_entry, community_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('user/createUser')
|
@Post('user/createUser')
|
||||||
|
@ -224,9 +224,13 @@ export class AppController {
|
||||||
return this.appService.deleteAdminCommunity(id);
|
return this.appService.deleteAdminCommunity(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete('user/deleteTenant/:id')
|
@Put('user/deleteTenant/:id')
|
||||||
deleteTenant(@Param('id') id: string) {
|
deleteTenant(
|
||||||
return this.appService.deleteTenant(id);
|
@Param('id') id: string,
|
||||||
|
@Body('community_id') community_id: string,
|
||||||
|
@Body('number_house') number_house: string
|
||||||
|
) {
|
||||||
|
return this.appService.deleteTenant(id, community_id, number_house);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post('user/changeStatus')
|
@Post('user/changeStatus')
|
||||||
|
|
|
@ -271,9 +271,9 @@ export class AppService {
|
||||||
.pipe(map((message: string) => ({ message })));
|
.pipe(map((message: string) => ({ message })));
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteTenant(id: string) {
|
deleteTenant(id: string, community_id: string, number_house: string) {
|
||||||
const pattern = { cmd: 'deleteTenant' };
|
const pattern = { cmd: 'deleteTenant' };
|
||||||
const payload = { id: id };
|
const payload = { _id: id, community_id: community_id, number_house: number_house };
|
||||||
return this.clientUserApp
|
return this.clientUserApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(map((message: string) => ({ message })));
|
.pipe(map((message: string) => ({ message })));
|
||||||
|
|
|
@ -66,7 +66,6 @@ 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'];
|
||||||
|
|
|
@ -105,12 +105,10 @@ export class CommunitiesService {
|
||||||
|
|
||||||
|
|
||||||
async deleteTenant(id: string, number_house: string, tenant_id: string) {
|
async deleteTenant(id: string, number_house: string, tenant_id: string) {
|
||||||
|
|
||||||
let community = await this.findOne(id);
|
let community = await this.findOne(id);
|
||||||
|
|
||||||
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 = "";
|
house.tenants.tenant_id = "";
|
||||||
house.state = "desocupada"
|
house.state = "desocupada"
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,10 @@ export class UsersController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'deleteTenant' })
|
@MessagePattern({ cmd: 'deleteTenant' })
|
||||||
deleteTenant(@Payload() user: any) {
|
deleteTenant(@Payload() user: any) {
|
||||||
return this.userService.deleteTenant(user['_id']);
|
let tenant_id = user['_id'];
|
||||||
|
return this.userService.deleteTenant(tenant_id,
|
||||||
|
user['community_id'],
|
||||||
|
user['number_house']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'changeStatus' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
|
|
|
@ -195,7 +195,7 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteAdminSystem(id: string) {
|
async deleteAdminSystem(id: string) {
|
||||||
return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1', number_house:'' }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -206,10 +206,18 @@ export class UsersService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteTenant(id: string) {
|
async deleteTenant(tenant_id: string, community_id: string, number_house: string) {
|
||||||
return this.userModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
|
||||||
|
try{
|
||||||
|
this.userModel.findOneAndUpdate({ _id: tenant_id }, { status: '-1' }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return await this.deleteTenantNumHouse(community_id, number_house, tenant_id);
|
||||||
|
} catch(error){
|
||||||
|
console.log(error)
|
||||||
|
return error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async validateEmail(email: string) {
|
async validateEmail(email: string) {
|
||||||
|
@ -257,7 +265,7 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
|
async saveTenantNumHouse(community_id: string, number_house: string, tenant_id: string) {
|
||||||
const pattern = { cmd: 'saveTenant' }
|
const pattern = { cmd: 'saveTenant' }
|
||||||
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
||||||
|
|
||||||
|
@ -269,10 +277,9 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async deleteTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
|
async deleteTenantNumHouse(community_id: string, number_house: string, tenant_id: string) {
|
||||||
const pattern = { cmd: 'deleteTenant' }
|
const pattern = { cmd: 'deleteTenant' }
|
||||||
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
||||||
|
|
||||||
return await this.clientCommunityApp
|
return await this.clientCommunityApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
|
|
@ -184,6 +184,31 @@ const Inquilinos = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteTenant = () => {
|
const deleteTenant = () => {
|
||||||
|
|
||||||
|
let _tenant = {
|
||||||
|
community_id: tenant.community_id,
|
||||||
|
number_house: tenant.number_house
|
||||||
|
};
|
||||||
|
|
||||||
|
fetch('http://localhost:4000/user/deleteTenant/' + tenant._id, {
|
||||||
|
cache: 'no-cache',
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify(_tenant),
|
||||||
|
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 _tenants = tenants.filter((val) => val._id !== tenant._id)
|
let _tenants = tenants.filter((val) => val._id !== tenant._id)
|
||||||
setTenants(_tenants)
|
setTenants(_tenants)
|
||||||
setDeleteTenantDialog(false)
|
setDeleteTenantDialog(false)
|
||||||
|
@ -192,7 +217,16 @@ const Inquilinos = () => {
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Inquilino Eliminado',
|
summary: 'Inquilino Eliminado',
|
||||||
life: 3000,
|
life: 3000,
|
||||||
})
|
}) }
|
||||||
|
)
|
||||||
|
.catch(
|
||||||
|
err => {
|
||||||
|
console.log('Ocurrió un error con el fetch', err)
|
||||||
|
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Inquilino no se pudo eliminar', life: 3000 });
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteSelectedTenants = () => {
|
const deleteSelectedTenants = () => {
|
||||||
|
|
Loading…
Reference in New Issue