Merge branch 'US-20-Eliminarcomunidaddevivienda' into US-32-ListarReservas
This commit is contained in:
commit
328265cb8c
|
@ -343,6 +343,11 @@ export class AppController {
|
||||||
) {
|
) {
|
||||||
return this.appService.saveTenant(community_id, number_house, tenant_id);
|
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
|
// #==== API Common Areas
|
||||||
@Post('commonArea/createCommonArea')
|
@Post('commonArea/createCommonArea')
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
@ -476,6 +481,7 @@ export class AppController {
|
||||||
@Body('date_entry') date_entry: Date,
|
@Body('date_entry') date_entry: Date,
|
||||||
@Body('user_id') user_id: string,
|
@Body('user_id') user_id: string,
|
||||||
@Body('common_area_id') common_area_id: string,
|
@Body('common_area_id') common_area_id: string,
|
||||||
|
@Body('community_id') community_id: string,
|
||||||
) {
|
) {
|
||||||
return this.appService.createReservation(
|
return this.appService.createReservation(
|
||||||
start_time,
|
start_time,
|
||||||
|
@ -484,6 +490,7 @@ export class AppController {
|
||||||
date_entry,
|
date_entry,
|
||||||
user_id,
|
user_id,
|
||||||
common_area_id,
|
common_area_id,
|
||||||
|
community_id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,6 +504,12 @@ export class AppController {
|
||||||
return this.appService.findReservation(paramReservation);
|
return this.appService.findReservation(paramReservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('reservation/findReservations/:id')
|
||||||
|
findReservations(@Param('id') community_id: string) {
|
||||||
|
return this.appService.findReservations(community_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #==== API Post
|
// #==== API Post
|
||||||
|
|
||||||
@Post('post/createPost')
|
@Post('post/createPost')
|
||||||
|
|
|
@ -311,7 +311,7 @@ export class AppService {
|
||||||
|
|
||||||
updateAdminSystem(_id: string, dni: string, name: string,
|
updateAdminSystem(_id: string, dni: string, name: string,
|
||||||
last_name: string, email: string, phone: number
|
last_name: string, email: string, phone: number
|
||||||
) {
|
) {
|
||||||
const pattern = { cmd: 'updateAdminSystem' };
|
const pattern = { cmd: 'updateAdminSystem' };
|
||||||
const payload = {
|
const payload = {
|
||||||
_id: _id, dni: dni, name: name, last_name: last_name,
|
_id: _id, dni: dni, name: name, last_name: last_name,
|
||||||
|
@ -429,6 +429,15 @@ export class AppService {
|
||||||
.pipe(map((message: string) => ({ message })));
|
.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 ===============================
|
// ====================== COMMON AREAS ===============================
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
createCommonArea(
|
createCommonArea(
|
||||||
|
@ -589,11 +598,12 @@ export class AppService {
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
createReservation(start_time: string, finish_time: string, status: string,
|
createReservation(start_time: string, finish_time: string, status: string,
|
||||||
date_entry: Date, user_id: string, common_area_id: string) {
|
date_entry: Date, user_id: string, common_area_id: string, community_id: string) {
|
||||||
const pattern = { cmd: 'createReservation' };
|
const pattern = { cmd: 'createReservation' };
|
||||||
const payload = {
|
const payload = {
|
||||||
start_time: start_time, finish_time: finish_time, status: status,
|
start_time: start_time, finish_time: finish_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,
|
||||||
|
community_id: community_id
|
||||||
};
|
};
|
||||||
return this.clientReservationApp
|
return this.clientReservationApp
|
||||||
.send<string>(pattern, payload)
|
.send<string>(pattern, payload)
|
||||||
|
@ -617,6 +627,14 @@ export class AppService {
|
||||||
.pipe(map((message: string) => ({ message })));
|
.pipe(map((message: string) => ({ message })));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findReservations(community_id: string) {
|
||||||
|
const pattern = { cmd: 'findReservationsByCommunity' };
|
||||||
|
const payload = { community_id: community_id };
|
||||||
|
return this.clientReservationApp
|
||||||
|
.send<string>(pattern, payload)
|
||||||
|
.pipe(map((message: string) => ({ message })));
|
||||||
|
}
|
||||||
|
|
||||||
// ====================== POSTS ===============================
|
// ====================== POSTS ===============================
|
||||||
|
|
||||||
//POST parameter from API
|
//POST parameter from API
|
||||||
|
|
|
@ -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'}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { Community, CommunityDocument } from 'src/schemas/community.schema';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
export class CommunitiesController {
|
export class CommunitiesController {
|
||||||
constructor(private readonly communitiesService: CommunitiesService) {}
|
constructor(private readonly communitiesService: CommunitiesService) { }
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'createCommunity' })
|
@MessagePattern({ cmd: 'createCommunity' })
|
||||||
create(@Payload() community: CommunityDocument) {
|
create(@Payload() community: CommunityDocument) {
|
||||||
|
@ -46,17 +46,17 @@ export class CommunitiesController {
|
||||||
return this.communitiesService.remove(_id);
|
return this.communitiesService.remove(_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.communitiesService.changeStatus(pid,pstatus);
|
return this.communitiesService.changeStatus(pid, pstatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'saveTenant' })
|
@MessagePattern({ cmd: 'saveTenant' })
|
||||||
saveTenant(@Payload() body: string) {
|
saveTenant(@Payload() body: string) {
|
||||||
|
|
||||||
let id = body['_id'];
|
let id = body['_id'];
|
||||||
let tenant_id = body['tenant_id'];
|
let tenant_id = body['tenant_id'];
|
||||||
|
@ -66,9 +66,9 @@ export class CommunitiesController {
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'deleteTenant' })
|
@MessagePattern({ cmd: 'deleteTenant' })
|
||||||
deleteTenant(@Payload() body: string) {
|
deleteTenant(@Payload() body: string) {
|
||||||
let id = body['_id'];
|
let id = body['_id'];
|
||||||
let tenant_id = body['tenant_id'];
|
let tenant_id = body['tenant_id'];
|
||||||
let number_house = body['number_house'];
|
let number_house = body['number_house'];
|
||||||
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
return this.communitiesService.deleteTenant(id, number_house, tenant_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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> {
|
||||||
|
@ -57,6 +59,7 @@ export class CommunitiesService {
|
||||||
}
|
}
|
||||||
|
|
||||||
async remove(id: string) {
|
async remove(id: string) {
|
||||||
|
await this.removeIdCommunity(id);
|
||||||
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
return this.communityModel.findOneAndUpdate({ _id: id }, { status: '-1' }, {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
|
@ -80,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 => {
|
||||||
|
@ -97,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);
|
||||||
|
|
||||||
|
@ -114,9 +114,31 @@ 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 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 })));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,12 @@ export class ReservationsController {
|
||||||
return this.reservationsService.findOne(_id);
|
return this.reservationsService.findOne(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MessagePattern({ cmd: 'findReservationsByCommunity' })
|
||||||
|
findReservationsByCommunity(@Payload() body: string) {
|
||||||
|
let community_id = body['community_id'];
|
||||||
|
return this.reservationsService.findReservationsByCommunity(community_id);
|
||||||
|
}
|
||||||
|
|
||||||
@MessagePattern({ cmd: 'updateReservation' })
|
@MessagePattern({ cmd: 'updateReservation' })
|
||||||
update(@Payload() reservation: ReservationDocument) {
|
update(@Payload() reservation: ReservationDocument) {
|
||||||
return this.reservationsService.update(reservation.id, reservation);
|
return this.reservationsService.update(reservation.id, reservation);
|
||||||
|
@ -38,4 +44,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,13 @@ export class ReservationsService {
|
||||||
new: true,
|
new: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeIdCommunity(community_id: string){
|
||||||
|
await this.reservationModel.updateMany({community_id: community_id}, {"$set":{"status": '-1'}});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async findReservationsByCommunity(community_id: string){
|
||||||
|
return this.reservationModel.find({ community_id: community_id }).exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -147,6 +147,13 @@ export class UsersController {
|
||||||
user['number_house']);
|
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' })
|
@MessagePattern({ cmd: 'changeStatus' })
|
||||||
changeStatus(@Payload() body: string) {
|
changeStatus(@Payload() body: string) {
|
||||||
let pid = body['id'];
|
let pid = body['id'];
|
||||||
|
|
|
@ -295,5 +295,11 @@ export class UsersService {
|
||||||
map((response: string) => ({ response }))
|
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'}});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,6 +56,7 @@ import AreasComunes from './components/AreasComunes';
|
||||||
import { useCookies } from "react-cookie";
|
import { useCookies } from "react-cookie";
|
||||||
import LogInUser from './components/LogInUser';
|
import LogInUser from './components/LogInUser';
|
||||||
import Page404 from './components/Page404'
|
import Page404 from './components/Page404'
|
||||||
|
import Reservaciones from './components/Reservaciones';
|
||||||
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
@ -202,6 +203,7 @@ const App = () => {
|
||||||
to: '/areasComunes',
|
to: '/areasComunes',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
{ label: 'Reservaciones', icon: PrimeIcons.CALENDAR, to: '/reservaciones'},
|
||||||
{ label: 'Comunicados', icon: PrimeIcons.COMMENTS, to: '/registroComunicado'},
|
{ label: 'Comunicados', icon: PrimeIcons.COMMENTS, to: '/registroComunicado'},
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -467,6 +469,7 @@ const App = () => {
|
||||||
<Route path="/guardasSeguridad" component={GuardasSeguridad} />
|
<Route path="/guardasSeguridad" component={GuardasSeguridad} />
|
||||||
<Route path="/inquilinos" component={Inquilinos} />
|
<Route path="/inquilinos" component={Inquilinos} />
|
||||||
<Route path="/areasComunes" component={AreasComunes} />
|
<Route path="/areasComunes" component={AreasComunes} />
|
||||||
|
<Route path="/reservaciones" component={Reservaciones} />
|
||||||
<Route path="/registroComunicado" component={RegistroComunicado} />
|
<Route path="/registroComunicado" component={RegistroComunicado} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
@ -67,13 +67,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 => {
|
||||||
|
@ -87,9 +92,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())
|
||||||
|
|
|
@ -107,6 +107,7 @@ const AdministradoresSistema = () => {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (_admin._id) {
|
if (_admin._id) {
|
||||||
|
|
||||||
fetch('http://localhost:4000/user/updateAdminSystem/', {
|
fetch('http://localhost:4000/user/updateAdminSystem/', {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
@ -315,10 +315,8 @@ const Communities = () => {
|
||||||
setDeleteCommunitiesDialog(true);
|
setDeleteCommunitiesDialog(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const infoCommunity = async (community) => {
|
const infoCommunity = async (community) => {
|
||||||
await tenantsList(community._id);
|
await tenantsList(community._id);
|
||||||
|
|
||||||
setCommunity({ ...community });
|
setCommunity({ ...community });
|
||||||
setCommunityDialog(true);
|
setCommunityDialog(true);
|
||||||
};
|
};
|
||||||
|
@ -383,40 +381,38 @@ const Communities = () => {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const deleteCommunity = () => {
|
const deleteCommunity = () => {
|
||||||
/* fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
fetch('http://localhost:4000/community/deleteCommunity/' + community._id, {
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function (response) {
|
function (response) {
|
||||||
if (response.status != 201)
|
if (response.status != 201)
|
||||||
console.log('Ocurrió un error con el servicio: ' + response.status);
|
console.log('Ocurrió un error con el servicio: ' + response.status);
|
||||||
else
|
else
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.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 });
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.catch(
|
.catch(
|
||||||
err => {
|
err => {
|
||||||
console.log('Ocurrió un error con el fetch', 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 });
|
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);
|
let _communities = communitiesList.filter((val) => val._id !== community._id);
|
||||||
_communities = _communities.filter(
|
_communities = _communities.filter(
|
||||||
(val) => val.status != -1,
|
(val) => val.status != -1,
|
||||||
|
|
|
@ -0,0 +1,353 @@
|
||||||
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
|
import { InputText } from 'primereact/inputtext';
|
||||||
|
import { Button } from 'primereact/button';
|
||||||
|
import { DataTable } from 'primereact/datatable';
|
||||||
|
import { Column } from 'primereact/column';
|
||||||
|
import { Dropdown } from 'primereact/dropdown';
|
||||||
|
import { Toast } from 'primereact/toast';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { Dialog } from 'primereact/dialog';
|
||||||
|
import { Toolbar } from 'primereact/toolbar';
|
||||||
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
|
import { faHome, faUserAlt } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { faCircleQuestion } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { faClockFour } from '@fortawesome/free-solid-svg-icons';
|
||||||
|
import { useCookies } from 'react-cookie';
|
||||||
|
|
||||||
|
const Reservations = () => {
|
||||||
|
let emptyReservation = {
|
||||||
|
_id: null,
|
||||||
|
start_time: '',
|
||||||
|
finish_time: '',
|
||||||
|
user_id: '',
|
||||||
|
user_name: '',
|
||||||
|
common_area_id: '',
|
||||||
|
common_area_name: '',
|
||||||
|
community_id: '',
|
||||||
|
status: '1',
|
||||||
|
status_text: '',
|
||||||
|
date_entry: new Date(),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const [reservations, setReservations] = useState([]);
|
||||||
|
const [reservation, setReservation] = useState(emptyReservation);
|
||||||
|
const [submitted, setSubmitted] = useState(false);
|
||||||
|
const [selectedReservations, setSelectedReservations] = useState(null);
|
||||||
|
const [globalFilter, setGlobalFilter] = useState(null);
|
||||||
|
const [deleteReservationDialog, setDeleteReservationDialog] = useState(false);
|
||||||
|
const [deleteReservationsDialog, setDeleteReservationsDialog] = useState(false);
|
||||||
|
const toast = useRef(null);
|
||||||
|
const dt = useRef(null);
|
||||||
|
const [cookies, setCookies] = useCookies()
|
||||||
|
const [areas, setAreas] = useState([]);
|
||||||
|
const [tenants, setTenants] = useState([]);
|
||||||
|
|
||||||
|
async function tenantsList(id) {
|
||||||
|
await fetch(`http://localhost:4000/user/findTenants/${id}`,
|
||||||
|
{ method: 'GET' })
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(data => data.message)
|
||||||
|
.then(data => {
|
||||||
|
data = data.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
)
|
||||||
|
data = data.map(item => {
|
||||||
|
item.password = '';
|
||||||
|
return item;
|
||||||
|
})
|
||||||
|
setTenants(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function areasList(id) {
|
||||||
|
await fetch(`http://localhost:4000/commonArea/findByCommunity/${id}`,
|
||||||
|
{ method: 'GET' })
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(data => data.message)
|
||||||
|
.then(data => {
|
||||||
|
data = data.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
)
|
||||||
|
setAreas(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function reservationList(id) {
|
||||||
|
await fetch(`http://localhost:4000/reservation/findReservations/${id}`,
|
||||||
|
{ method: 'GET' })
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then(data => data.message)
|
||||||
|
.then(data => {
|
||||||
|
data = data.filter(
|
||||||
|
(val) => val.status != -1,
|
||||||
|
)
|
||||||
|
data.map((item) => {
|
||||||
|
if (item.status == '1') {
|
||||||
|
item.status_text = 'Activo';
|
||||||
|
} else if (item.status == '0') {
|
||||||
|
item.status_text = 'Inactivo';
|
||||||
|
}
|
||||||
|
tenants.find((item2) => item2._id == item.user_id);
|
||||||
|
})
|
||||||
|
|
||||||
|
setReservations(data)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
tenantsList(cookies.community_id);
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
areasList(cookies.community_id);
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
tenants.map((item) => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reservationList(cookies.community_id);
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const actionsReservation = (rowData) => {
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="actions">
|
||||||
|
<Button
|
||||||
|
icon="pi pi-trash"
|
||||||
|
className="p-button-rounded p-button-danger mt-2 mx-2"
|
||||||
|
onClick={() => confirmDeleteReservation(rowData)}
|
||||||
|
title="Eliminar Reserva"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const confirmDeleteReservation = (reservation) => {
|
||||||
|
setReservation(reservation);
|
||||||
|
setDeleteReservationDialog(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const confirmDeleteSelected = () => {
|
||||||
|
setDeleteReservationsDialog(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const leftToolbarTemplate = () => {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<div className="my-2">
|
||||||
|
<Button
|
||||||
|
label="Eliminar"
|
||||||
|
icon="pi pi-trash"
|
||||||
|
className="p-button-danger"
|
||||||
|
onClick={confirmDeleteSelected}
|
||||||
|
disabled={!selectedReservations || !selectedReservations.length}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rightToolbarTemplate = () => {
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<Button
|
||||||
|
label="Exportar"
|
||||||
|
icon="pi pi-upload"
|
||||||
|
className="p-button-help"
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const header = (
|
||||||
|
<div className="flex flex-column md:flex-row md:justify-content-between md:align-items-center">
|
||||||
|
<h5 className="m-0">
|
||||||
|
Reservaciones <i className="fal fa-user"></i>
|
||||||
|
</h5>
|
||||||
|
<span className="block mt-2 md:mt-0 p-input-icon-left">
|
||||||
|
<i className="pi pi-search" />
|
||||||
|
<InputText
|
||||||
|
type="search"
|
||||||
|
onInput={(e) => setGlobalFilter(e.target.value)}
|
||||||
|
placeholder="Buscar..."
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
const headerStartTime = (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
{' '}
|
||||||
|
<FontAwesomeIcon icon={faClockFour} style={{ color: '#C08135' }} />
|
||||||
|
Hora de Apertura
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const headerEndTime = (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
{' '}
|
||||||
|
<FontAwesomeIcon icon={faClockFour} style={{ color: '#D7A86E' }} />{' '}
|
||||||
|
Hora de Cierre
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const headerUser = (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
{' '}
|
||||||
|
<FontAwesomeIcon icon={faUserAlt} style={{ color: '#C08135' }} />{' '}
|
||||||
|
Usuario
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
const headerArea = (
|
||||||
|
<>
|
||||||
|
<p>
|
||||||
|
{' '}
|
||||||
|
<FontAwesomeIcon icon={faHome} style={{ color: '#D7A86E' }} />{' '}
|
||||||
|
Código de Area
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
|
||||||
|
const headerStatus = (
|
||||||
|
<>
|
||||||
|
<p> {' '}
|
||||||
|
<FontAwesomeIcon icon={faCircleQuestion} style={{ color: "#C08135" }} />{' '}
|
||||||
|
Estado
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
|
||||||
|
const statusBodyTemplate = (rowData) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<span
|
||||||
|
className={`status status-${rowData.status}`}
|
||||||
|
>
|
||||||
|
{rowData.status_text}
|
||||||
|
</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid">
|
||||||
|
<div className="col-12">
|
||||||
|
<Toast ref={toast} />
|
||||||
|
<div className="card">
|
||||||
|
<Toolbar
|
||||||
|
className="mb-4"
|
||||||
|
left={leftToolbarTemplate}
|
||||||
|
right={rightToolbarTemplate}
|
||||||
|
></Toolbar>
|
||||||
|
<DataTable
|
||||||
|
ref={dt}
|
||||||
|
value={reservations}
|
||||||
|
dataKey="_id"
|
||||||
|
paginator
|
||||||
|
rows={5}
|
||||||
|
selection={selectedReservations}
|
||||||
|
onSelectionChange={(e) => setSelectedReservations(e.value)}
|
||||||
|
scrollable
|
||||||
|
scrollHeight="400px"
|
||||||
|
scrollDirection="both"
|
||||||
|
header={header}
|
||||||
|
rowsPerPageOptions={[5, 10, 25]}
|
||||||
|
className="datatable-responsive mt-3"
|
||||||
|
paginatorTemplate="FirstPageLink PrevPageLink PageLinks NextPageLink LastPageLink CurrentPageReport RowsPerPageDropdown"
|
||||||
|
currentPageReportTemplate="Mostrando {first} a {last} de {totalRecords} reservaciones de la comunidad"
|
||||||
|
globalFilter={globalFilter}
|
||||||
|
emptyMessage="No hay reservas registradas."
|
||||||
|
>
|
||||||
|
<Column
|
||||||
|
selectionMode="multiple"
|
||||||
|
headerStyle={{ width: '3rem' }}
|
||||||
|
></Column>
|
||||||
|
<Column
|
||||||
|
field="start_time"
|
||||||
|
sortable
|
||||||
|
header={headerStartTime}
|
||||||
|
style={{
|
||||||
|
flexGrow: 1,
|
||||||
|
flexBasis: '160px',
|
||||||
|
minWidth: '160px',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
}}
|
||||||
|
></Column>
|
||||||
|
<Column
|
||||||
|
field="finish_time"
|
||||||
|
sortable
|
||||||
|
header={headerEndTime}
|
||||||
|
style={{
|
||||||
|
flexGrow: 1,
|
||||||
|
flexBasis: '160px',
|
||||||
|
minWidth: '160px',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
}}
|
||||||
|
alignFrozen="left"
|
||||||
|
></Column>
|
||||||
|
<Column
|
||||||
|
field="user_id"
|
||||||
|
header={headerUser}
|
||||||
|
style={{
|
||||||
|
flexGrow: 1,
|
||||||
|
flexBasis: '160px',
|
||||||
|
minWidth: '160px',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
}}
|
||||||
|
></Column>
|
||||||
|
<Column
|
||||||
|
field="common_area_id"
|
||||||
|
header={headerArea}
|
||||||
|
style={{
|
||||||
|
flexGrow: 1,
|
||||||
|
flexBasis: '160px',
|
||||||
|
minWidth: '160px',
|
||||||
|
wordBreak: 'break-word',
|
||||||
|
}}
|
||||||
|
></Column>
|
||||||
|
<Column
|
||||||
|
field="status"
|
||||||
|
sortable
|
||||||
|
header={headerStatus}
|
||||||
|
body={statusBodyTemplate}
|
||||||
|
style={{ flexGrow: 1, flexBasis: '160px', minWidth: '160px', wordBreak: 'break-word' }}>
|
||||||
|
</Column>
|
||||||
|
<Column
|
||||||
|
|
||||||
|
style={{ flexGrow: 1, flexBasis: '80px', minWidth: '80px' }}
|
||||||
|
body={actionsReservation}
|
||||||
|
></Column>
|
||||||
|
</DataTable>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default React.memo(Reservations);
|
Loading…
Reference in New Issue