Merge pull request #194 from DeimosPr4/US-20-Eliminarcomunidaddevivienda

eliminar comunidad
This commit is contained in:
Eduardo Quiros 2022-08-24 04:15:55 +00:00 committed by GitHub
commit f065a0418b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 162 additions and 72 deletions

View File

@ -373,6 +373,11 @@ export class AppController {
) {
return this.appService.saveTenant(community_id, number_house, tenant_id);
}
@Delete('community/deleteCommunity/:id')
deleteCommunity(@Param('id') paramCommunityId: string) {
return this.appService.deleteCommunity(paramCommunityId);
}
// #==== API Common Areas
@Post('commonArea/createCommonArea')
createCommonArea(

View File

@ -445,6 +445,15 @@ export class AppService {
.pipe(map((message: string) => ({ message })));
}
deleteCommunity(id: string) {
const pattern = { cmd: 'removeCommunity' };
const payload = { _id: id };
return this.clientCommunityApp
.send<string>(pattern, payload)
.pipe(map((message: string) => ({ message })));
}
// ====================== COMMON AREAS ===============================
//POST parameter from API
createCommonArea(

View File

@ -5,7 +5,7 @@ import { CommonAreasService } from './common_areas.service';
@Controller()
export class CommonAreasController {
constructor(private readonly commonAreasService: CommonAreasService) {}
constructor(private readonly commonAreasService: CommonAreasService) { }
@MessagePattern({ cmd: 'createCommonArea' })
create(@Payload() commonArea: CommonAreaDocument) {
@ -40,11 +40,17 @@ export class CommonAreasController {
return this.commonAreasService.findByCommunity(_community_id);
}
//cambiar de estado
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.commonAreasService.changeStatus(pid,pstatus);
}
//cambiar de estado
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.commonAreasService.changeStatus(pid, pstatus);
}
@MessagePattern({ cmd: 'removeIdCommunity' })
removeIdCommunity(@Payload() area: any) {
let community_id = area['community_id'];
return this.commonAreasService.removeIdCommunity(community_id);
}
}

View File

@ -47,4 +47,8 @@ export class CommonAreasService {
});
}
async removeIdCommunity(community_id: string){
await this.commonAreaModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}});
}
}

View File

@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema';
@Controller()
export class CommunitiesController {
constructor(private readonly communitiesService: CommunitiesService) {}
constructor(private readonly communitiesService: CommunitiesService) { }
@MessagePattern({ cmd: 'createCommunity' })
create(@Payload() community: CommunityDocument) {
@ -46,17 +46,17 @@ export class CommunitiesController {
return this.communitiesService.remove(_id);
}
//cambiar de estado
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.communitiesService.changeStatus(pid,pstatus);
}
//cambiar de estado
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];
let pstatus = body['status'];
return this.communitiesService.changeStatus(pid, pstatus);
}
@MessagePattern({ cmd: 'saveTenant' })
saveTenant(@Payload() body: string) {
@MessagePattern({ cmd: 'saveTenant' })
saveTenant(@Payload() body: string) {
let id = body['_id'];
let tenant_id = body['tenant_id'];
@ -66,9 +66,9 @@ export class CommunitiesController {
@MessagePattern({ cmd: 'deleteTenant' })
deleteTenant(@Payload() body: string) {
let id = body['_id'];
let tenant_id = body['tenant_id'];
let number_house = body['number_house'];
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
}
let id = body['_id'];
let tenant_id = body['tenant_id'];
let number_house = body['number_house'];
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
}
}

View File

@ -18,6 +18,26 @@ import { Community, CommunitySchema } from '../schemas/community.schema';
},
},
]),
ClientsModule.register([
{
name: 'SERVICIO_AREAS_COMUNES',
transport: Transport.TCP,
options: {
host: '127.0.0.1',
port: 3003,
},
},
]),
ClientsModule.register([
{
name: 'SERVICIO_RESERVACIONES',
transport: Transport.TCP,
options: {
host: '127.0.0.1',
port: 3006,
},
},
]),
MongooseModule.forFeature([
{ name: Community.name, schema: CommunitySchema },
]),

View File

@ -14,6 +14,8 @@ export class CommunitiesService {
@InjectModel(Community.name)
private readonly communityModel: Model<CommunityDocument>,
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
@Inject('SERVICIO_AREAS_COMUNES') private readonly clientAreaApp: ClientProxy,
@Inject('SERVICIO_RESERVACIONES') private readonly clientReservationApp: ClientProxy,
) { }
async create(community: CommunityDocument): Promise<Community> {
@ -57,6 +59,7 @@ export class CommunitiesService {
}
async remove(id: string) {
await this.removeIdCommunity(id);
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
new: true,
});
@ -80,7 +83,6 @@ export class CommunitiesService {
return finalValue['response'];
}
async saveTenant(id: string, number_house: string, ptenant_id: string) {
let community = await this.findOne(id);
await community.houses.map(house => {
@ -97,13 +99,11 @@ export class CommunitiesService {
}
return house;
})
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true,
});
}
async deleteTenant(id: string, number_house: string, tenant_id: string) {
let community = await this.findOne(id);
@ -114,9 +114,31 @@ export class CommunitiesService {
}
return house;
})
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
new: true,
});
}
async removeIdCommunity(community: string) {
const pattern = { cmd: 'removeIdCommunity' };
const payload = { community_id: community };
await this.clientUserApp
.send<string>(pattern, payload)
.pipe(map((response: string) => ({ response })));
const pattern2 = { cmd: 'removeIdCommunity' };
const payload2 = { community_id: community };
await this.clientAreaApp
.send<string>(pattern2, payload2)
.pipe(map((response: string) => ({ response })));
const pattern3 = { cmd: 'removeIdCommunity' };
const payload3 = { community_id: community };
await this.clientReservationApp
.send<string>(pattern3, payload3)
.pipe(map((response: string) => ({ response })));
}
}

View File

@ -38,4 +38,10 @@ export class ReservationsController {
let _id = id['id'];
return this.reservationsService.remove(_id);
}
@MessagePattern({ cmd: 'removeIdCommunity' })
removeIdCommunity(@Payload() reservation: any) {
let community_id = reservation['community_id'];
return this.reservationsService.removeIdCommunity(community_id);
}
}

View File

@ -45,4 +45,8 @@ export class ReservationsService {
new: true,
});
}
async removeIdCommunity(community_id: string){
await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}});
}
}

View File

@ -29,6 +29,9 @@ export class Reservation {
@Prop()
user_id: string;
@Prop()
community_id: string;
}
export const ReservationSchema = SchemaFactory.createForClass(Reservation);

View File

@ -147,6 +147,13 @@ export class UsersController {
user['number_house']);
}
@MessagePattern({ cmd: 'removeIdCommunity' })
removeIdCommunity(@Payload() user: any) {
let community_id = user['community_id'];
return this.userService.removeIdCommunity(community_id);
}
@MessagePattern({ cmd: 'changeStatus' })
changeStatus(@Payload() body: string) {
let pid = body['id'];

View File

@ -303,5 +303,11 @@ export class UsersService {
map((response: string) => ({ response }))
)
}
async removeIdCommunity(community_id: string){
await this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}});
await this.userModel.updateMany({community_id: community_id, user_type:'3' }, {"$set":{"community_id": '', "status": '-1'}});
return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": '', "status": '-1'}});
}
}

View File

@ -67,13 +67,18 @@ const AdministradoresComunidad = () => {
item.status_text = 'Eliminado';
}
//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
})
if (item.community_id || item.community_id != '') {
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
})
} else {
item.community_name = "Sin Comunidad Asignada";
return item;
}
}));
})
.then(data => {
@ -87,9 +92,6 @@ const AdministradoresComunidad = () => {
}
async function getCommunites() {
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' })
.then((response) => response.json())

View File

@ -315,10 +315,8 @@ const Communities = () => {
setDeleteCommunitiesDialog(true);
};
const infoCommunity = async (community) => {
await tenantsList(community._id);
setCommunity({ ...community });
setCommunityDialog(true);
};
@ -383,40 +381,38 @@ const Communities = () => {
);
}
const deleteCommunity = () => {
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
cache: 'no-cache',
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
let _community = communities.filter(val => val._id !== community._id);
setCommunities(_community);
setDeleteCommunityDialog(false);
setCommunity(emptyCommunity);
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
}
)
.catch(
err => {
console.log('Ocurrió un error con el fetch', err)
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
}
);
*/
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
cache: 'no-cache',
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
})
.then(
function (response) {
if (response.status != 201)
console.log('Ocurrió un error con el servicio: ' + response.status);
else
return response.json();
}
)
.then(
function (response) {
let _community = communitiesList.filter(val => val._id !== community._id);
setCommunitiesList(_community);
setDeleteCommunityDialog(false);
setCommunity(emptyCommunity);
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
}
)
.catch(
err => {
console.log('Ocurrió un error con el fetch', err)
toast.current.show({ severity: 'danger', summary: 'Error', detail: 'Comunidad de Viviendas no se pudo eliminar', life: 3000 });
}
);
let _communities = communitiesList.filter((val) => val._id !== community._id);
_communities = _communities.filter(
(val) => val.status != -1,