Skip to content

Commit

Permalink
Revert the searchAvailability method changes, as UI treats it differe…
Browse files Browse the repository at this point in the history
…ntly than availabilityCalendar

also update the test case for searchAvailability
  • Loading branch information
shintre committed Jul 8, 2024
1 parent 7a452cd commit efc1988
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 64 deletions.
113 changes: 56 additions & 57 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Plugin {
// ONLY add payload key when absolutely necessary
payload: {
productIds,
optionIds,
startDate,
endDate,
dateFormat,
Expand All @@ -167,66 +168,64 @@ class Plugin {
availQuery,
},
}) {
try {
assert(this.jwtKey, 'JWT secret should be set');
assert(
productIds.length === productIds.length,
'mismatched productIds/options length',
);
// assert(
// optionIds.length === units.length,
// 'mismatched options/units length',
// );
assert(productIds.every(Boolean), 'some invalid productId(s)');
// assert(optionIds.every(Boolean), 'some invalid optionId(s)');
console.log("AC: START DATE BEFORE: " + startDate);
let todayDate = moment(new Date(), dateFormat).format('YYYY-MM-DD');
startDate = moment(startDate, dateFormat).format('YYYY-MM-DD');
console.log("AC: TodayDATE: " + todayDate.toString());
console.log("AC: startDate: " + startDate.toString());
if (startDate < todayDate) {
startDate = todayDate.toString();
}
console.log("AC: START DATE AFTER: " + startDate);

const localDateStart = startDate;
const localDateEnd = moment(endDate, dateFormat).format('YYYY-MM-DD');
assert(this.jwtKey, 'JWT secret should be set');
assert(
productIds.length === productIds.length,
'mismatched productIds/options length',
);
assert(
optionIds.length === units.length,
'mismatched options/units length',
);
assert(productIds.every(Boolean), 'some invalid productId(s)');
// assert(optionIds.every(Boolean), 'some invalid optionId(s)');
console.log("START DATE BEFORE: " + startDate);
let todayDate = Date.now();
if (Date(startDate) < todayDate) {
startDate = todayDate.toString();
}
console.log("START DATE AFTER: " + startDate);
const localDateStart = moment(startDate, dateFormat).format('YYYY-MM-DD');
const localDateEnd = moment(endDate, dateFormat).format('YYYY-MM-DD');
const headers = getHeaders({
apiKey: this.apiKey,
});

// console.log("AC: END DATE: " + localDateEnd);
const headers = getHeaders({
apiKey: this.apiKey,
});

const url = `${this.endpoint}/availability/calendar`;
const availability = (
await Promise.map(productIds, async (productId, ix) => {
// console.log("PRODUCT ID: " + productId);
const data = {
productId,
// optionId: optionIds[ix],
localDateStart,
localDateEnd,
// units is required here to get the total pricing for the calendar
//units: units[ix].map(u => ({ id: u.unitId, quantity: u.quantity })),
};
const result = await axios({
method: 'get',
url,
data,
headers,
});
return Promise.map(result.data, avail => translateAvailability({
rootValue: avail,
const url = `${this.endpoint}/availability/calendar`;
let availability = (
await Promise.map(productIds, async (productId, ix) => {
const data = {
productId,
localDateStart,
localDateEnd,
};
return R.path(['data'], await axios({
method: 'get',
url,
data,
headers,
}));
}, { concurrency: CONCURRENCY })
);
availability = await Promise.map(availability,
(avails, ix) => {
return Promise.map(avails,
avail => translateAvailability({
typeDefs: availTypeDefs,
query: availQuery,
}))
}, { concurrency: CONCURRENCY })
);
return { availability };
} catch (err) {
console.log("ERR: " + err);
return false;
}
rootValue: avail,
variableValues: {
productId: productIds[ix],
optionId: optionIds[ix],
// currency,
unitsWithQuantity: units[ix],
jwtKey: this.jwtKey,
},
}),
);
},
);
return { availability };
}

async availabilityCalendar({
Expand Down
17 changes: 10 additions & 7 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('search tests', () => {
token,
typeDefsAndQueries,
payload: {
startDate: moment().add(1, 'months').format(dateFormat),
startDate: moment().add(1, 'days').format(dateFormat),
endDate: moment().add(1, 'months').add(2, 'days').format(dateFormat),
dateFormat,
productIds: [
Expand All @@ -149,20 +149,23 @@ describe('search tests', () => {
token,
typeDefsAndQueries,
payload: {
startDate: moment().add(1, 'months').format(dateFormat),
startDate: moment().add(1, 'days').format(dateFormat),
endDate: moment().add(2, 'months').format(dateFormat),
dateFormat,
productIds: [
'11',
],
productIds: ['11'],
optionIds: ["2"],
units: [[
{"unitId":"ADULT","quantity":1}
]
]
},
});
expect(retVal).toBeTruthy();
const { availability } = retVal;
expect(availability).toHaveLength(1);
expect(availability[0].length).toBeGreaterThan(0);
// availabilityKey = R.path([0, 0, 'key'], availability);
// expect(availabilityKey).toBeTruthy();
availabilityKey = R.path([0, 0, 'key'], availability);
expect(availabilityKey).toBeTruthy();
});
let booking;
const reference = faker.datatype.uuid();
Expand Down
3 changes: 3 additions & 0 deletions resolvers/availability.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const resolvers = {
unitsWithQuantity,
jwtKey,
} = args;

// console.log("jwtKey : " + jwtKey);
// console.log("root : " + JSON.stringify(root));
if (!jwtKey) return null;
if (root.status !== 'AVAILABLE' && root.status !== 'FREESALE') return null;
return jwt.sign(({
Expand Down

0 comments on commit efc1988

Please sign in to comment.