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

228 lines
7.0 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,
@Inject('SERVICIO_AREAS_COMUNES') private readonly clientCommonAreaApp: ClientProxy,
@Inject('SERVICIO_INVITADOS') private readonly clientGuestApp: ClientProxy,
@Inject('SERVICIO_PAGOS') private readonly clientPaymentApp: ClientProxy,
@Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy,
) { }
// ====================== USERS ===============================
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, community_id: string) {
2022-06-29 09:23:07 +00:00
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,
community_id: community_id
};
2022-06-29 09:23:07 +00:00
return this.clientUserApp
.send<string>(pattern, payload)
2022-06-29 09:23:07 +00:00
.pipe(
map((message: string) => ({ message })),
2022-06-29 09:23:07 +00:00
);
}
2022-06-29 02:30:10 +00:00
//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() {
2022-06-29 09:23:07 +00:00
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(
map((message: string) => ({ message })),
2022-06-29 02:30:10 +00:00
);
}
2022-06-29 10:12:27 +00:00
//GET parameter from API
findUser(paramUserDNI: string) {
const pattern = { cmd: 'findUserDNI' };
const payload = { dni: paramUserDNI };
2022-06-29 10:12:27 +00:00
return this.clientUserApp
.send<string>(pattern, payload)
2022-06-29 10:12:27 +00:00
.pipe(
map((message: string) => ({ message })),
);
2022-06-29 10:12:27 +00:00
}
// ====================== COMMUNITIES ===============================
2022-06-29 10:12:27 +00:00
//POST parameter from API
createCommunity(name: string, province: string, canton: string, district: string
2022-07-01 03:22:54 +00:00
, num_houses: number, phone: number, quote: number, status: string, date_entry: Date, houses: [{}]) {
2022-06-29 10:12:27 +00:00
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, houses
};
2022-06-29 10:12:27 +00:00
return this.clientCommunityApp
.send<string>(pattern, payload)
2022-06-29 10:12:27 +00:00
.pipe(
map((message: string) => ({ message })),
2022-06-29 10:12:27 +00:00
);
}
allCommunities() {
2022-06-29 10:12:27 +00:00
const pattern = { cmd: 'findAllCommunities' };
const payload = {};
return this.clientCommunityApp
.send<string>(pattern, payload)
2022-06-29 10:12:27 +00:00
.pipe(
map((message: string) => ({ message })),
2022-06-29 10:12:27 +00:00
);
}
//GET parameter from API
findCommunity(paramCommunityId: string) {
2022-06-29 10:12:27 +00:00
const pattern = { cmd: 'findOneCommunity' };
const payload = { id: paramCommunityId };
2022-06-29 10:12:27 +00:00
return this.clientCommunityApp
.send<string>(pattern, payload)
2022-06-29 10:12:27 +00:00
.pipe(
map((message: string) => ({ message })),
);
2022-06-29 10:12:27 +00:00
}
// ====================== 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 })),
);
}
// ====================== GUESTS ===============================
//POST parameter from API
createGuest(name: string, last_name: string, dni: string, number_plate: string, phone: number
, status: string, date_entry: Date) {
const pattern = { cmd: 'createGuest' };
const payload = {
name: name, last_name: last_name, dni: dni, number_plate: number_plate, phone: phone,
status: status, date_entry: date_entry
};
return this.clientGuestApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allGuests() {
const pattern = { cmd: 'findAllGuests' };
const payload = {};
return this.clientGuestApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
//GET parameter from API
findGuest(paramGuestDNI: string) {
const pattern = { cmd: 'findGuestDNI' };
const payload = { dni: paramGuestDNI };
return this.clientGuestApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
// ====================== PAYMENTS ===============================
//POST parameter from API
createPayment(date_payment: Date, mount: number, description: string, period: string
, status: string, user_id: string, communty_id: string) {
const pattern = { cmd: 'createPayment' };
const payload = {
date_payment: date_payment, mount: mount, description: description,
period: period, status: status, user_id: user_id, communty_id: communty_id
};
return this.clientPaymentApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
allPayments() {
const pattern = { cmd: 'findAllPayments' };
const payload = {};
return this.clientPaymentApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
//GET parameter from API
findPayment(paramPaymentId: string) {
const pattern = { cmd: 'findOnePayment' };
const payload = { id: paramPaymentId };
return this.clientPaymentApp
.send<string>(pattern, payload)
.pipe(
map((message: string) => ({ message })),
);
}
2022-06-29 02:30:10 +00:00
}