diff --git a/api/graphql/query/Resource/availability.js b/api/graphql/query/Resource/availability.js index 9accf2d..22fd210 100644 --- a/api/graphql/query/Resource/availability.js +++ b/api/graphql/query/Resource/availability.js @@ -11,15 +11,18 @@ class ZoomAccountAvailability extends BaseResolver { const topic = await resource.getTopic(); if (this.parent.subject_type === 'ZoomAccount') { - const key = { - id: this.parent.subject_id, - dateTimeRange: { - start_at: topic.start_at, - end_at: topic.end_at, - }, - excludeTopics: [topic.id], - }; - return (await ZoomAccount.findAllAvailabilityDuring([key]))[0]; + return ( + await ZoomAccount.findAllAvailabilityDuring([ + { + id: this.parent.subject_id, + dateTimeRange: { + start_at: topic.start_at, + end_at: topic.end_at, + }, + excludeTopics: [topic.id], + }, + ]) + )[0]; } //NOTE(naman) For a new resource add finding availability logic here diff --git a/api/services/ZoomAccount/index.js b/api/services/ZoomAccount/index.js index 5463c61..1d4ed66 100644 --- a/api/services/ZoomAccount/index.js +++ b/api/services/ZoomAccount/index.js @@ -1,5 +1,5 @@ -import DataLoader from 'dataloader'; import Models from 'Models'; +import DataLoader from 'dataloader'; import BaseModelService, { saveInstance, requireInstance, @@ -10,16 +10,17 @@ export default class ZoomAccount extends BaseModelService { static findAllInUse(...args) { return Models.ZoomAccount.findAll(utilizedResourceClause(...args)); } - static async findAllAvailabilityDuring(keys) { - const resultPromises = keys.map(async (key) => { - const { id, ...args } = key; - return !(await Models.ZoomAccount.findOne({ - where: { id }, - ...utilizedResourceClause(args), - })); - }); - return Promise.all(resultPromises); + static async findAllAvailabilityDuring(keys) { + return Promise.all( + keys.map( + async ({ id, ...args }) => + !(await Models.ZoomAccount.findOne({ + where: { id }, + ...utilizedResourceClause(args), + })), + ), + ); } static getAvailabilityLoader() { @@ -28,13 +29,15 @@ export default class ZoomAccount extends BaseModelService { @requireInstance async ifAvailableDuring(dateTimeRange, options) { - const key = { - id: this.instance.id, - dateTimeRange, - options, - }; - - return (await ZoomAccount.findAllAvailabilityDuring([key]))[0]; + return ( + await ZoomAccount.findAllAvailabilityDuring([ + { + id: this.instance.id, + dateTimeRange, + ...options, + }, + ]) + )[0]; } @saveInstance