diff --git a/api-gateway/src/app.controller.ts b/api-gateway/src/app.controller.ts index 5066563a..56c1252c 100644 --- a/api-gateway/src/app.controller.ts +++ b/api-gateway/src/app.controller.ts @@ -468,7 +468,7 @@ export class AppController { } - + // #==== API Reservation @@ -516,7 +516,7 @@ export class AppController { return this.appService.deleteReservation(id); } - + // #==== API Post @Post('post/createPost') @@ -529,6 +529,16 @@ export class AppController { return this.appService.createPost(post, date_entry, user_id, community_id); } + @Put('post/updatePost/:id') + updatePost( + @Param('id') id: string, + @Body('post') post: string, + @Body('user_id') user_id: string, + @Body('community_id') community_id: string, + ) { + return this.appService.updatePost(id, post, user_id, community_id); + } + @Get('post/allPosts') allPosts() { return this.appService.allPosts(); diff --git a/api-gateway/src/app.service.ts b/api-gateway/src/app.service.ts index 970b061e..7677f6ba 100644 --- a/api-gateway/src/app.service.ts +++ b/api-gateway/src/app.service.ts @@ -540,7 +540,7 @@ 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,tenant_id:tenant_id, community_id:community_id,date_entry: date_entry + status: status, tenant_id: tenant_id, community_id: community_id, date_entry: date_entry }; return this.clientGuestApp .send(pattern, payload) @@ -571,17 +571,17 @@ export class AppService { .send(pattern, payload) .pipe(map((message: string) => ({ message }))); } - + // ====================== RESERVATIONS =============================== //POST parameter from API createReservation(date: string, time: string, status: string, - date_entry: Date, user_id: string, common_area_id: string, + date_entry: Date, user_id: string, common_area_id: string, common_area_name: string, community_id: string) { const pattern = { cmd: 'createReservation' }; const payload = { date: date, time: time, status: status, - date_entry: date_entry, user_id: user_id, common_area_id: common_area_id, + date_entry: date_entry, user_id: user_id, common_area_id: common_area_id, common_area_name: common_area_name, community_id: community_id }; return this.clientReservationApp @@ -638,6 +638,16 @@ export class AppService { .pipe(map((message: string) => ({ message }))); } + updatePost(id: string, post: string, user_id: string, community_id: string) { + const pattern = { cmd: 'updatePost' }; + const payload = { + post: post, id: id, user_id: user_id, community_id: community_id + }; + return this.clientPostApp + .send(pattern, payload) + .pipe(map((message: string) => ({ message }))); + } + allPosts() { const pattern = { cmd: 'findAllPosts' }; const payload = {}; diff --git a/web-ui/web-react/src/components/RegistroComunicado.js b/web-ui/web-react/src/components/RegistroComunicado.js index fbe91808..945bbc2c 100644 --- a/web-ui/web-react/src/components/RegistroComunicado.js +++ b/web-ui/web-react/src/components/RegistroComunicado.js @@ -16,7 +16,7 @@ import classNames from 'classnames'; const RegistroComunicado = () => { - let emptyComunicado = { + const emptyComunicado = { _id: null, post: '', user_id: '', @@ -29,6 +29,7 @@ const RegistroComunicado = () => { const [comunicado, setComunicado] = useState(emptyComunicado); const [comunicados, setComunicados] = useState([]); + const [saveButtonLabel, setSaveButtonLabel] = useState('Registrar'); const [comunicadoId, setComunicadoId] = useState(null); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const [submitted, setSubmitted] = useState(false); @@ -48,31 +49,60 @@ const RegistroComunicado = () => { } const saveComunicado = () => { - var data = { - post: document.getElementById('txt_comunicado').value, - user_id: cookies.id, - community_id: cookies.community_id - }; + if (comunicado._id === null) { + var data = { + post: comunicado.post, + user_id: cookies.id, + community_id: cookies.community_id + }; - fetch('http://localhost:4000/post/createPost', { - cache: 'no-cache', - method: 'POST', - body: JSON.stringify(data), - headers: { - 'Content-Type': 'application/json' - } - }).then((response) => { - if (response.status != 201) - console.log('Ocurrió un error con el servicio: ' + response.status); - else - return response.json(); - }).then((_response) => { + fetch('http://localhost:4000/post/createPost', { + cache: 'no-cache', + method: 'POST', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }).then((response) => { + if (response.status != 201) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + }).then((_response) => { + setComunicado(emptyComunicado); + listaComunis(); + }).catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } else { + const data = { + _id: comunicado._id, + post: comunicado.post, + user_id: comunicado.user_id, + community_id: comunicado.community_id + }; - }).catch( - err => console.log('Ocurrió un error con el fetch', err) - ); + fetch(`http://localhost:4000/post/updatePost/${comunicado._id}`, { + cache: 'no-cache', + method: 'PUT', + body: JSON.stringify(data), + headers: { + 'Content-Type': 'application/json' + } + }).then((response) => { + if (response.status != 200) + console.log('Ocurrió un error con el servicio: ' + response.status); + else + return response.json(); + }).then((_response) => { + setComunicado(emptyComunicado); + setSaveButtonLabel('Registrar'); + listaComunis(); + }).catch( + err => console.log('Ocurrió un error con el fetch', err) + ); + } } - const header = (
@@ -111,9 +141,27 @@ const RegistroComunicado = () => { ) } + const edit = (rowData) => { + setComunicado(rowData); + setComunicadoId(rowData._id); + setSaveButtonLabel('Actualizar'); + } + + const cancelEdit = () => { + setComunicado(emptyComunicado); + setSaveButtonLabel('Registrar'); + setComunicadoId(null); + } + const actions = (rowData) => { return (
+
-