add column numero de vivienda

This commit is contained in:
Mariela 2022-07-31 20:02:13 -06:00
parent 9cac88f333
commit 18ab1f4700
4 changed files with 45 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import { Tenant, TenantSchema } from './tenant.schema';
@Schema() @Schema()
export class House extends Document { export class House extends Document {
@Prop({ default: ' ' }) @Prop({ default: ' ' })
number: string; number_house: string;
@Prop({ default: 'desocupada' }) @Prop({ default: 'desocupada' })
state: string; state: string;

View File

@ -36,6 +36,9 @@ export class User {
@Prop() @Prop()
community_id?: string; community_id?: string;
@Prop()
number_house?: string;
} }
export const UserSchema = SchemaFactory.createForClass(User); export const UserSchema = SchemaFactory.createForClass(User);

View File

@ -127,13 +127,28 @@ export class UsersService {
//find inquilinos //find inquilinos
async findTenantsCommunity(pcommunity_id: string): Promise<User[]> { async findTenantsCommunity(pcommunity_id: string) {
let houses = await this.findCommunityHouses(pcommunity_id); //let tenants = await this.findCommunityTenants(pcommunity_id);
return this.userModel.find({ community_id: pcommunity_id, user_type: 4 }).exec()
.then();
return await this.userModel.find({ community_id: pcommunity_id, user_type: 4 })
.then(async (users) => {
if (users) {
await Promise.all(
users.map(async (u) => {
//buscar al usuario con el id de la comunidad anexado
let number_house = await this.findNumHouseTenant(pcommunity_id, u['_id']);
u['number_house'] = number_house;
return u;
}),
)
}
return users;
})
} }
async testSendMail(user: UserDocument) { async testSendMail(user: UserDocument) {
let passwordEncriptada = Md5.init(user.password); let passwordEncriptada = Md5.init(user.password);
user.password = passwordEncriptada; user.password = passwordEncriptada;
@ -179,7 +194,7 @@ export class UsersService {
}); });
} }
async findCommunityHouses(community_id: string) { async findNumHouseTenant(community_id: string, tenant_id: string) {
const pattern = { cmd: 'findOneCommunity' } const pattern = { cmd: 'findOneCommunity' }
const payload = { _id: community_id } const payload = { _id: community_id }
@ -190,8 +205,15 @@ export class UsersService {
) )
const finalValue = await lastValueFrom(callback); const finalValue = await lastValueFrom(callback);
const response = finalValue['response']; const response = finalValue['response'];
console.log(response['houses']); const houses = response['houses'];
return response['houses']; let num_house = "";
await houses.forEach(async house => {
if (tenant_id == house.tenants.tenant_id) {
num_house = house.number_house;
}
})
return num_house;
} }
} }

View File

@ -31,6 +31,7 @@ const Inquilinos = () => {
password: '', password: '',
community_id: '', community_id: '',
community_name: '', community_name: '',
number_house: 'Sin número de vivienda',
user_type: '4', user_type: '4',
date_entry: new Date(), date_entry: new Date(),
status: '1' status: '1'
@ -55,7 +56,15 @@ const Inquilinos = () => {
await fetch(`http://localhost:4000/user/findTenants/${cookies.community_id}`, { method: 'GET' }) await fetch(`http://localhost:4000/user/findTenants/${cookies.community_id}`, { method: 'GET' })
.then((response) => response.json()) .then((response) => response.json())
.then(data => data.message) .then(data => data.message)
.then(data => setTenants(data)); .then(data => {
data.map((item) => {
if(item.number_house ==""){
item.number_house = "Sin vivienda asignada";
}
})
setTenants(data)
});
} }
@ -279,11 +288,7 @@ const Inquilinos = () => {
</> </>
) )
const headerCommuntiy = (
<>
<p> <FontAwesomeIcon icon={faHome} style={{ color: "#D7A86E" }} /> Comunidad</p>
</>
)
const headerNumberHouse = ( const headerNumberHouse = (
<> <>
@ -315,7 +320,7 @@ const Inquilinos = () => {
</Column> </Column>
<Column field="email" sortable header={headerEmail} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="email" sortable header={headerEmail} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="phone" header={headerPhone} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="phone" header={headerPhone} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column field="community_name" header={headerCommuntiy} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column> <Column field="number_house" header={headerNumberHouse} style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}></Column>
<Column header={headerOptions} style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsTenant}></Column> <Column header={headerOptions} style={{ flexGrow: 1, flexBasis: '130px', minWidth: '130px' }} body={actionsTenant}></Column>
</DataTable> </DataTable>
<Dialog visible={deleteTenantDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantDialogFooter} onHide={hideDeleteTenantDialog}> <Dialog visible={deleteTenantDialog} style={{ width: '450px' }} header="Confirmar" modal footer={deleteTenantDialogFooter} onHide={hideDeleteTenantDialog}>