update servicio comunidades
agregar acceso a mongo y agregar valores de subdocumentos
This commit is contained in:
parent
cc0e2348bb
commit
3bc61cbd4f
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,32 @@ export class AppService {
|
||||||
@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
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(
|
||||||
|
map((message: string) => ({ message })),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//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
|
return this.clientUserApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(
|
.pipe(
|
||||||
|
@ -33,10 +53,9 @@ export class AppService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//GET parameter from API
|
//GET parameter from API
|
||||||
findUser(paramUserDNI: string) {
|
findUser(paramUserDNI: string) {
|
||||||
const pattern = { cmd: 'find' };
|
const pattern = { cmd: 'findUserDNI' };
|
||||||
const payload = { dni: paramUserDNI };
|
const payload = { dni: paramUserDNI };
|
||||||
return this.clientUserApp
|
return this.clientUserApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
|
@ -45,13 +64,16 @@ export class AppService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ====================== 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(
|
||||||
|
@ -69,7 +91,6 @@ export class AppService {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//GET parameter from API
|
//GET parameter from API
|
||||||
findCommunity(paramCommunityId: string) {
|
findCommunity(paramCommunityId: string) {
|
||||||
const pattern = { cmd: 'findOneCommunity' };
|
const pattern = { cmd: 'findOneCommunity' };
|
||||||
|
@ -80,5 +101,4 @@ export class AppService {
|
||||||
map((message: string) => ({ message })),
|
map((message: string) => ({ message })),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,7 +5,8 @@ import { ClientsModule, Transport } from "@nestjs/microservices";
|
||||||
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ ClientsModule.register([
|
imports: [
|
||||||
|
ClientsModule.register([
|
||||||
{
|
{
|
||||||
name: "SERVICIO_COMUNIDADES",
|
name: "SERVICIO_COMUNIDADES",
|
||||||
transport: Transport.TCP,
|
transport: Transport.TCP,
|
||||||
|
|
|
@ -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]
|
||||||
})
|
})
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
Loading…
Reference in New Issue