forked from coding-blocks/gondor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1114278
commit c1c1d88
Showing
11 changed files
with
104 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import DataLoader from 'dataloader'; | ||
|
||
class BaseLoader { | ||
constructor(keys) { | ||
this.keys = keys; | ||
} | ||
} | ||
|
||
BaseLoader.loader = function () { | ||
return () => { | ||
const Loader = this; | ||
|
||
return new DataLoader(async (keys) => new Loader(keys).load()); | ||
}; | ||
}; | ||
|
||
export default BaseLoader; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import Models from 'Models'; | ||
import BaseLoader from 'Services/BaseModelService/Loader'; | ||
|
||
export default class InviteStatus extends BaseLoader { | ||
async load() { | ||
const invites = await Models.CalendarEventInvite.findAll({ | ||
where: { | ||
[Models.Sequelize.Op.or]: this.keys.map(({ user_id, event_id }) => ({ | ||
user_id, | ||
event_id, | ||
})), | ||
}, | ||
}); | ||
|
||
return this.keys.map( | ||
(key) => | ||
invites.find((invite) => invite.event_id === key.event_id)?.status, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Models from 'Models'; | ||
import BaseLoader from 'Services/BaseModelService/Loader'; | ||
import overlapDateTimeClause from 'Utils/overlapDateTimeClause'; | ||
|
||
export default class Availability extends BaseLoader { | ||
load = async () => { | ||
const invites = await Models.CalendarEventInvite.scope('visible').findAll({ | ||
include: [ | ||
{ | ||
model: Models.CalendarEvent, | ||
as: 'event', | ||
where: { | ||
[Models.Sequelize.Op.or]: this.keys.map( | ||
({ user_id, dateTimeRange, excludeEvents = [] }) => ({ | ||
[Models.Sequelize.Op.and]: [ | ||
{ | ||
$user_id$: user_id, | ||
}, | ||
{ | ||
id: { | ||
[Models.Sequelize.Op.notIn]: excludeEvents, | ||
}, | ||
}, | ||
overlapDateTimeClause(dateTimeRange), | ||
], | ||
}), | ||
), | ||
}, | ||
required: true, | ||
}, | ||
], | ||
}); | ||
|
||
return this.keys.map( | ||
(key) => !invites.find((invite) => this.equateKeyAndInvite(key, invite)), | ||
); | ||
}; | ||
|
||
equateKeyAndInvite({ user_id, excludedEvents = [], dateTimeRange }, invite) { | ||
if (invite.user_id !== user_id || excludedEvents.includes(invite.event.id)) | ||
return false; | ||
|
||
if ( | ||
new Date(invite.event.start_at) > new Date(dateTimeRange.end_at) || | ||
new Date(invite.event.end_at) < new Date(dateTimeRange.start_at) | ||
) | ||
return false; | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters