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 {
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);
}

View File

@ -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<string>(pattern, payload)
.send<string>(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<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allUsers() {
const pattern = { cmd: 'findAllUsers' };
const payload = {};
return this.clientUserApp
.send<string>(pattern, payload)
.send<string>(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<string>(pattern, payload)
.send<string>(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<string>(pattern, payload)
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
map((message: string) => ({ message })),
);
}
allCommunities(){
allCommunities() {
const pattern = { cmd: 'findAllCommunities' };
const payload = {};
return this.clientCommunityApp
.send<string>(pattern, payload)
.send<string>(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<string>(pattern, payload)
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
map((message: string) => ({ message })),
);
}
}

View File

@ -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 { }

View File

@ -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]
})

View File

@ -32,6 +32,10 @@ export class CommunitiesService {
});
}
async remove(id: string) {
return this.communityModel.findByIdAndRemove({ _id: id }).exec();
}

View File

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

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