finish functionality

This commit is contained in:
Eduardo Quiros 2022-09-01 14:27:11 -06:00
parent eb55195783
commit 1a7edfc76e
No known key found for this signature in database
GPG Key ID: B77F36C3F12720B4
3 changed files with 118 additions and 50 deletions

View File

@ -353,6 +353,33 @@ export class AppController {
);
}
@Put('community/updateCommunity/:id')
updateCommunity(
@Param('id') id: string,
@Body('name') name: string,
@Body('province') province: string,
@Body('canton') canton: string,
@Body('district') district: string,
@Body('num_houses') num_houses: number,
@Body('phone') phone: string,
@Body('status') status: string,
@Body('date_entry') date_entry: Date,
@Body('houses') houses: [],
) {
return this.appService.updateCommunity(
id,
name,
province,
canton,
district,
num_houses,
phone,
status,
date_entry,
houses,
);
}
@Get('community/allCommunities')
allcommunities() {
return this.appService.allCommunities();

View File

@ -426,6 +426,25 @@ export class AppService {
.pipe(map((message: string) => ({ message })));
}
updateCommunity(id: string, name: string, province: string, canton: string, district: string, num_houses: number, phone: string, status: string, date_entry: Date, houses: unknown) {
const pattern = { cmd: 'updateCommunity' };
const payload = {
id: id,
name: name,
province: province,
canton: canton,
district: district,
num_houses: num_houses,
phone: phone,
status: status,
date_entry: date_entry,
houses: houses,
};
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
allCommunities() {
const pattern = { cmd: 'findAllCommunities' };
const payload = {};

View File

@ -203,6 +203,7 @@ const Communities = () => {
districtId &&
community.phone
) {
if (saveButtonLabel === 'Registrar') {
let _communities = [...communitiesList];
let _community = { ...community };
_community.province = provinciaId;
@ -245,17 +246,37 @@ const Communities = () => {
detail: 'Comunidad de vivienda Creada',
life: 3000,
});
setCommunitiesList(_communities);
setProvinciaId('');
setCantonId('');
setDistrictId('');
setCodeHouses('');
getCommunites();
setCommunity(emptyCommunity);
})
.catch((err) => console.log('Ocurrió un error con el fetch', err));
} else {
let _community = { ...community };
_community.province = provinciaId;
_community.canton = cantonId;
_community.district = districtId;
console.log(`Actualizando comunidad: ${_community}`);
fetch(`http://localhost:4000/community/updateCommunity/${community._id}`, {
method: 'PUT',
cache: 'no-cache',
body: JSON.stringify(_community),
headers: {
'Content-Type': 'application/json',
}
}).then((response) => {
getCommunites();
if (response.status != 200)
console.log('Ocurrió un error con el servicio: ' + response.status);
else return response.json();
}).catch((err) => console.log('Ocurrió un error con el fetch', err));
setSaveButtonLabel('Registrar');
setCommunity(emptyCommunity);
}
} else {
setSubmitted(true);
}
@ -356,6 +377,7 @@ const Communities = () => {
detail: 'Comunidad de Viviendas Actualizada',
life: 3000,
});
getCommunites();
})
.catch((err) => console.log('Ocurrió un error con el fetch', err));
};