This commit is contained in:
Phillip Thelen
2024-03-06 12:02:38 +01:00
committed by Sabe Jones
parent a50c0eb1e7
commit c18e06f071
9 changed files with 49 additions and 38 deletions

View File

@@ -65,7 +65,7 @@ describe('shared.ops.purchase', () => {
}
});
it.only('returns error when unknown item is requested', async () => {
it('returns error when unknown item is requested', async () => {
try {
await purchase(user, { params: { type: 'gear', key: 'randomKey' } });
} catch (err) {

View File

@@ -181,7 +181,7 @@
</div>
</div>
<countdown-banner
v-if="item.event && item.owned == null"
v-if="item.end && item.owned == null"
:end-date="endDate"
class="limitedTime available"
/>
@@ -741,7 +741,7 @@ export default {
return (!this.user.purchased.plan.customerId && !this.user.purchased.plan.consecutive.trinkets && this.getPriceClass() === 'hourglasses');
},
endDate () {
return moment(this.item.event.end);
return moment(this.item.end);
},
totalOwned () {
return this.user.items[this.item.purchaseType][this.item.key] || 0;

View File

@@ -470,7 +470,7 @@ export default {
return this.icons.gems;
},
endDate () {
return moment(this.item.event.end);
return moment(this.item.end);
},
},
watch: {

View File

@@ -38,7 +38,7 @@
</div>
</div>
<div
v-if="quest.event && !abbreviated"
v-if="quest.end && !abbreviated"
class="m-auto"
>
{{ limitedString }}
@@ -210,14 +210,14 @@ export default {
return collect.text;
},
countdownString () {
if (!this.quest.event || this.purchased) return;
const diffDuration = moment.duration(moment(this.quest.event.end).diff(moment()));
if (!this.quest.end || this.purchased) return;
const diffDuration = moment.duration(moment(this.quest.end).diff(moment()));
if (diffDuration.asSeconds() <= 0) {
this.limitedString = this.$t('noLongerAvailable');
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', {
days: moment(this.quest.event.end).diff(moment(), 'days'),
days: moment(this.quest.end).diff(moment(), 'days'),
hours: diffDuration.hours(),
minutes: diffDuration.minutes(),
});

View File

@@ -18,7 +18,7 @@
:emptyItem="emptyItem"
></slot>
<span
v-if="item.event && item.owned == null && showEventBadge"
v-if="item.end && item.owned == null && showEventBadge"
class="badge badge-round badge-item badge-clock"
>
<span
@@ -114,7 +114,7 @@
</div>
</div>
<div
v-if="item.event && item.purchaseType !== 'quests'"
v-if="item.end && item.purchaseType !== 'quests'"
:class="item.purchaseType === 'gear' ? 'mt-4' : 'mt-2'"
>
{{ limitedString }}
@@ -370,14 +370,14 @@ export default {
};
},
countdownString () {
if (!this.item.event) return;
const diffDuration = moment.duration(moment(this.item.event.end).diff(moment()));
if (!this.item.end) return;
const diffDuration = moment.duration(moment(this.item.end).diff(moment()));
if (diffDuration.asSeconds() <= 0) {
this.limitedString = this.$t('noLongerAvailable');
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
this.limitedString = this.$t('limitedAvailabilityDays', {
days: moment(this.item.event.end).diff(moment(), 'days'),
days: moment(this.item.end).diff(moment(), 'days'),
hours: diffDuration.hours(),
minutes: diffDuration.minutes(),
});

View File

@@ -800,19 +800,8 @@ export function assembleScheduledMatchers (date) {
let cachedScheduleMatchers = null;
export function getScheduleMatchingGroup (type, date) {
const checkedDate = date || new Date();
if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate)
|| getMonth(checkedDate) !== getMonth(cacheDate))) {
cacheDate = null;
cachedScheduleMatchers = null;
}
if (!cachedScheduleMatchers) {
cacheDate = new Date();
const scheduleMatchers = {};
assembleScheduledMatchers(checkedDate).forEach(matcher => {
if (!scheduleMatchers[matcher.type]) {
scheduleMatchers[matcher.type] = {
function makeMatcherClass () {
return {
matchers: [],
items: [],
match (key) {
@@ -828,8 +817,26 @@ export function getScheduleMatchingGroup (type, date) {
}
return false;
},
getEndDate () {
return new Date();
},
};
}
export function getScheduleMatchingGroup (type, date) {
const checkedDate = date || new Date();
if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate)
|| getMonth(checkedDate) !== getMonth(cacheDate))) {
cacheDate = null;
cachedScheduleMatchers = null;
}
if (!cachedScheduleMatchers) {
cacheDate = new Date();
const scheduleMatchers = {};
assembleScheduledMatchers(checkedDate).forEach(matcher => {
if (!scheduleMatchers[matcher.type]) {
scheduleMatchers[matcher.type] = makeMatcherClass();
}
if (matcher.matcher instanceof Function) {
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
} else if (matcher.items instanceof Array) {

View File

@@ -56,7 +56,7 @@ function getDefaultGearProps (item, language) {
};
}
export default function getItemInfo (user, type, item, officialPinnedItems, language = 'en') {
export default function getItemInfo (user, type, item, officialPinnedItems, language = 'en', matcher = null) {
if (officialPinnedItems === undefined) {
officialPinnedItems = getOfficialPinnedItems(user); // eslint-disable-line no-param-reassign
}
@@ -478,5 +478,10 @@ export default function getItemInfo (user, type, item, officialPinnedItems, lang
throw new BadRequest(i18n.t('wrongItemType', { type }, language));
}
if (matcher) {
itemInfo.end = matcher.getEndDate();
console.log(itemInfo);
}
return itemInfo;
}

View File

@@ -75,7 +75,7 @@ shops.getMarketCategories = function getMarket (user, language) {
premiumHatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
.filter(hp => hp.limited
&& matchers.match(hp.key))
.map(premiumHatchingPotion => getItemInfo(user, 'premiumHatchingPotion', premiumHatchingPotion, officialPinnedItems, language)), 'key');
.map(premiumHatchingPotion => getItemInfo(user, 'premiumHatchingPotion', premiumHatchingPotion, officialPinnedItems, language, matchers)), 'key');
if (premiumHatchingPotionsCategory.items.length > 0) {
categories.push(premiumHatchingPotionsCategory);
}
@@ -277,7 +277,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
bundleCategory.items = sortBy(values(content.bundles)
.filter(bundle => bundle.type === 'quests'
&& bundleMatchers.match(bundle.key))
.map(bundle => getItemInfo(user, 'bundles', bundle, officialPinnedItems, language)));
.map(bundle => getItemInfo(user, 'bundles', bundle, officialPinnedItems, language, bundleMatchers)));
if (bundleCategory.items.length > 0) {
categories.push(bundleCategory);
@@ -489,13 +489,12 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
category.items = map(
spells,
spell => getItemInfo(user, 'seasonalSpell', spell, officialPinnedItems, language),
spell => getItemInfo(user, 'seasonalSpell', spell, officialPinnedItems, language, spellMatcher),
);
categories.push(category);
}
console.log(questMatcher);
const quests = pickBy(content.quests, (quest, key) => questMatcher.match(key));
if (keys(quests).length > 0) {
@@ -504,7 +503,7 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
text: i18n.t('quests', language),
};
category.items = map(quests, quest => getItemInfo(user, 'seasonalQuest', quest, officialPinnedItems, language));
category.items = map(quests, quest => getItemInfo(user, 'seasonalQuest', quest, officialPinnedItems, language, questMatcher));
categories.push(category);
}
@@ -541,7 +540,7 @@ shops.getBackgroundShopSets = function getBackgroundShopSets (language) {
text: i18n.t(key, language),
};
set.items = map(group, background => getItemInfo(null, 'background', background, officialPinnedItems, language));
set.items = map(group, background => getItemInfo(null, 'background', background, officialPinnedItems, language, matchers));
sets.push(set);
}

View File

@@ -102,7 +102,7 @@ export default async function purchase (user, req = {}, analytics) {
if (!matchers.match(item.key)) {
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
}
} else if (item.event && item.event.gear) {
} else if (item.end && item.event.gear) {
const matchers = getScheduleMatchingGroup('seasonalGear');
if (!matchers.match(item.set)) {
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));