get user admin comunidad de vivienda desde servicio comunidades
This commit is contained in:
parent
17604ace92
commit
31ef827baf
|
@ -110,6 +110,14 @@ export class AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Post('community/findCommunityAdmin')
|
||||||
|
findCommunityAdmin(
|
||||||
|
@Body('community_id') community_id: string,
|
||||||
|
) {
|
||||||
|
return this.appService.findCommunityAdmin(community_id);
|
||||||
|
}
|
||||||
|
|
||||||
// #==== API Common Areas
|
// #==== API Common Areas
|
||||||
@Post('commonArea/createCommonArea')
|
@Post('commonArea/createCommonArea')
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
|
|
@ -115,6 +115,18 @@ export class AppService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//GET parameter from API
|
||||||
|
findCommunityAdmin(community_id: string) {
|
||||||
|
const pattern = { cmd: 'findCommunityAdmin' };
|
||||||
|
const payload = { community_id: community_id };
|
||||||
|
return this.clientCommunityApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((message: string) => ({ message })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// ====================== COMMUNITIES ===============================
|
// ====================== COMMUNITIES ===============================
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
|
|
|
@ -29,6 +29,12 @@ export class CommunitiesController {
|
||||||
return this.communitiesService.findOneName(_id);
|
return this.communitiesService.findOneName(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* @MessagePattern({cmd: 'findCommunityAdmin'})
|
||||||
|
findCommunityAdmin(@Payload() community: any) {
|
||||||
|
let _community = community['community_id'];
|
||||||
|
return this.communitiesService.findCommunityAdmin(_community, "2");
|
||||||
|
}*/
|
||||||
|
|
||||||
@MessagePattern({cmd: 'updateCommunity'})
|
@MessagePattern({cmd: 'updateCommunity'})
|
||||||
update(@Payload() community: CommunityDocument) {
|
update(@Payload() community: CommunityDocument) {
|
||||||
return this.communitiesService.update(community.id, community);
|
return this.communitiesService.update(community.id, community);
|
||||||
|
|
|
@ -2,12 +2,23 @@ import { Module } from '@nestjs/common';
|
||||||
import { CommunitiesService } from './communities.service';
|
import { CommunitiesService } from './communities.service';
|
||||||
import { CommunitiesController } from './communities.controller';
|
import { CommunitiesController } from './communities.controller';
|
||||||
import { MongooseModule } from '@nestjs/mongoose';
|
import { MongooseModule } from '@nestjs/mongoose';
|
||||||
|
import { ClientsModule, Transport } from "@nestjs/microservices";
|
||||||
|
|
||||||
import { Community, CommunitySchema } from '../schemas/community.schema';
|
import { Community, CommunitySchema } from '../schemas/community.schema';
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
|
{
|
||||||
|
name: "SERVICIO_USUARIOS",
|
||||||
|
transport: Transport.TCP,
|
||||||
|
options: {
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 3001
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]),
|
||||||
MongooseModule.forFeature([{ name: Community.name, schema: CommunitySchema }]),
|
MongooseModule.forFeature([{ name: Community.name, schema: CommunitySchema }]),
|
||||||
],
|
],
|
||||||
controllers: [CommunitiesController],
|
controllers: [CommunitiesController],
|
||||||
|
|
|
@ -1,13 +1,20 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Inject } from '@nestjs/common';
|
||||||
import { Model } from 'mongoose';
|
import { Model } from 'mongoose';
|
||||||
import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
||||||
import { InjectModel } from '@nestjs/mongoose';
|
import { InjectModel } from '@nestjs/mongoose';
|
||||||
|
import { RpcException, ClientProxy } from '@nestjs/microservices';
|
||||||
|
import { from, lastValueFrom, map, scan, mergeMap } from 'rxjs';
|
||||||
|
import { Admin } from 'src/schemas/admin.entity';
|
||||||
|
import { appendFileSync } from 'fs';
|
||||||
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CommunitiesService {
|
export class CommunitiesService {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@InjectModel(Community.name) private readonly communityModel: Model<CommunityDocument>,
|
@InjectModel(Community.name) private readonly communityModel: Model<CommunityDocument>,
|
||||||
|
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
|
||||||
|
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(community: CommunityDocument): Promise<Community> {
|
async create(community: CommunityDocument): Promise<Community> {
|
||||||
|
@ -15,10 +22,29 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<Community[]> {
|
async findAll(): Promise<Community[]> {
|
||||||
return this.communityModel
|
|
||||||
|
return await this.communityModel
|
||||||
.find()
|
.find()
|
||||||
.setOptions({ sanitizeFilter: true })
|
.setOptions({ sanitizeFilter: true })
|
||||||
.exec();
|
.exec()
|
||||||
|
.then( async community => {
|
||||||
|
if(community){
|
||||||
|
await Promise.all(community.map(async c => {
|
||||||
|
let admin = await this.findCommunityAdmin(c["_id"], "2")
|
||||||
|
if(admin){
|
||||||
|
c["id_admin"] = admin["_id"]
|
||||||
|
c["name_admin"] = admin["name"]
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}))
|
||||||
|
|
||||||
|
console.log(community)
|
||||||
|
}
|
||||||
|
|
||||||
|
return community;
|
||||||
|
})
|
||||||
|
|
||||||
|
//buscar al usuario con el id de la comunidad anexado
|
||||||
}
|
}
|
||||||
|
|
||||||
findOne(id: string): Promise<Community> {
|
findOne(id: string): Promise<Community> {
|
||||||
|
@ -37,4 +63,19 @@ export class CommunitiesService {
|
||||||
async remove(id: string) {
|
async remove(id: string) {
|
||||||
return this.communityModel.findByIdAndRemove({ _id: id }).exec();
|
return this.communityModel.findByIdAndRemove({ _id: id }).exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findCommunityAdmin(community: string, user_type: string) {
|
||||||
|
const pattern = { cmd: 'findOneCommunityUser' }
|
||||||
|
const payload = { community_id: community, user_type: user_type }
|
||||||
|
|
||||||
|
let callback = await this.clientUserApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((response: string) => ({ response }))
|
||||||
|
)
|
||||||
|
|
||||||
|
const finalValue = await lastValueFrom(callback);
|
||||||
|
return finalValue['response'];
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
export interface Admin {
|
||||||
|
id_community: string;
|
||||||
|
user_type: string;
|
||||||
|
}
|
|
@ -7,6 +7,11 @@ export type CommunityDocument = Community & Document;
|
||||||
|
|
||||||
@Schema({ collection: 'communities' })
|
@Schema({ collection: 'communities' })
|
||||||
export class Community {
|
export class Community {
|
||||||
|
@Prop()
|
||||||
|
id_admin: string;
|
||||||
|
|
||||||
|
@Prop({ default: "Sin Administrador" })
|
||||||
|
name_admin: string ;
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
name: string;
|
name: string;
|
||||||
|
@ -37,6 +42,7 @@ export class Community {
|
||||||
|
|
||||||
@Prop({ type: [HouseSchema] })
|
@Prop({ type: [HouseSchema] })
|
||||||
houses: Array<House>;
|
houses: Array<House>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,9 @@ export class House extends Document {
|
||||||
@Prop({ default: " " })
|
@Prop({ default: " " })
|
||||||
number_house: string;
|
number_house: string;
|
||||||
|
|
||||||
|
@Prop({ default: " " })
|
||||||
|
description: string;
|
||||||
|
|
||||||
@Prop({ default: "desocupada" })
|
@Prop({ default: "desocupada" })
|
||||||
state: string;
|
state: string;
|
||||||
|
|
||||||
|
|
|
@ -66,4 +66,13 @@ export class UsersController {
|
||||||
testSendMail(@Payload() user: UserDocument) {
|
testSendMail(@Payload() user: UserDocument) {
|
||||||
return this.userService.testSendMail(user);
|
return this.userService.testSendMail(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//buscar usuario de una comunidad
|
||||||
|
@MessagePattern({ cmd: 'findOneCommunityUser' })
|
||||||
|
findCommunityUser(@Payload() user: any) {
|
||||||
|
return this.userService.findCommunityUser(user["community_id"], user["user_type"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,4 +99,10 @@ export class UsersService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async findCommunityUser(community_id: string, user_type: number): Promise<User> {
|
||||||
|
return this.userModel.findOne({ community_id: community_id, user_type: user_type }).exec();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,16 @@ const Communities = () => {
|
||||||
<div className="grid">
|
<div className="grid">
|
||||||
<div className="col-12">
|
<div className="col-12">
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<h5>Administradores de comunidad</h5>
|
<h5>Comunidades de Viviendas</h5>
|
||||||
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
<DataTable value={communitiesList} scrollable scrollHeight="400px" scrollDirection="both" className="mt-3">
|
||||||
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="name" header="Nombre" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="last_name" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="province" header="Provincia" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="dni" header="Cantón" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="canton" header="Cantón" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="email" header="Distrito" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
<Column field="district" header="Distrito" style={{ flexGrow: 1, flexBasis: '160px' }}></Column>
|
||||||
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
<Column field="phone" header="Telefóno" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||||
|
<Column field="num_houses" header="Número de viviendas" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||||
|
<Column field="quote" header="Cuota mensual" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||||
|
<Column field="name_admin" header="Administrador" style={{ flexGrow: 1, flexBasis: '180px' }}></Column>
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue