diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 9017c566..51a8507a 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -11,22 +11,12 @@ export class AppController { @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, - ); + return this.appService.createAdminSystem(dni, name, last_name, email, phone, + user_type, status, date_entry); } @Post('user/createGuard') @@ -37,24 +27,30 @@ export class AppController { @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, @Body('community_id') community_id: string, ) { - return this.appService.createGuard( - dni, - name, - last_name, - email, - phone, - password, - user_type, - status, - date_entry, - community_id, - ); + return this.appService.createGuard(dni, name, last_name, email, phone, + user_type, status, date_entry,community_id); + } + + @Post('user/createAdminCommunity') + createAdminCommunity( + //Nombre, Apellidos, Correo electrónico, Cédula, Teléfono, Contraseña + @Body('dni') dni: string, + @Body('name') name: string, + @Body('last_name') last_name: string, + @Body('email') email: string, + @Body('phone') phone: number, + @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.createAdminCommunity(dni, name, last_name, email, phone, + user_type, status, date_entry,community_id); } @Post('user/createUser') @@ -371,4 +367,8 @@ export class AppController { html(@Body('email') email: string, @Body('name') name: string) { return this.appService.html(email, name); } + + + + } diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index c61d0df8..4b71002b 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -54,64 +54,47 @@ export class AppService { } //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, - ) { + createAdminSystem(dni: string, name: string, last_name: string, email: string, phone: number + , 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, + dni: dni, name: name, last_name: last_name, email: email, phone: phone, + password: this.generatePassword(), user_type: user_type, status: status, date_entry: date_entry }; return this.clientUserApp .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - createGuard( - dni: string, - name: string, - last_name: string, - email: string, - phone: number, - password: string, - user_type: string, - status: string, - date_entry: Date, - community_id: string, - ) { + createGuard(dni: string, name: string, last_name: string, email: string, phone: number + , user_type: string, status: string, date_entry: Date, community_id: string) { const pattern = { cmd: 'createGuard' }; 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, + dni: dni, name: name, last_name: last_name, email: email, phone: phone, + password: this.generatePassword(), user_type: user_type, status: status, date_entry: date_entry, community_id + }; return this.clientUserApp .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } + + createAdminCommunity(dni: string, name: string, last_name: string, email: string, phone: number + , user_type: string, status: string, date_entry: Date, community_id: string) { + const pattern = { cmd: 'createAdminCommunity' }; + const payload = { + dni: dni, name: name, last_name: last_name, email: email, phone: phone, + password: this.generatePassword(), user_type: user_type, status: status, date_entry: date_entry, community_id + + }; + return this.clientUserApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + allUsers() { const pattern = { cmd: 'findAllUsers' }; const payload = {}; @@ -153,6 +136,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + deleteAdminSystem(id: string) { const pattern = { cmd: 'deleteAdminSystem' }; const payload = { id: id }; @@ -181,17 +165,8 @@ export class AppService { // ====================== COMMUNITIES =============================== //POST parameter from API - createCommunity( - name: string, - province: string, - canton: string, - district: string, - num_houses: number, - phone: string, - status: string, - date_entry: Date, - houses: [], - ) { + createCommunity(name: string, province: string, canton: string, district: string + , num_houses: number, phone: string, status: string, date_entry: Date, houses: []) { const pattern = { cmd: 'createCommunity' }; const payload = { name: name, @@ -287,13 +262,8 @@ export class AppService { ) { 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, + name: name, last_name: last_name, dni: dni, number_plate: number_plate, phone: phone, + status: status, date_entry: date_entry }; return this.clientGuestApp .send(pattern, payload) @@ -317,7 +287,7 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } - // ====================== PAYMENTS =============================== + // ====================== PAYMENTS =============================== //POST parameter from API createPayment( @@ -331,13 +301,8 @@ export class AppService { ) { 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, + date_payment: date_payment, mount: mount, description: description, + period: period, status: status, user_id: user_id, communty_id: communty_id }; return this.clientPaymentApp .send(pattern, payload) @@ -364,22 +329,12 @@ export class AppService { // ====================== RESERVATIONS =============================== //POST parameter from API - createReservation( - start_time: string, - finish_time: string, - status: string, - date_entry: Date, - user_id: string, - common_area_id: string, - ) { + createReservation(start_time: string, finish_time: string, status: string, + date_entry: Date, user_id: string, common_area_id: string) { const pattern = { cmd: 'createReservation' }; const payload = { - start_time: start_time, - finish_time: finish_time, - status: status, - date_entry: date_entry, - user_id: user_id, - common_area_id: common_area_id, + start_time: start_time, finish_time: finish_time, status: status, + date_entry: date_entry, user_id: user_id, common_area_id: common_area_id }; return this.clientReservationApp .send(pattern, payload) @@ -406,18 +361,12 @@ export class AppService { // ====================== POSTS =============================== //POST parameter from API - createPost( - post: string, - date_entry: Date, - user_id: string, - community_id: string, - ) { + createPost(post: string, date_entry: Date, user_id: string, + community_id: string) { const pattern = { cmd: 'createPost' }; const payload = { - post: post, - date_entry: date_entry, - user_id: user_id, - community_id: community_id, + post: post, date_entry: date_entry, user_id: user_id, + community_id: community_id }; return this.clientPostApp .send(pattern, payload) @@ -444,18 +393,12 @@ export class AppService { // ====================== COMMNENT POSTS =============================== //Comment parameter from API - createComment( - comment: string, - date_entry: Date, - user_id: string, - post_id: string, - ) { + createComment(comment: string, date_entry: Date, user_id: string, + post_id: string) { const pattern = { cmd: 'createComment' }; const payload = { - comment: comment, - date_entry: date_entry, - user_id: user_id, - post_id: post_id, + comment: comment, date_entry: date_entry, user_id: user_id, + post_id: post_id }; return this.clientPostApp .send(pattern, payload) @@ -482,18 +425,12 @@ export class AppService { // ====================== REPORTS =============================== //Report parameter from API - createReport( - action: string, - description: string, - date_entry: Date, - user_id: string, - ) { + createReport(action: string, description: string, date_entry: Date, + user_id: string) { const pattern = { cmd: 'createReport' }; const payload = { - action: action, - description: description, - date_entry: date_entry, - user_id: user_id, + action: action, description: description, date_entry: date_entry, + user_id: user_id }; return this.clientReportApp .send(pattern, payload) @@ -532,4 +469,22 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } + + + + /* Function to generate combination of password */ + generatePassword() { + var pass = ''; + var str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + 'abcdefghijklmnopqrstuvwxyz0123456789@#$'; + + for (let i = 1; i <= 8; i++) { + var char = Math.floor(Math.random() + * str.length + 1); + + pass += str.charAt(char) + } + + return pass; + } } diff --git a/servicio-notificaciones/src/email.controller.ts b/servicio-notificaciones/src/email.controller.ts index 7af1d7ad..66ffbdb5 100644 --- a/servicio-notificaciones/src/email.controller.ts +++ b/servicio-notificaciones/src/email.controller.ts @@ -19,27 +19,62 @@ export class EmailController { return response; } - @MessagePattern({ cmd: 'html' }) - async postHTMLEmail(@Payload() user: any) { - const url = 'http://localhost:3000/'; - const image = 'images/email.ong'; - var response = await this.mailService.sendMail({ - to: user['email'], - from: 'mbonilla.guti@gmail.com', - subject: 'HTML Dynamic Template', - template: 'templateEmail', - context: { - name: user['name'], - url, - }, - attachments: [ - { - filename: 'email.png', - path: __dirname + '/mails/images/email.png', - cid: 'logo', //my mistake was putting "cid:logo@cid" here! - }, - ], - }); - return response; - } + @MessagePattern({ cmd: 'html' }) + async postHTMLEmail(@Payload() user: any) { + const url = "http://localhost:3000/"; + const image = "images/email.ong"; + var response = await this.mailService.sendMail({ + to: user["email"], + from: "mbonilla.guti@gmail.com", + subject: 'HTML Dynamic Template', + template: 'templateEmail', + context: { + name: user["name"], + url + }, + attachments: [ + { + filename: 'email.png', + path: __dirname + '/mails/images/email.png', + cid: 'logo' //my mistake was putting "cid:logo@cid" here! + } + ] + }); + return response; + } + + + @MessagePattern({ cmd: 'emailCreateUserAdminCommunity' }) + async emailCreateUserAdmin(@Payload() user: any) { + const url = "http://localhost:3000/"; + const image = "images/email.png"; + const logo = "images/Logo Katoikia.svg"; + var response = await this.mailService.sendMail({ + to: user["email"], + from: "mbonilla.guti@gmail.com", + subject: 'Usuario registrado', + template: 'emailCreateUserAdminCommunity', + context: { + name: user["name"], + password: user["password"], + date_entry: user["date_entry"], + email: user["email"], + community_name: user['community_name'], + url + }, + attachments: [ + { + filename: 'email.png', + path: __dirname + '/mails/images/email.png', + cid: 'image_email' //my mistake was putting "cid:logo@cid" here! + }, + { + filename: 'Logo Katoikia.svg', + path: __dirname + '/mails/images/Logo Katoikia.svg', + cid: 'logoKatoikia' //my mistake was putting "cid:logo@cid" here! + } + ] + }); + return response; + } } diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs new file mode 100644 index 00000000..e14f72e0 --- /dev/null +++ b/servicio-notificaciones/src/mails/emailCreateUserAdmin.hbs @@ -0,0 +1,442 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + + \ No newline at end of file diff --git a/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs new file mode 100644 index 00000000..54886e4e --- /dev/null +++ b/servicio-notificaciones/src/mails/emailCreateUserAdminCommunity.hbs @@ -0,0 +1,442 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + + \ No newline at end of file diff --git a/servicio-notificaciones/src/mails/images/Logo Katoikia.png b/servicio-notificaciones/src/mails/images/Logo Katoikia.png new file mode 100644 index 00000000..d59e2c9a Binary files /dev/null and b/servicio-notificaciones/src/mails/images/Logo Katoikia.png differ diff --git a/servicio-notificaciones/src/mails/images/Logo Katoikia.svg b/servicio-notificaciones/src/mails/images/Logo Katoikia.svg new file mode 100644 index 00000000..1416dbb0 --- /dev/null +++ b/servicio-notificaciones/src/mails/images/Logo Katoikia.svg @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/servicio-usuarios/src/users/users.controller.ts b/servicio-usuarios/src/users/users.controller.ts index 8fd67095..e26afb95 100644 --- a/servicio-usuarios/src/users/users.controller.ts +++ b/servicio-usuarios/src/users/users.controller.ts @@ -22,6 +22,11 @@ export class UsersController { return this.userService.create(user); } + @MessagePattern({ cmd: 'createAdminCommunity' }) + createAdminCommunity(@Payload() user: UserDocument) { + return this.userService.createAdminCommunity(user); + } + @MessagePattern({ cmd: 'findAllUsers' }) findAll() { return this.userService.findAll(); @@ -91,4 +96,7 @@ export class UsersController { return this.userService.deleteAdminSystem(user['id']); } + + + } diff --git a/servicio-usuarios/src/users/users.module.ts b/servicio-usuarios/src/users/users.module.ts index fd466bb2..3d4c7979 100644 --- a/servicio-usuarios/src/users/users.module.ts +++ b/servicio-usuarios/src/users/users.module.ts @@ -18,7 +18,17 @@ import { ClientsModule, Transport } from '@nestjs/microservices'; }, }, ]), - MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]), + ClientsModule.register([ + { + name: "SERVICIO_COMUNIDADES", + transport: Transport.TCP, + options: { + host: "127.0.0.1", + port: 3002 + } + } + ]), + MongooseModule.forFeature([{ name: User.name, schema: UserSchema }]), ], controllers: [UsersController], providers: [UsersService], diff --git a/servicio-usuarios/src/users/users.service.ts b/servicio-usuarios/src/users/users.service.ts index 07141e7d..45228d53 100644 --- a/servicio-usuarios/src/users/users.service.ts +++ b/servicio-usuarios/src/users/users.service.ts @@ -4,6 +4,7 @@ import { User, UserDocument } from '../schemas/user.schema'; import { InjectModel } from '@nestjs/mongoose'; import { Md5 } from 'md5-typescript'; import { map } from 'rxjs/operators'; +import { lastValueFrom } from 'rxjs'; import { RpcException, ClientProxy } from '@nestjs/microservices'; @@ -11,9 +12,10 @@ import { RpcException, ClientProxy } from '@nestjs/microservices'; export class UsersService { constructor( @InjectModel(User.name) private readonly userModel: Model, - @Inject('SERVICIO_NOTIFICACIONES') - private readonly clientNotificationtApp: ClientProxy, - ) {} + @Inject('SERVICIO_NOTIFICACIONES') private readonly clientNotificationtApp: ClientProxy, + @Inject('SERVICIO_COMUNIDADES') private readonly clientCommunityApp: ClientProxy, + + ) { } private publicKey: string; async create(user: UserDocument): Promise { let passwordEncriptada = Md5.init(user.password); @@ -21,6 +23,38 @@ export class UsersService { return this.userModel.create(user); } + + async createAdminCommunity(user: UserDocument) { + let password = user.password; + let passwordEncriptada = Md5.init(user.password); + user.password = passwordEncriptada; + this.userModel.create(user); + let community = await this.findCommunity(user.community_id); + user.community_id = community['name']; + + const pattern = { cmd: 'emailCreateUserAdminCommunity' }; + const payload = { email: user['email'], password: password, name: user['name'], date_entry: user['date_entry'] }; + return this.clientNotificationtApp + .send(pattern, payload) + .pipe( + map((message: string) => ({ message })), + ); + } + + async findCommunity(community_id: string) { + const pattern = { cmd: 'findOneCommunity' } + const payload = { _id: community_id } + + let callback = await this.clientCommunityApp + .send(pattern, payload) + .pipe( + map((response: string) => ({ response })) + ) + const finalValue = await lastValueFrom(callback); + return finalValue['response']; + + } + async findAll(): Promise { return this.userModel.find().setOptions({ sanitizeFilter: true }).exec(); } @@ -106,4 +140,9 @@ export class UsersService { async deleteAdminSystem(id: string) { return this.userModel.deleteOne({ _id: id }).exec(); } + + + + } + diff --git a/web-ui/web-react/src/components/AdministradoresComunidad.js b/web-ui/web-react/src/components/AdministradoresComunidad.js index c1ec59c4..37c4dae6 100644 --- a/web-ui/web-react/src/components/AdministradoresComunidad.js +++ b/web-ui/web-react/src/components/AdministradoresComunidad.js @@ -13,85 +13,89 @@ import { faAt } from '@fortawesome/free-solid-svg-icons'; import { faIdCardAlt } from '@fortawesome/free-solid-svg-icons'; import { faEllipsis } from '@fortawesome/free-solid-svg-icons'; import { faHomeAlt } from '@fortawesome/free-solid-svg-icons'; +import { Dropdown } from 'primereact/dropdown'; +import classNames from 'classnames'; const AdministradoresComunidad = () => { - const [listaAdmins, setListaAdmins] = useState([]); - const [listaAdminComunidad, setListaAdminComunidad] = useState([]); - const [adminCommunity, setAdminCommunity] = useState(emptyAdminCommunity); - const [selectedAdminsCommunities, setSelectedAdminsCommunities] = - useState(null); - const [globalFilter, setGlobalFilter] = useState(null); - const [deleteAdminCommunityDialog, setDeleteAdminCommunityDialog] = - useState(false); - const [deleteAdminsCommunitiesDialog, setDeleteAdminsCommunitiesDialog] = - useState(false); - const toast = useRef(null); - const dt = useRef(null); - let emptyAdminCommunity = { - _id: null, - dni: '', - name: '', - last_name: '', - email: '', - phone: '', - password: '', - community_id: '', - community_name: '', - user_type: '2', - status: '', - }; + let emptyAdminCommunity = { + _id: null, + dni: '', + name: '', + last_name: '', + email: '', + phone: '', + password: '', + confirmPassword: '', + community_id: '', + community_name: '', + user_type: '2', + date_entry: new Date(), + status: '1' + }; - async function listaAdmin() { - let nombres = await fetch( - 'http://localhost:4000/user/findAdminComunidad/', - { method: 'GET' }, - ) - .then((response) => response.json()) - .then((data) => { - return Promise.all( - data.message.map((item) => { - //item.full_name returns the repositorie name - return fetch( - `http://localhost:4000/community/findCommunityName/${item.community_id}`, - { method: 'GET' }, - ) - .then((response2) => response2.json()) - .then((data) => { - console.log(data.message.name); - item.community_name = data.message.name; - return item; - }); - }), - ); - }) - .then((data) => setListaAdmins(data)); - } + const [listaAdmins, setListaAdmins] = useState([]); + const [listaAdminComunidad, setListaAdminComunidad] = useState([]); + const [adminCommunity, setAdminCommunity] = useState(emptyAdminCommunity); + const [selectedAdminsCommunities, setSelectedAdminsCommunities] = useState(null); + const [globalFilter, setGlobalFilter] = useState(null); + const [deleteAdminCommunityDialog, setDeleteAdminCommunityDialog] = useState(false); + const [deleteAdminsCommunitiesDialog, setDeleteAdminsCommunitiesDialog] = useState(false); + const [communitiesList, setCommunitiesList] = useState([]); + const [communityId, setCommunityId] = useState(null); + const [submitted, setSubmitted] = useState(false); + const toast = useRef(null); + const dt = useRef(null); - async function nombreComunidad(id) { - let nombres = await fetch( - 'http://localhost:4000/community/findCommunityName/' + id, - { method: 'GET' }, - ); - let nombresRes = await nombres.json(); - return await nombresRes.message['name']; - } - async function setNameCommunities() { - Promise.all( - listaAdmins.map(async function (administrador) { - // await listaComunidades(administrador.community_id); - administrador.community_id = await listaAdminComunidad.name; - }), - ); - } + async function listaAdmin() { + let nombres = await fetch('http://localhost:4000/user/findAdminComunidad/', { method: 'GET' }) + .then((response) => response.json()) + .then((data) => { + return Promise.all(data.message.map(item => { + //item.full_name returns the repositorie name + return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' }) + .then((response2) => response2.json()) + .then(data => data.message) + .then(data => { + item.community_name = data['name'] + return item + }) + })); + }) + .then(data => setListaAdmins(data)); - useEffect(() => { - listaAdmin(); - }, []); + } - const deleteAdminCommunity = () => { - /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { + + + + + async function getCommunites() { + let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' }); + let resList = await response.json(); + let list = await resList.message; + console.log(list); + + setCommunitiesList(await list); + } + + useEffect(() => { + listaAdmin(); + }, []) + + useEffect(() => { + getCommunites(); + },[]) + + const cList = communitiesList.map((item) => ({ + label: item.name, + value: item._id, + })) + + + const deleteAdminCommunity = () => { + /* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, { cache: 'no-cache', method: 'DELETE', headers: { @@ -123,541 +127,370 @@ const AdministradoresComunidad = () => { } ); */ - let _administrators = listaAdmins.filter( - (val) => val._id !== adminCommunity._id, - ); - setListaAdmins(_administrators); - setDeleteAdminCommunityDialog(false); - setAdminCommunity(emptyAdminCommunity); - toast.current.show({ - severity: 'success', - summary: 'Administrador de Comunidad Eliminada', - life: 3000, - }); - }; - - const deleteSelectedAdminsCommunity = () => { - let _admins = listaAdmins.filter( - (val) => !selectedAdminsCommunities.includes(val), - ); - /* selectedCommunities.map((item) => { - fetch('http://localhost:4000/user/deleteCommunity/' + item._id, { - cache: 'no-cache', - method: 'DELETE', - headers: { - 'Content-Type': 'application/json' - } - }) - })*/ - setListaAdmins(_admins); - setDeleteAdminsCommunitiesDialog(false); - setSelectedAdminsCommunities(null); - toast.current.show({ - severity: 'success', - summary: 'Éxito', - detail: 'Administradores de Comunidad de Viviendas Eliminado', - life: 3000, - }); - }; - - const hideDeleteAdminCommunityDialog = () => { - setDeleteAdminCommunityDialog(false); - }; - - const hideDeleteAdminsCommunitysDialog = () => { - setDeleteAdminsCommunitiesDialog(false); - }; - - const confirmDeleteAdminCommunity = (adminCommunity) => { - setAdminCommunity(adminCommunity); - setDeleteAdminCommunityDialog(true); - }; - - const confirmDeleteSelected = () => { - setDeleteAdminsCommunitiesDialog(true); - }; - - const actionsAdminCommunity = (rowData) => { - return ( -
-
- ); - }; - - const leftToolbarTemplate = () => { - return ( - -
-
-
- ); - }; - - const rightToolbarTemplate = () => { - return ( - -