eliminar usuarios, reservaciones y areas
This commit is contained in:
parent
49cb71e767
commit
9da33006d9
|
@ -5,7 +5,7 @@ import { CommonAreasService } from './common_areas.service';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class CommonAreasController {
|
export class CommonAreasController {
|
||||||
constructor(private readonly commonAreasService: CommonAreasService) {}
|
constructor(private readonly commonAreasService: CommonAreasService) { }
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'createCommonArea' })
|
@MessagePattern({ cmd: 'createCommonArea' })
|
||||||
create(@Payload() commonArea: CommonAreaDocument) {
|
create(@Payload() commonArea: CommonAreaDocument) {
|
||||||
|
@ -40,11 +40,17 @@ export class CommonAreasController {
|
||||||
return this.commonAreasService.findByCommunity(_community_id);
|
return this.commonAreasService.findByCommunity(_community_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//cambiar de estado
|
//cambiar de estado
|
||||||
@MessagePattern({ cmd: 'changeStatus' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
changeStatus(@Payload() body: string) {
|
changeStatus(@Payload() body: string) {
|
||||||
let pid = body['id'];
|
let pid = body['id'];
|
||||||
let pstatus = body['status'];
|
let pstatus = body['status'];
|
||||||
return this.commonAreasService.changeStatus(pid,pstatus);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,4 +47,8 @@ export class CommonAreasService {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async removeIdCommunity(community_id: string){
|
||||||
|
await this.commonAreaModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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([
|
MongooseModule.forFeature([
|
||||||
{ name: Community.name, schema: CommunitySchema },
|
{ name: Community.name, schema: CommunitySchema },
|
||||||
]),
|
]),
|
||||||
|
|
|
@ -14,6 +14,8 @@ export class CommunitiesService {
|
||||||
@InjectModel(Community.name)
|
@InjectModel(Community.name)
|
||||||
private readonly communityModel: Model<CommunityDocument>,
|
private readonly communityModel: Model<CommunityDocument>,
|
||||||
@Inject('SERVICIO_USUARIOS') private readonly clientUserApp: ClientProxy,
|
@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> {
|
async create(community: CommunityDocument): Promise<Community> {
|
||||||
|
@ -81,7 +83,6 @@ export class CommunitiesService {
|
||||||
return finalValue['response'];
|
return finalValue['response'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async saveTenant(id: string, number_house: string, ptenant_id: string) {
|
async saveTenant(id: string, number_house: string, ptenant_id: string) {
|
||||||
let community = await this.findOne(id);
|
let community = await this.findOne(id);
|
||||||
await community.houses.map(house => {
|
await community.houses.map(house => {
|
||||||
|
@ -98,13 +99,11 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
return house;
|
return house;
|
||||||
})
|
})
|
||||||
|
|
||||||
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async deleteTenant(id: string, number_house: string, tenant_id: string) {
|
async deleteTenant(id: string, number_house: string, tenant_id: string) {
|
||||||
let community = await this.findOne(id);
|
let community = await this.findOne(id);
|
||||||
|
|
||||||
|
@ -115,7 +114,6 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
return house;
|
return house;
|
||||||
})
|
})
|
||||||
|
|
||||||
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
return await this.communityModel.findOneAndUpdate({ _id: id }, community, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
@ -123,13 +121,24 @@ export class CommunitiesService {
|
||||||
|
|
||||||
async removeIdCommunity(community: string) {
|
async removeIdCommunity(community: string) {
|
||||||
const pattern = { cmd: 'removeIdCommunity' };
|
const pattern = { cmd: 'removeIdCommunity' };
|
||||||
const payload = { community_id: community};
|
const payload = { community_id: community };
|
||||||
|
|
||||||
let callback = await this.clientUserApp
|
await this.clientUserApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
.pipe(map((response: string) => ({ response })));
|
.pipe(map((response: string) => ({ response })));
|
||||||
|
|
||||||
const finalValue = await lastValueFrom(callback);
|
const pattern2 = { cmd: 'removeIdCommunity' };
|
||||||
return finalValue['response'];
|
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 })));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,4 +38,10 @@ export class ReservationsController {
|
||||||
let _id = id['id'];
|
let _id = id['id'];
|
||||||
return this.reservationsService.remove(_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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,8 @@ export class ReservationsService {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeIdCommunity(community_id: string){
|
||||||
|
await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ export class Reservation {
|
||||||
|
|
||||||
@Prop()
|
@Prop()
|
||||||
user_id: string;
|
user_id: string;
|
||||||
|
|
||||||
|
@Prop()
|
||||||
|
community_id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ReservationSchema = SchemaFactory.createForClass(Reservation);
|
export const ReservationSchema = SchemaFactory.createForClass(Reservation);
|
||||||
|
|
|
@ -297,9 +297,9 @@ export class UsersService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async removeIdCommunity(community_id: string){
|
async removeIdCommunity(community_id: string){
|
||||||
return this.userModel.updateMany({community_id: community_id, user_type:'2' }, {"$set":{"community_id": ''}});
|
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'}});
|
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'}});*/
|
return this.userModel.updateMany({community_id: community_id, user_type:'4' }, {"$set":{"community_id": '', "status": '-1'}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,13 +66,18 @@ const AdministradoresComunidad = () => {
|
||||||
item.status_text = 'Eliminado';
|
item.status_text = 'Eliminado';
|
||||||
}
|
}
|
||||||
//item.full_name returns the repositorie name
|
//item.full_name returns the repositorie name
|
||||||
return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' })
|
if (item.community_id || item.community_id != '') {
|
||||||
.then((response2) => response2.json())
|
return fetch(`http://localhost:4000/community/findCommunityName/${item.community_id}`, { method: 'GET' })
|
||||||
.then(data => data.message)
|
.then((response2) => response2.json())
|
||||||
.then(data => {
|
.then(data => data.message)
|
||||||
item.community_name = data['name']
|
.then(data => {
|
||||||
return item
|
item.community_name = data['name']
|
||||||
})
|
return item
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
item.community_name = "Sin Comunidad Asignada";
|
||||||
|
return item;
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
@ -86,9 +91,6 @@ const AdministradoresComunidad = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function getCommunites() {
|
async function getCommunites() {
|
||||||
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' })
|
let response = await fetch('http://localhost:4000/community/allCommunities', { method: 'GET' })
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
|
@ -158,15 +160,15 @@ const AdministradoresComunidad = () => {
|
||||||
let _admins = listaAdmins.filter(
|
let _admins = listaAdmins.filter(
|
||||||
(val) => !selectedAdminsCommunities.includes(val),
|
(val) => !selectedAdminsCommunities.includes(val),
|
||||||
);
|
);
|
||||||
selectedAdminsCommunities.map((item) => {
|
selectedAdminsCommunities.map((item) => {
|
||||||
fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, {
|
fetch('http://localhost:4000/user/deleteAdminCommunity/' + item._id, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
setListaAdmins(_admins);
|
setListaAdmins(_admins);
|
||||||
setDeleteAdminsCommunitiesDialog(false);
|
setDeleteAdminsCommunitiesDialog(false);
|
||||||
setSelectedAdminsCommunities(null);
|
setSelectedAdminsCommunities(null);
|
||||||
|
|
|
@ -400,8 +400,8 @@ const Communities = () => {
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
|
|
||||||
let _community = communities.filter(val => val._id !== community._id);
|
let _community = communitiesList.filter(val => val._id !== community._id);
|
||||||
setCommunities(_community);
|
setCommunitiesList(_community);
|
||||||
setDeleteCommunityDialog(false);
|
setDeleteCommunityDialog(false);
|
||||||
setCommunity(emptyCommunity);
|
setCommunity(emptyCommunity);
|
||||||
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
toast.current.show({ severity: 'success', summary: 'Exito', detail: 'Comunidad de Viviendas Eliminada', life: 3000 });
|
||||||
|
|
Loading…
Reference in New Issue