diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index c0959dd9..898e3b54 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -5,7 +5,23 @@ import { AppService } from "./app.service"; export class AppController { constructor(private readonly appService: AppService) { } - //#API orderService - create order + //#API userService - create user + @Post('user/createAdminSystem') + createAdminSystem( + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @Body('password') password: string, + @Body('user_type') user_type: string, + @Body('status') status: string, + @Body('date_entry') date_entry: Date, + ) { + return this.appService.createAdminSystem(dni, name, last_name, email, phone, password, + user_type, status, date_entry); + } + @Post('user/create') createUser( @Body('dni') dni: string, @@ -17,12 +33,14 @@ export class AppController { @Body('user_type') user_type: string, @Body('status') status: string, @Body('date_entry') date_entry: Date, + @Body('community_id') community_id: string, ) { return this.appService.createUser(dni, name, last_name, email, phone, password, - user_type, status, date_entry); + user_type, status, date_entry, community_id); } + @Get('user/all') allUsers() { return this.appService.allUsers(); @@ -50,10 +68,16 @@ export class AppController { @Body('quote') quote: number, @Body('status') status: string, @Body('date_entry') date_entry: Date, + @Body('houses') houses: {}, + ) { + console.log(houses); + + + return this.appService.createCommunity(name, province, canton, district, num_houses, phone, - quote, status, date_entry); + quote, status, date_entry, houses); } diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 98c56fd8..53f8e015 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -8,77 +8,97 @@ export class AppService { constructor( @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, @Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy, - ) {} - + ) { } + + // ====================== USERS =============================== + //POST parameter from API createUser(dni: string, name: string, last_name: string, email: string, phone: number - , password: string , user_type: string, status: string, date_entry: Date){ + , password: string, user_type: string, status: string, date_entry: Date, community_id: string) { const pattern = { cmd: 'createUser' }; - const payload = {dni: dni, name: name, last_name: last_name, email: email, phone: phone, - password: password, user_type: user_type, status: status, date_entry: date_entry}; + const payload = { + dni: dni, name: name, last_name: last_name, email: email, phone: phone, + password: password, user_type: user_type, status: status, date_entry: date_entry, + community_id: community_id + }; return this.clientUserApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), + map((message: string) => ({ message })), ); } - allUsers(){ + //POST parameter from API + createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number + , password: string, user_type: string, status: string, date_entry: Date) { + const pattern = { cmd: 'createAdminSystem' }; + const payload = { + dni: dni, name: name, last_name: last_name, email: email, phone: phone, + password: password, user_type: user_type, status: status, date_entry: date_entry + }; + return this.clientUserApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + allUsers() { const pattern = { cmd: 'findAllUsers' }; const payload = {}; return this.clientUserApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), + map((message: string) => ({ message })), ); } - - //GET parameter from API - findUser(paramUserDNI: string){ - const pattern = { cmd: 'find' }; - const payload = {dni: paramUserDNI}; + //GET parameter from API + findUser(paramUserDNI: string) { + const pattern = { cmd: 'findUserDNI' }; + const payload = { dni: paramUserDNI }; return this.clientUserApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), - ); + map((message: string) => ({ message })), + ); } + // ====================== COMMUNITIES =============================== //POST parameter from API createCommunity(name: string, province: string, canton: string, district: string - , num_houses: number , phone: number, quote: number, status: string, date_entry: Date){ + , num_houses: number, phone: number, quote: number, status: string, date_entry: Date, houses: {}) { const pattern = { cmd: 'createCommunity' }; - const payload = {name: name, province: province, canton: canton, district: district, num_houses: num_houses, - phone: phone, quote: quote, status: status, date_entry: date_entry}; + const payload = { + name: name, province: province, canton: canton, district: district, num_houses: num_houses, + phone: phone, quote: quote, status: status, date_entry: date_entry, houses + }; return this.clientCommunityApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), + map((message: string) => ({ message })), ); } - allCommunities(){ + allCommunities() { const pattern = { cmd: 'findAllCommunities' }; const payload = {}; return this.clientCommunityApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), + map((message: string) => ({ message })), ); } - - //GET parameter from API - findCommunity(paramCommunityId: string){ + //GET parameter from API + findCommunity(paramCommunityId: string) { const pattern = { cmd: 'findOneCommunity' }; - const payload = {id: paramCommunityId}; + const payload = { id: paramCommunityId }; return this.clientCommunityApp - .send(pattern, payload) + .send(pattern, payload) .pipe( - map((message: string) => ({ message})), - ); + map((message: string) => ({ message })), + ); } - } \ No newline at end of file diff --git a/servicio-comunidad-viviendas/src/app.module.ts b/servicio-comunidad-viviendas/src/app.module.ts index aad08704..fed96129 100644 --- a/servicio-comunidad-viviendas/src/app.module.ts +++ b/servicio-comunidad-viviendas/src/app.module.ts @@ -5,19 +5,20 @@ import { ClientsModule, Transport } from "@nestjs/microservices"; @Module({ - imports: [ ClientsModule.register([ - { - name: "SERVICIO_COMUNIDADES", - transport: Transport.TCP, - options: { - host: "127.0.0.1", - port: 3002 + imports: [ + ClientsModule.register([ + { + name: "SERVICIO_COMUNIDADES", + transport: Transport.TCP, + options: { + host: "127.0.0.1", + port: 3002 + } } - } - ]), - MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_comunidades?retryWrites=true&w=majority`), - CommunitiesModule], + ]), + MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_comunidades?retryWrites=true&w=majority`), + CommunitiesModule], controllers: [], providers: [], }) -export class AppModule {} +export class AppModule { } diff --git a/servicio-comunidad-viviendas/src/communities/communities.module.ts b/servicio-comunidad-viviendas/src/communities/communities.module.ts index dc761451..e515e738 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.module.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.module.ts @@ -1,8 +1,15 @@ import { Module } from '@nestjs/common'; import { CommunitiesService } from './communities.service'; import { CommunitiesController } from './communities.controller'; +import { MongooseModule } from '@nestjs/mongoose'; + +import { Community, CommunitySchema } from '../schemas/community.schema'; + @Module({ + imports: [ + MongooseModule.forFeature([{ name: Community.name, schema: CommunitySchema }]), + ], controllers: [CommunitiesController], providers: [CommunitiesService] }) diff --git a/servicio-comunidad-viviendas/src/communities/communities.service.ts b/servicio-comunidad-viviendas/src/communities/communities.service.ts index 4375668b..f953c670 100644 --- a/servicio-comunidad-viviendas/src/communities/communities.service.ts +++ b/servicio-comunidad-viviendas/src/communities/communities.service.ts @@ -32,6 +32,10 @@ export class CommunitiesService { }); } + + + + async remove(id: string) { return this.communityModel.findByIdAndRemove({ _id: id }).exec(); } diff --git a/servicio-comunidad-viviendas/src/schemas/community.schema.ts b/servicio-comunidad-viviendas/src/schemas/community.schema.ts index 05cbdfd7..64d997fe 100644 --- a/servicio-comunidad-viviendas/src/schemas/community.schema.ts +++ b/servicio-comunidad-viviendas/src/schemas/community.schema.ts @@ -1,10 +1,10 @@ import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; import { Document } from 'mongoose'; +import { House, HouseSchema } from './house.schema'; export type CommunityDocument = Community & Document; - @Schema({ collection: 'communities' }) export class Community { @@ -34,8 +34,10 @@ export class Community { @Prop() date_entry: Date; + + @Prop({ type: HouseSchema }) + houses: House } - export const CommunitySchema = SchemaFactory.createForClass(Community); \ No newline at end of file diff --git a/servicio-comunidad-viviendas/src/schemas/house.schema.ts b/servicio-comunidad-viviendas/src/schemas/house.schema.ts new file mode 100644 index 00000000..0ee35e1d --- /dev/null +++ b/servicio-comunidad-viviendas/src/schemas/house.schema.ts @@ -0,0 +1,18 @@ +import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; +import { Document } from 'mongoose'; +import { Tenant, TenantSchema } from './tenant.schema'; + + + +@Schema() +export class House extends Document { + @Prop({ default: " " }) + number: string; + + @Prop({ default: " " }) + description: string; + + @Prop({ type: TenantSchema, default: " " }) + tenants: Tenant; +} +export const HouseSchema = SchemaFactory.createForClass(House); \ No newline at end of file diff --git a/servicio-comunidad-viviendas/src/schemas/tenant.schema.ts b/servicio-comunidad-viviendas/src/schemas/tenant.schema.ts new file mode 100644 index 00000000..489c2326 --- /dev/null +++ b/servicio-comunidad-viviendas/src/schemas/tenant.schema.ts @@ -0,0 +1,12 @@ +import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; +import { Document } from 'mongoose'; + + + +@Schema() +export class Tenant { + @Prop() + tenant_id: string; +} + +export const TenantSchema = SchemaFactory.createForClass(Tenant); \ No newline at end of file