simplify schedule matching usage

This commit is contained in:
Phillip Thelen
2024-01-31 22:52:44 +01:00
committed by Sabe Jones
parent 129cb7627c
commit 736ef16430
7 changed files with 72 additions and 38 deletions

View File

@@ -7,7 +7,7 @@ import { removeItemByPath } from './pinnedGearUtils';
import getItemInfo from '../libs/getItemInfo';
import content from '../content/index';
import updateUserBalance from './updateUserBalance';
import { assembleScheduledMatchers } from '../content/constants/schedule';
import { getScheduleMatchingGroup } from '../content/constants/schedule';
const incentiveBackgrounds = ['blue', 'green', 'red', 'purple', 'yellow'];
@@ -225,12 +225,8 @@ export default async function unlock (user, req = {}, analytics) {
const { set, items, paths } = getSet(setType, firstPath, req);
if (isBackground) {
const matchers = assembleScheduledMatchers(new Date())
.filter(matcher => matcher.type === 'backgrounds')
.map(matcher => matcher.matcher);
const isAvailable = matchers.map(matcher => matcher(set.key))
.every(matcher => matcher === true);
if (!isAvailable) {
const matchers = getScheduleMatchingGroup('backgrounds');
if (!matchers.match(set.key)) {
throw new NotAuthorized(i18n.t('notAvailable', req.language));
}
}