Skip to content

Commit

Permalink
fix dumbassery
Browse files Browse the repository at this point in the history
  • Loading branch information
rsiminel committed May 27, 2024
1 parent a84131d commit 8fa9e8e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manager2/src/app/tps/tps.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h3>Extend TP {{ selectedEvent ? selectedEvent.name : '' }}</h3>
</div>
<div class="modal-footer">
<div class="form-group row col-sm-12">
<button type="button" class="p-button p-button-sm p-button-primary" (click)="extend_reservation(new_expire)" data-dismiss="modal">Extend</button>
<button type="button" class="p-button p-button-sm p-button-primary" (click)="extend_reservation()" data-dismiss="modal">Extend</button>
<button type="button" class="p-button p-button-sm p-button-secondary" data-dismiss="modal">Cancel</button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion manager2/src/app/tps/tps.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class TpsComponent implements OnInit {
this.listEvents();
}

extend_reservation(new_expire: Date) {
extend_reservation() {
this.msg = '';
this.errmsg = '';
if (new Date(this.new_expire).getTime() < this.selectedEvent.end) {
Expand Down
17 changes: 6 additions & 11 deletions routes/tp.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ router.put('/tp/:id/reserve/now', async function(req, res) {
res.status(403).send({message: 'Not allowed to reserve now this reservation'});
return;
}

if (reservation.to < new Date().getTime()) {
res.status(403).send({message: 'End date can not be in the past'});
return;
Expand All @@ -324,6 +323,10 @@ router.put('/tp/:id/reserve/extend', async function(req, res) {
res.status(403).send({message: 'Not authorized'});
return;
}
if(! req.body.to) {
res.status(403).send({message: 'No input'});
return;
}
if(! sansrv.sanitizeAll([req.params.id])) {
res.status(403).send({message: 'Invalid parameters'});
return;
Expand Down Expand Up @@ -351,24 +354,16 @@ router.put('/tp/:id/reserve/extend', async function(req, res) {

let reservation_id = ObjectID.createFromHexString(req.params.id);

let filter = {};
if(isadmin) {
filter = {_id: reservation_id};
}
else{
filter = {_id: reservation_id, owner: user.uid};
}
let filter = {_id: reservation_id};
let reservation = await dbsrv.mongo_reservations().findOne(filter);
if(!reservation){
res.status(403).send({message: 'Not allowed to extend this reservation'});
res.status(404).send({message: 'Reservation does not exist'});
return;
}

if (req.body.to < reservation.to) {
res.status(403).send({message: 'Extended end date must be after current end date'});
return;
}

if (req.body.to < new Date().getTime()) {
res.status(403).send({message: 'Extended end date can not be in the past'});
return;
Expand Down

0 comments on commit 8fa9e8e

Please sign in to comment.