update servicio comunidades

agregar acceso a mongo y agregar valores de subdocumentos
This commit is contained in:
Mariela 2022-06-30 19:42:50 -06:00
parent cc0e2348bb
commit 3bc61cbd4f
8 changed files with 139 additions and 51 deletions

View File

@ -5,7 +5,23 @@ import { AppService } from "./app.service";
export class AppController { export class AppController {
constructor(private readonly appService: AppService) { } 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') @Post('user/create')
createUser( createUser(
@Body('dni') dni: string, @Body('dni') dni: string,
@ -17,12 +33,14 @@ export class AppController {
@Body('user_type') user_type: string, @Body('user_type') user_type: string,
@Body('status') status: string, @Body('status') status: string,
@Body('date_entry') date_entry: Date, @Body('date_entry') date_entry: Date,
@Body('community_id') community_id: string,
) { ) {
return this.appService.createUser(dni, name, last_name, email, phone, password, 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') @Get('user/all')
allUsers() { allUsers() {
return this.appService.allUsers(); return this.appService.allUsers();
@ -50,10 +68,16 @@ export class AppController {
@Body('quote') quote: number, @Body('quote') quote: number,
@Body('status') status: string, @Body('status') status: string,
@Body('date_entry') date_entry: Date, @Body('date_entry') date_entry: Date,
@Body('houses') houses: {},
) { ) {
console.log(houses);
return this.appService.createCommunity(name, province, canton, return this.appService.createCommunity(name, province, canton,
district, num_houses, phone, district, num_houses, phone,
quote, status, date_entry); quote, status, date_entry, houses);
} }

View File

@ -8,77 +8,97 @@ export class AppService {
constructor( constructor(
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy, @Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
@Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy, @Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy,
) {} ) { }
// ====================== USERS ===============================
//POST parameter from API //POST parameter from API
createUser(dni: string, name: string, last_name: string, email: string, phone: number 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 pattern = { cmd: 'createUser' };
const payload = {dni: dni, name: name, last_name: last_name, email: email, phone: phone, const payload = {
password: password, user_type: user_type, status: status, date_entry: date_entry}; 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 return this.clientUserApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .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<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allUsers() {
const pattern = { cmd: 'findAllUsers' }; const pattern = { cmd: 'findAllUsers' };
const payload = {}; const payload = {};
return this.clientUserApp return this.clientUserApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .pipe(
map((message: string) => ({ message})), map((message: string) => ({ message })),
); );
} }
//GET parameter from API
//GET parameter from API findUser(paramUserDNI: string) {
findUser(paramUserDNI: string){ const pattern = { cmd: 'findUserDNI' };
const pattern = { cmd: 'find' }; const payload = { dni: paramUserDNI };
const payload = {dni: paramUserDNI};
return this.clientUserApp return this.clientUserApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .pipe(
map((message: string) => ({ message})), map((message: string) => ({ message })),
); );
} }
// ====================== COMMUNITIES ===============================
//POST parameter from API //POST parameter from API
createCommunity(name: string, province: string, canton: string, district: string 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 pattern = { cmd: 'createCommunity' };
const payload = {name: name, province: province, canton: canton, district: district, num_houses: num_houses, const payload = {
phone: phone, quote: quote, status: status, date_entry: date_entry}; 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 return this.clientCommunityApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .pipe(
map((message: string) => ({ message})), map((message: string) => ({ message })),
); );
} }
allCommunities(){ allCommunities() {
const pattern = { cmd: 'findAllCommunities' }; const pattern = { cmd: 'findAllCommunities' };
const payload = {}; const payload = {};
return this.clientCommunityApp return this.clientCommunityApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .pipe(
map((message: string) => ({ message})), map((message: string) => ({ message })),
); );
} }
//GET parameter from API
//GET parameter from API findCommunity(paramCommunityId: string) {
findCommunity(paramCommunityId: string){
const pattern = { cmd: 'findOneCommunity' }; const pattern = { cmd: 'findOneCommunity' };
const payload = {id: paramCommunityId}; const payload = { id: paramCommunityId };
return this.clientCommunityApp return this.clientCommunityApp
.send<string>(pattern, payload) .send<string>(pattern, payload)
.pipe( .pipe(
map((message: string) => ({ message})), map((message: string) => ({ message })),
); );
} }
} }

View File

@ -5,19 +5,20 @@ import { ClientsModule, Transport } from "@nestjs/microservices";
@Module({ @Module({
imports: [ ClientsModule.register([ imports: [
{ ClientsModule.register([
name: "SERVICIO_COMUNIDADES", {
transport: Transport.TCP, name: "SERVICIO_COMUNIDADES",
options: { transport: Transport.TCP,
host: "127.0.0.1", options: {
port: 3002 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`),
MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_comunidades?retryWrites=true&w=majority`), CommunitiesModule],
CommunitiesModule],
controllers: [], controllers: [],
providers: [], providers: [],
}) })
export class AppModule {} export class AppModule { }

View File

@ -1,8 +1,15 @@
import { Module } from '@nestjs/common'; 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 { Community, CommunitySchema } from '../schemas/community.schema';
@Module({ @Module({
imports: [
MongooseModule.forFeature([{ name: Community.name, schema: CommunitySchema }]),
],
controllers: [CommunitiesController], controllers: [CommunitiesController],
providers: [CommunitiesService] providers: [CommunitiesService]
}) })

View File

@ -32,6 +32,10 @@ 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();
} }

View File

@ -1,10 +1,10 @@
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose'; import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose'; import { Document } from 'mongoose';
import { House, HouseSchema } from './house.schema';
export type CommunityDocument = Community & Document; export type CommunityDocument = Community & Document;
@Schema({ collection: 'communities' }) @Schema({ collection: 'communities' })
export class Community { export class Community {
@ -34,8 +34,10 @@ export class Community {
@Prop() @Prop()
date_entry: Date; date_entry: Date;
@Prop({ type: HouseSchema })
houses: House
} }
export const CommunitySchema = SchemaFactory.createForClass(Community); export const CommunitySchema = SchemaFactory.createForClass(Community);

View File

@ -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);

View File

@ -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);