update microservicios-areas-comunes
agregar schema y metodos de microservicios agregar conexion a bd y api gateway
This commit is contained in:
parent
0526b7ac18
commit
f11aa85bd6
|
@ -22,7 +22,7 @@ export class AppController {
|
|||
user_type, status, date_entry);
|
||||
}
|
||||
|
||||
@Post('user/create')
|
||||
@Post('user/createUser')
|
||||
createUser(
|
||||
@Body('dni') dni: string,
|
||||
@Body('name') name: string,
|
||||
|
@ -39,23 +39,20 @@ export class AppController {
|
|||
user_type, status, date_entry, community_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Get('user/all')
|
||||
@Get('user/allUsers')
|
||||
allUsers() {
|
||||
return this.appService.allUsers();
|
||||
}
|
||||
|
||||
|
||||
@Get('user/find/:dni')
|
||||
findUser(
|
||||
@Param('dni') paramUserDNI: string
|
||||
){
|
||||
) {
|
||||
return this.appService.findUser(paramUserDNI);
|
||||
}
|
||||
|
||||
|
||||
// #==== API Communities
|
||||
// #==== API Communities
|
||||
//#API orderService - create order
|
||||
@Post('community/createCommunity')
|
||||
createCommunity(
|
||||
|
@ -71,25 +68,50 @@ export class AppController {
|
|||
@Body('houses') houses: [{}],
|
||||
|
||||
) {
|
||||
|
||||
|
||||
|
||||
return this.appService.createCommunity(name, province, canton,
|
||||
district, num_houses, phone,
|
||||
quote, status, date_entry, houses);
|
||||
}
|
||||
|
||||
|
||||
@Get('community/allCommunities')
|
||||
allcommunities() {
|
||||
return this.appService.allCommunities();
|
||||
}
|
||||
|
||||
|
||||
@Get('community/findCommunity/:id')
|
||||
findCommunity(
|
||||
@Param('dni') paramCommunityId: string
|
||||
){
|
||||
@Param('id') paramCommunityId: string
|
||||
) {
|
||||
return this.appService.findCommunity(paramCommunityId);
|
||||
}
|
||||
|
||||
|
||||
// #==== API Common Areas
|
||||
//#API orderService - create order
|
||||
@Post('commonArea/createCommonArea')
|
||||
createCommonArea(
|
||||
@Body('name') name: string,
|
||||
@Body('hourMin') hourMin: string,
|
||||
@Body('hourMax') hourMax: string,
|
||||
@Body('bookable') bookable: number,
|
||||
@Body('community_id') community_id: string,
|
||||
) {
|
||||
|
||||
return this.appService.createCommonArea(name, hourMin, hourMax,
|
||||
bookable, community_id);
|
||||
}
|
||||
|
||||
|
||||
@Get('commonArea/allCommonAreas')
|
||||
allCommonAreas() {
|
||||
return this.appService.allCommonAreas();
|
||||
}
|
||||
|
||||
|
||||
@Get('commonArea/findCommonArea/:id')
|
||||
findCommonArea(
|
||||
@Param('id') paramCommonAreaId: string
|
||||
) {
|
||||
return this.appService.findCommonArea(paramCommonAreaId);
|
||||
}
|
||||
}
|
|
@ -25,6 +25,16 @@ import { AppService } from './app.service';
|
|||
}
|
||||
}
|
||||
]),
|
||||
ClientsModule.register([
|
||||
{
|
||||
name: "SERVICIO_AREAS_COMUNES",
|
||||
transport: Transport.TCP,
|
||||
options: {
|
||||
host: "127.0.0.1",
|
||||
port: 3003
|
||||
}
|
||||
}
|
||||
]),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
|
|
@ -8,6 +8,7 @@ export class AppService {
|
|||
constructor(
|
||||
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
|
||||
@Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy,
|
||||
@Inject('SERVICIO_AREAS_COMUNES') private readonly clientCommonAreaApp: ClientProxy,
|
||||
) { }
|
||||
|
||||
// ====================== USERS ===============================
|
||||
|
@ -81,8 +82,6 @@ export class AppService {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
allCommunities() {
|
||||
const pattern = { cmd: 'findAllCommunities' };
|
||||
const payload = {};
|
||||
|
@ -103,4 +102,44 @@ export class AppService {
|
|||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ====================== COMMON AREAS ===============================
|
||||
//POST parameter from API
|
||||
createCommonArea(name: string, hourMin: string, hourMax: string,
|
||||
bookable: number, community_id: string) {
|
||||
const pattern = { cmd: 'createCommonArea' };
|
||||
const payload = {
|
||||
name: name, hourMin: hourMin, hourMax: hourMax, bookable: bookable,
|
||||
community_id: community_id
|
||||
};
|
||||
return this.clientCommonAreaApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
allCommonAreas() {
|
||||
const pattern = { cmd: 'findAllCommonAreas' };
|
||||
const payload = {};
|
||||
return this.clientCommonAreaApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
//GET parameter from API
|
||||
findCommonArea(paramCommonAreaId: string) {
|
||||
const pattern = { cmd: 'findOneCommonArea' };
|
||||
const payload = { id: paramCommonAreaId };
|
||||
return this.clientCommonAreaApp
|
||||
.send<string>(pattern, payload)
|
||||
.pipe(
|
||||
map((message: string) => ({ message })),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
"@nestjs/core": "^8.0.0",
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/microservices": "^8.4.7",
|
||||
"@nestjs/mongoose": "^9.1.1",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
"dependencies": {
|
||||
"@nestjs/common": "^8.0.0",
|
||||
"@nestjs/core": "^8.0.0",
|
||||
"@nestjs/mapped-types": "*",
|
||||
"@nestjs/microservices": "^8.4.7",
|
||||
"@nestjs/mongoose": "^9.1.1",
|
||||
"@nestjs/platform-express": "^8.0.0",
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
import { Controller, Get } from '@nestjs/common';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor() {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return "hello world";
|
||||
}
|
||||
}
|
|
@ -1,8 +1,23 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { CommonAreasModule } from './common_areas/common_areas.module';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
import { ClientsModule, Transport } from "@nestjs/microservices";
|
||||
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
imports: [
|
||||
ClientsModule.register([
|
||||
{
|
||||
name: "SERVICIO_AREAS_COMUNES",
|
||||
transport: Transport.TCP,
|
||||
options: {
|
||||
host: "127.0.0.1",
|
||||
port: 3003
|
||||
}
|
||||
}
|
||||
]),
|
||||
MongooseModule.forRoot(`mongodb+srv://proyecto_4:proyecto_4@proyecto4.yv4fb.mongodb.net/servicio_areas_comunes?retryWrites=true&w=majority`),
|
||||
CommonAreasModule],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
})
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
import { MessagePattern, Payload } from '@nestjs/microservices';
|
||||
import { CommonAreaDocument } from 'src/schemas/common_area.schema';
|
||||
import { CommonAreasService } from './common_areas.service';
|
||||
|
||||
@Controller()
|
||||
export class CommonAreasController {
|
||||
constructor(private readonly commonAreasService: CommonAreasService) {}
|
||||
|
||||
@MessagePattern({cmd: 'createCommonArea'})
|
||||
create(@Payload() commonArea: CommonAreaDocument) {
|
||||
return this.commonAreasService.create(commonArea);
|
||||
}
|
||||
|
||||
@MessagePattern({cmd: 'findAllCommonAreas'})
|
||||
findAll() {
|
||||
return this.commonAreasService.findAll();
|
||||
}
|
||||
|
||||
@MessagePattern({cmd: 'findOneCommonArea'})
|
||||
findOne(@Payload() id: string) {
|
||||
return this.commonAreasService.findOne(id);
|
||||
}
|
||||
|
||||
@MessagePattern({cmd: 'updateCommonArea'})
|
||||
update(@Payload() commonArea: CommonAreaDocument) {
|
||||
return this.commonAreasService.update(commonArea.id, commonArea);
|
||||
}
|
||||
|
||||
@MessagePattern({cmd: 'removeCommonArea'})
|
||||
remove(@Payload() id: string) {
|
||||
return this.commonAreasService.remove(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { CommonAreasService } from './common_areas.service';
|
||||
import { CommonAreasController } from './common_areas.controller';
|
||||
import { MongooseModule } from '@nestjs/mongoose';
|
||||
|
||||
import { CommonArea, CommonAreaSchema } from '../schemas/common_area.schema';
|
||||
@Module({
|
||||
imports: [
|
||||
MongooseModule.forFeature([{ name: CommonArea.name, schema: CommonAreaSchema }]),
|
||||
],
|
||||
controllers: [CommonAreasController],
|
||||
providers: [CommonAreasService]
|
||||
})
|
||||
export class CommonAreasModule {}
|
|
@ -0,0 +1,37 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { CommonArea, CommonAreaDocument } from 'src/schemas/common_area.schema';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model } from 'mongoose';
|
||||
|
||||
@Injectable()
|
||||
export class CommonAreasService {
|
||||
|
||||
constructor(
|
||||
@InjectModel(CommonArea.name) private readonly commonAreaModel: Model<CommonAreaDocument>,
|
||||
) {}
|
||||
|
||||
async create(commonArea: CommonAreaDocument): Promise<CommonArea> {
|
||||
return this.commonAreaModel.create(commonArea);
|
||||
}
|
||||
|
||||
async findAll(): Promise<CommonArea[]> {
|
||||
return this.commonAreaModel
|
||||
.find()
|
||||
.setOptions({ sanitizeFilter: true })
|
||||
.exec();
|
||||
}
|
||||
|
||||
findOne(id: string): Promise<CommonArea> {
|
||||
return this.commonAreaModel.findOne({ _id: id }).exec();
|
||||
}
|
||||
|
||||
update(id: string, commonArea: CommonAreaDocument) {
|
||||
return this.commonAreaModel.findOneAndUpdate({ _id: id }, commonArea, {
|
||||
new: true,
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.commonAreaModel.findByIdAndRemove({ _id: id }).exec();
|
||||
}
|
||||
}
|
|
@ -1,8 +1,18 @@
|
|||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { NestFactory } from "@nestjs/core";
|
||||
import { Transport } from "@nestjs/microservices";
|
||||
import { AppModule } from "./app.module";
|
||||
import { Logger } from "@nestjs/common";
|
||||
|
||||
const logger = new Logger();
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
const app = await NestFactory.createMicroservice(AppModule, {
|
||||
transport: Transport.TCP,
|
||||
options: {
|
||||
host: "127.0.0.1",
|
||||
port: 3003
|
||||
}
|
||||
});
|
||||
app.listen().then(() => logger.log("Microservice Áreas Comunes is listening" ));
|
||||
}
|
||||
bootstrap();
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document } from 'mongoose';
|
||||
import { Timestamp } from 'rxjs';
|
||||
import { TimerOptions } from 'timers';
|
||||
|
||||
|
||||
export type CommonAreaDocument = CommonArea & Document;
|
||||
|
||||
@Schema({ collection: 'common_areas' })
|
||||
export class CommonArea {
|
||||
|
||||
@Prop()
|
||||
name: string;
|
||||
|
||||
@Prop()
|
||||
hourMin: string; //hora militar, separado por dos puntos
|
||||
|
||||
@Prop()
|
||||
hourMax: string; //hora militar, separado por dos puntos
|
||||
|
||||
@Prop()
|
||||
bookable: number; //saber si es necesario reservarlo o no
|
||||
|
||||
@Prop()
|
||||
community_id: string;
|
||||
}
|
||||
|
||||
export const CommonAreaSchema = SchemaFactory.createForClass(CommonArea);
|
|
@ -1,5 +1,4 @@
|
|||
import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
|
||||
import { Document } from 'mongoose';
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue