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);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @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
 | 
			
		||||
  @Post('commonArea/createCommonArea')
 | 
			
		||||
  createCommonArea(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -301,6 +301,13 @@ export class AppService {
 | 
			
		|||
    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 ===============================
 | 
			
		||||
  //POST parameter from API
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -53,4 +53,13 @@ export class CommunitiesController {
 | 
			
		|||
     let pstatus = body['status'];
 | 
			
		||||
     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)
 | 
			
		||||
    private readonly communityModel: Model<CommunityDocument>,
 | 
			
		||||
    @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
 | 
			
		||||
  ) {}
 | 
			
		||||
  ) { }
 | 
			
		||||
 | 
			
		||||
  async create(community: CommunityDocument): Promise<Community> {
 | 
			
		||||
    return this.communityModel.create(community);
 | 
			
		||||
| 
						 | 
				
			
			@ -56,15 +56,15 @@ export class CommunitiesService {
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  async remove(id: string) {
 | 
			
		||||
    return this.communityModel.findOneAndUpdate({ _id: id }, {status: '-1'}, {
 | 
			
		||||
    return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
 | 
			
		||||
      new: true,
 | 
			
		||||
    });  
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async changeStatus(id: string, status: string) {
 | 
			
		||||
    return this.communityModel.findOneAndUpdate({ _id: id }, {status: status}, {
 | 
			
		||||
    return this.communityModel.findOneAndUpdate({ _id: id }, { status: status }, {
 | 
			
		||||
      new: true,
 | 
			
		||||
    });  
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async findCommunityAdmin(community: string, user_type: string) {
 | 
			
		||||
| 
						 | 
				
			
			@ -78,4 +78,23 @@ export class CommunitiesService {
 | 
			
		|||
    const finalValue = await lastValueFrom(callback);
 | 
			
		||||
    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) {
 | 
			
		||||
    const pattern = { cmd: 'findOneCommunity' }
 | 
			
		||||
    const payload = { _id: community_id }
 | 
			
		||||
  async saveTenantNumHouse(community_id: string, number_house:string, tenant_id: string) {
 | 
			
		||||
    const pattern = { cmd: 'saveTenant' }
 | 
			
		||||
    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)
 | 
			
		||||
      .pipe(
 | 
			
		||||
        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,
 | 
			
		||||
      phone: '',
 | 
			
		||||
      password: '',
 | 
			
		||||
      community_id: document.getElementById('numero_vivienda').value,
 | 
			
		||||
      community_id: cookies.community_id,
 | 
			
		||||
      community_name: '',
 | 
			
		||||
      number_house: 'Sin número de vivienda',
 | 
			
		||||
      number_house: document.getElementById('numero_vivienda').value,
 | 
			
		||||
      date_entry: new Date(),
 | 
			
		||||
      user_type: '3',
 | 
			
		||||
      status: '1',
 | 
			
		||||
      status_text: '',
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fetch('http://localhost:3000/api/createUser', {
 | 
			
		||||
    fetch('http://localhost:4000/user/createUser', {
 | 
			
		||||
      method: 'POST',
 | 
			
		||||
      cache: 'no-cache',
 | 
			
		||||
      body: JSON.stringify(newTenant),
 | 
			
		||||
| 
						 | 
				
			
			@ -147,11 +147,31 @@ const Inquilinos = () => {
 | 
			
		|||
      },
 | 
			
		||||
    }).then((response) => {
 | 
			
		||||
      if (response.ok) {
 | 
			
		||||
        alert('Inquilino registrado correctamente')
 | 
			
		||||
        return response.json()
 | 
			
		||||
      } else {
 | 
			
		||||
        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 = () => {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue