edicion para agregar inquilino al numero de vivienda
This commit is contained in:
parent
69775a366d
commit
d710e7c0ed
|
@ -223,6 +223,14 @@ export class AppController {
|
||||||
return this.appService.findHousesCommunity(community_id);
|
return this.appService.findHousesCommunity(community_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('community/saveTenant')
|
||||||
|
saveTenant(
|
||||||
|
@Body('community_id') community_id: string,
|
||||||
|
@Body('number_house') number_house: string,
|
||||||
|
@Body('tenant_id') tenant_id: string,
|
||||||
|
) {
|
||||||
|
return this.appService.saveTenant(community_id, number_house, tenant_id);
|
||||||
|
}
|
||||||
// #==== API Common Areas
|
// #==== API Common Areas
|
||||||
@Post('commonArea/createCommonArea')
|
@Post('commonArea/createCommonArea')
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
|
|
@ -301,6 +301,13 @@ export class AppService {
|
||||||
return houses;
|
return houses;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveTenant(id: string, number_house: string, tenant_id: string) {
|
||||||
|
const pattern = { cmd: 'saveTenant' };
|
||||||
|
const payload = { _id: id, number_house: number_house, tenant_id: tenant_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
|
||||||
|
|
|
@ -53,4 +53,13 @@ export class CommunitiesController {
|
||||||
let pstatus = body['status'];
|
let pstatus = body['status'];
|
||||||
return this.communitiesService.changeStatus(pid,pstatus);
|
return this.communitiesService.changeStatus(pid,pstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'saveTenant' })
|
||||||
|
saveTenant(@Payload() body: string) {
|
||||||
|
let id = body['_id'];
|
||||||
|
let tenant_id = body['tenant_id'];
|
||||||
|
let number_house = body['number_house'];
|
||||||
|
return this.communitiesService.saveTenant(id, number_house, tenant_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ export class CommunitiesService {
|
||||||
@InjectModel(Community.name)
|
@InjectModel(Community.name)
|
||||||
private readonly communityModel: Model<CommunityDocument>,
|
private readonly communityModel: Model<CommunityDocument>,
|
||||||
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
|
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
async create(community: CommunityDocument): Promise<Community> {
|
async create(community: CommunityDocument): Promise<Community> {
|
||||||
return this.communityModel.create(community);
|
return this.communityModel.create(community);
|
||||||
|
@ -56,15 +56,15 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string) {
|
async remove(id: string) {
|
||||||
return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
|
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async changeStatus(id: string, status: string) {
|
async changeStatus(id: string, status: string) {
|
||||||
return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, {
|
return this.communityModel.findOneAndUpdate({ _id: id }, { status: status }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async findCommunityAdmin(community: string, user_type: string) {
|
async findCommunityAdmin(community: string, user_type: string) {
|
||||||
|
@ -78,4 +78,23 @@ export class CommunitiesService {
|
||||||
const finalValue = await lastValueFrom(callback);
|
const finalValue = await lastValueFrom(callback);
|
||||||
return finalValue['response'];
|
return finalValue['response'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async saveTenant(id: string, number_house: string, tenant_id: string) {
|
||||||
|
|
||||||
|
let community = await this.findOne(id);
|
||||||
|
|
||||||
|
await community.houses.map(house => {
|
||||||
|
if(house.number_house == number_house){
|
||||||
|
house.tenants.tenant_id = tenant_id
|
||||||
|
}
|
||||||
|
return house;
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(community.houses)
|
||||||
|
|
||||||
|
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
||||||
|
new: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,20 +229,15 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async findHousesCommunity(community_id: string) {
|
async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
|
||||||
const pattern = { cmd: 'findOneCommunity' }
|
const pattern = { cmd: 'saveTenant' }
|
||||||
const payload = { _id: community_id }
|
const payload = { _id: community_id, number_house: number_house, tenant_id: tenant_id }
|
||||||
|
|
||||||
let callback = await this.clientCommunityApp
|
return await this.clientCommunityApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(
|
.pipe(
|
||||||
map((response: string) => ({ response }))
|
map((response: string) => ({ response }))
|
||||||
)
|
)
|
||||||
const finalValue = await lastValueFrom(callback);
|
|
||||||
const response = finalValue['response'];
|
|
||||||
const houses = response['houses'];
|
|
||||||
|
|
||||||
return houses;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,16 +129,16 @@ const Inquilinos = () => {
|
||||||
email: document.getElementById('correo_electronico').value,
|
email: document.getElementById('correo_electronico').value,
|
||||||
phone: '',
|
phone: '',
|
||||||
password: '',
|
password: '',
|
||||||
community_id: document.getElementById('numero_vivienda').value,
|
community_id: cookies.community_id,
|
||||||
community_name: '',
|
community_name: '',
|
||||||
number_house: 'Sin número de vivienda',
|
number_house: document.getElementById('numero_vivienda').value,
|
||||||
date_entry: new Date(),
|
date_entry: new Date(),
|
||||||
user_type: '3',
|
user_type: '3',
|
||||||
status: '1',
|
status: '1',
|
||||||
status_text: '',
|
status_text: '',
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('http://localhost:3000/api/createUser', {
|
fetch('http://localhost:4000/user/createUser', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
body: JSON.stringify(newTenant),
|
body: JSON.stringify(newTenant),
|
||||||
|
@ -147,11 +147,31 @@ const Inquilinos = () => {
|
||||||
},
|
},
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
alert('Inquilino registrado correctamente')
|
return response.json()
|
||||||
} else {
|
} else {
|
||||||
alert('Error al registrar inquilino')
|
alert('Error al registrar inquilino')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
/* .then(res => {
|
||||||
|
console.log(data.message)
|
||||||
|
let data = {
|
||||||
|
community_id: cookies.community_id,
|
||||||
|
number_house: document.getElementById('numero_vivienda').value,
|
||||||
|
tenant_id: data.message._id
|
||||||
|
}
|
||||||
|
return fetch('http://localhost:4000/community/saveTenant',
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
cache: 'no-cache',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
).then(res => alert('Inquilino registrado correctamente'))
|
||||||
|
.catch(error => alert('Error al registrar inquilino'))
|
||||||
|
})
|
||||||
|
.catch(error => alert('Error al registrar inquilino'))*/
|
||||||
}
|
}
|
||||||
|
|
||||||
const deleteTenant = () => {
|
const deleteTenant = () => {
|
||||||
|
|
Loading…
Reference in New Issue