Skip to content

Commit

Permalink
BRS-613: DUP: Users can book passes for future dates by setting the m…
Browse files Browse the repository at this point in the history
…achine's date to future date. (#95)
  • Loading branch information
marklise authored May 20, 2022
1 parent 30eee8a commit c6e29e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
6 changes: 4 additions & 2 deletions lambda/dynamoUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const PASS_TYPE_EXPIRY_HOURS = {
PM: 0,
DAY: 0
};
const DEFAULT_BOOKING_DAYS_AHEAD = 3;

const dynamodb = new AWS.DynamoDB(options);

Expand Down Expand Up @@ -165,14 +166,15 @@ const getPassesByStatus = async function(status, filterExpression = undefined) {

module.exports = {
ACTIVE_STATUS,
RESERVED_STATUS,
DEFAULT_BOOKING_DAYS_AHEAD,
EXPIRED_STATUS,
PASS_TYPE_AM,
PASS_TYPE_PM,
PASS_TYPE_DAY,
TIMEZONE,
RESERVED_STATUS,
PM_ACTIVATION_HOUR,
PASS_TYPE_EXPIRY_HOURS,
TIMEZONE,
timeZone,
TABLE_NAME,
dynamodb,
Expand Down
21 changes: 14 additions & 7 deletions lambda/writePass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ const AWS = require('aws-sdk');
const axios = require('axios');

const { verifyJWT } = require('../captchaUtil');
const { dynamodb, runQuery, TABLE_NAME } = require('../dynamoUtil');
const { dynamodb, runQuery, TABLE_NAME, DEFAULT_BOOKING_DAYS_AHEAD } = require('../dynamoUtil');
const { sendResponse, checkWarmup } = require('../responseUtil');
const { utcToZonedTime } = require('date-fns-tz');
const { formatISO } = require('date-fns');
const { formatISO, add, compareAsc, startOfDay } = require('date-fns');

// default opening/closing hours in 24h time
const DEFAULT_AM_OPENING_HOUR = 7;
Expand Down Expand Up @@ -104,6 +104,17 @@ exports.handler = async (event, context) => {
facilityObj.KeyConditionExpression = 'pk =:pk AND sk =:sk';
const facilityData = await runQuery(facilityObj);

// Check bookingDaysAhead
const bookingDaysAhead = facilityData[0].bookingDaysAhead === null ? DEFAULT_BOOKING_DAYS_AHEAD : facilityData[0].bookingDaysAhead;
const futureDateMax = add(localDate, { days: bookingDaysAhead });
const datecompared = compareAsc(startOfDay(new Date(date)), startOfDay(new Date(futureDateMax)));
if (datecompared > 0) {
return sendResponse(400, {
msg: 'You cannot book for a date that far ahead.',
title: 'Booking date in the future invalid'
});
}

// There should only be 1 facility.
let openingHour = facilityData[0].bookingOpeningHour || DEFAULT_AM_OPENING_HOUR;
let closingHour = DEFAULT_PM_OPENING_HOUR;
Expand Down Expand Up @@ -161,11 +172,7 @@ exports.handler = async (event, context) => {
'&email=' +
email +
'&park=' +
parkName +
'&date=' +
dateselector +
'&type=' +
type;
parkName;

const encodedCancellationLink = encodeURI(cancellationLink);

Expand Down

0 comments on commit c6e29e1

Please sign in to comment.