Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2-5060 Change logic of monthly event calculation #404

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/abstract/lib/GroupBuilder/AvailableGroupBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ const getScheduledEventEntity = (settings: {
const section = getScheduledSection();

const scheduledAt = new Date(scheduledAtDay);
scheduledAt.setHours(section.timeFrom!.hours);
scheduledAt.setMinutes(section.timeFrom!.minutes);

if (section.timeFrom === null) {
throw new Error('[getScheduledEventEntity]: timeFrom is null');
}

scheduledAt.setHours(section.timeFrom.hours);
scheduledAt.setMinutes(section.timeFrom.minutes);

const result: EventEntity = {
entity: getActivity(),
Expand Down
18 changes: 15 additions & 3 deletions src/abstract/lib/GroupBuilder/AvailableGroupEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,22 @@ export class AvailableGroupEvaluator implements IEvaluator<EventEntity> {

const now = this.utility.getNow();

if (event.availability.timeFrom === null) {
throw new Error('[isValidWhenNoSpreadAndNoAccessBeforeStartTime] timeFrom is null');
}

if (event.availability.timeTo === null) {
throw new Error('[isValidWhenNoSpreadAndNoAccessBeforeStartTime] timeTo is null');
}

if (event.scheduledAt === null) {
throw new Error('[isValidWhenNoSpreadAndNoAccessBeforeStartTime] scheduledAt is null');
}

const isCurrentTimeInTimeWindow = isTimeInInterval({
timeToCheck: getHourMinute(now),
intervalFrom: event.availability.timeFrom!,
intervalTo: event.availability.timeTo!,
intervalFrom: event.availability.timeFrom,
intervalTo: event.availability.timeTo,
including: 'from',
});

Expand All @@ -45,7 +57,7 @@ export class AvailableGroupEvaluator implements IEvaluator<EventEntity> {
const isCompletedToday = !!endAt && this.utility.isToday(new Date(endAt));

return (
isScheduledToday && now > event.scheduledAt! && isCurrentTimeInTimeWindow && !isCompletedToday
isScheduledToday && now > event.scheduledAt && isCurrentTimeInTimeWindow && !isCompletedToday
);
}

Expand Down
60 changes: 48 additions & 12 deletions src/abstract/lib/GroupBuilder/GroupUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,17 @@ export class GroupUtility {
}

private getStartedAt(eventActivity: EventEntity): Date {
const record = this.getProgressRecord(eventActivity)!;
const record = this.getProgressRecord(eventActivity);

if (record === null) {
throw new Error('[getStartedAt] Progress record is null');
}

if (record.startAt === null) {
throw new Error('[getStartedAt] Progress record startAt is null');
}

return new Date(record.startAt!);
return new Date(record.startAt);
}

private getAllowedTimeInterval(
Expand All @@ -43,8 +51,16 @@ export class GroupUtility {
): DatesFromTo {
const { event } = eventActivity;

const { hours: hoursFrom, minutes: minutesFrom } = event.availability.timeFrom!;
const { hours: hoursTo, minutes: minutesTo } = event.availability.timeTo!;
if (event.availability.timeFrom === null) {
throw new Error('[getAllowedTimeInterval] timeFrom is null');
}

if (event.availability.timeTo === null) {
throw new Error('[getAllowedTimeInterval] timeTo is null');
}

const { hours: hoursFrom, minutes: minutesFrom } = event.availability.timeFrom;
const { hours: hoursTo, minutes: minutesTo } = event.availability.timeTo;

if (scheduledWhen === 'today') {
const allowedFrom = this.getToday();
Expand Down Expand Up @@ -154,25 +170,41 @@ export class GroupUtility {

let from = this.getToday();

if (timeFrom === null) {
throw new Error('[getVoidInterval] timeFrom is null');
}

if (timeTo === null) {
throw new Error('[getVoidInterval] timeTo is null');
}

if (buildFrom) {
from = this.getToday();
from.setHours(timeTo!.hours);
from.setMinutes(timeTo!.minutes);
from.setHours(timeTo.hours);
from.setMinutes(timeTo.minutes);
}

const to = this.getToday();
to.setHours(timeFrom!.hours);
to.setMinutes(timeFrom!.minutes);
to.setHours(timeFrom.hours);
to.setMinutes(timeFrom.minutes);

return { from, to };
}

public isSpreadToNextDay(event: ScheduleEvent): boolean {
if (event.availability.timeFrom === null) {
throw new Error('[isSpreadToNextDay] timeFrom is null');
}

if (event.availability.timeTo === null) {
throw new Error('[isSpreadToNextDay] timeTo is null');
}

return (
event.availability.availabilityType === AvailabilityLabelType.ScheduledAccess &&
isSourceLess({
timeSource: event.availability.timeTo!,
timeTarget: event.availability.timeFrom!,
timeSource: event.availability.timeTo,
timeTarget: event.availability.timeFrom,
})
);
}
Expand All @@ -188,7 +220,7 @@ export class GroupUtility {
isAccessBeforeStartTime,
);

const completedAt = this.getCompletedAt(eventActivity)!;
const completedAt = this.getCompletedAt(eventActivity);

if (!completedAt) {
return false;
Expand Down Expand Up @@ -272,7 +304,11 @@ export class GroupUtility {

public getTimeToComplete(eventActivity: EventEntity): HourMinute | null {
const { event } = eventActivity;
const timer = event.timers.timer!;
const timer = event.timers.timer;

if (timer === null) {
throw new Error('[getTimeToComplete] Timer is null');
}

const startedTime = this.getStartedAt(eventActivity);

Expand Down
9 changes: 7 additions & 2 deletions src/abstract/lib/GroupBuilder/ScheduledGroupEvaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ const getScheduledEventEntity = (settings: {
const section = getScheduledSection();

const scheduledAt = new Date(scheduledAtDay);
scheduledAt.setHours(section.timeFrom!.hours);
scheduledAt.setMinutes(section.timeFrom!.minutes);

if (section.timeFrom === null) {
throw new Error('[getScheduledEventEntity]: timeFrom is null');
}

scheduledAt.setHours(section.timeFrom.hours);
scheduledAt.setMinutes(section.timeFrom.minutes);

const result: EventEntity = {
entity: getActivity(),
Expand Down
Loading
Loading