katoikia-app/api-gateway/src/app.service.ts

84 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-06-29 09:23:07 +00:00
import { Injectable, Inject } from '@nestjs/common';
2022-06-29 02:30:10 +00:00
import { ClientProxy } from "@nestjs/microservices";
import { map } from "rxjs/operators";
@Injectable()
export class AppService {
constructor(
2022-06-29 09:23:07 +00:00
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
2022-06-29 10:12:27 +00:00
@Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy,
2022-06-29 02:30:10 +00:00
) {}
2022-06-29 09:23:07 +00:00
//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){
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};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
);
}
2022-06-29 02:30:10 +00:00
2022-06-29 09:23:07 +00:00
allUsers(){
const pattern = { cmd: 'findAllUsers' };
2022-06-29 02:30:10 +00:00
const payload = {};
2022-06-29 09:23:07 +00:00
return this.clientUserApp
.send<string>(pattern, payload)
2022-06-29 02:30:10 +00:00
.pipe(
2022-06-29 09:23:07 +00:00
map((message: string) => ({ message})),
2022-06-29 02:30:10 +00:00
);
}
2022-06-29 09:23:07 +00:00
2022-06-29 10:12:27 +00:00
//GET parameter from API
findUser(paramUserDNI: string){
const pattern = { cmd: 'find' };
const payload = {dni: paramUserDNI};
return this.clientUserApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
);
}
//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){
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};
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
);
}
allCommunities(){
const pattern = { cmd: 'findAllCommunities' };
const payload = {};
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
);
}
//GET parameter from API
findCommunity(paramCommunityId: string){
const pattern = { cmd: 'findOneCommunity' };
const payload = {id: paramCommunityId};
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message})),
);
}
2022-06-29 02:30:10 +00:00
}