From c18e06f0717b643efe2fdb37c9dff65ad1767bcc Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Wed, 6 Mar 2024 12:02:38 +0100 Subject: [PATCH] changes --- test/common/ops/buy/purchase.js | 2 +- .../client/src/components/shops/buyModal.vue | 4 +- .../components/shops/quests/buyQuestModal.vue | 2 +- .../src/components/shops/quests/questInfo.vue | 8 ++-- .../client/src/components/shops/shopItem.vue | 10 ++--- .../script/content/constants/schedule.js | 41 +++++++++++-------- website/common/script/libs/getItemInfo.js | 7 +++- website/common/script/libs/shops.js | 11 +++-- website/common/script/ops/buy/purchase.js | 2 +- 9 files changed, 49 insertions(+), 38 deletions(-) diff --git a/test/common/ops/buy/purchase.js b/test/common/ops/buy/purchase.js index ef10b7c182..b2f13553f5 100644 --- a/test/common/ops/buy/purchase.js +++ b/test/common/ops/buy/purchase.js @@ -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) { diff --git a/website/client/src/components/shops/buyModal.vue b/website/client/src/components/shops/buyModal.vue index 838989164e..d4e0851039 100644 --- a/website/client/src/components/shops/buyModal.vue +++ b/website/client/src/components/shops/buyModal.vue @@ -181,7 +181,7 @@ @@ -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; diff --git a/website/client/src/components/shops/quests/buyQuestModal.vue b/website/client/src/components/shops/quests/buyQuestModal.vue index 7943e5d291..395303ebc5 100644 --- a/website/client/src/components/shops/quests/buyQuestModal.vue +++ b/website/client/src/components/shops/quests/buyQuestModal.vue @@ -470,7 +470,7 @@ export default { return this.icons.gems; }, endDate () { - return moment(this.item.event.end); + return moment(this.item.end); }, }, watch: { diff --git a/website/client/src/components/shops/quests/questInfo.vue b/website/client/src/components/shops/quests/questInfo.vue index ac69169b1e..d606df48b3 100644 --- a/website/client/src/components/shops/quests/questInfo.vue +++ b/website/client/src/components/shops/quests/questInfo.vue @@ -38,7 +38,7 @@
{{ 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(), }); diff --git a/website/client/src/components/shops/shopItem.vue b/website/client/src/components/shops/shopItem.vue index f6aeaeb9fb..4a831b57d4 100644 --- a/website/client/src/components/shops/shopItem.vue +++ b/website/client/src/components/shops/shopItem.vue @@ -18,7 +18,7 @@ :emptyItem="emptyItem" >
{{ 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(), }); diff --git a/website/common/script/content/constants/schedule.js b/website/common/script/content/constants/schedule.js index b094e32987..c0259fb80b 100644 --- a/website/common/script/content/constants/schedule.js +++ b/website/common/script/content/constants/schedule.js @@ -800,6 +800,29 @@ export function assembleScheduledMatchers (date) { let cachedScheduleMatchers = null; +function makeMatcherClass () { + return { + matchers: [], + items: [], + match (key) { + if (this.matchers.length === 0) { + if (this.items.length > 0) { + return inListMatcher(this.items)(key); + } + } else { + if (this.items.length > 0 && !inListMatcher(this.items)(key)) { + return false; + } + return this.matchers.every(m => m(key)); + } + return false; + }, + getEndDate () { + return new Date(); + }, + }; +} + export function getScheduleMatchingGroup (type, date) { const checkedDate = date || new Date(); if (cacheDate !== null && (getDay(checkedDate) !== getDay(cacheDate) @@ -812,23 +835,7 @@ export function getScheduleMatchingGroup (type, date) { const scheduleMatchers = {}; assembleScheduledMatchers(checkedDate).forEach(matcher => { if (!scheduleMatchers[matcher.type]) { - scheduleMatchers[matcher.type] = { - matchers: [], - items: [], - match (key) { - if (this.matchers.length === 0) { - if (this.items.length > 0) { - return inListMatcher(this.items)(key); - } - } else { - if (this.items.length > 0 && !inListMatcher(this.items)(key)) { - return false; - } - return this.matchers.every(m => m(key)); - } - return false; - }, - }; + scheduleMatchers[matcher.type] = makeMatcherClass(); } if (matcher.matcher instanceof Function) { cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher); diff --git a/website/common/script/libs/getItemInfo.js b/website/common/script/libs/getItemInfo.js index ff9477b30c..120fc277b5 100644 --- a/website/common/script/libs/getItemInfo.js +++ b/website/common/script/libs/getItemInfo.js @@ -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; } diff --git a/website/common/script/libs/shops.js b/website/common/script/libs/shops.js index 9326ba5c73..1ef7968892 100644 --- a/website/common/script/libs/shops.js +++ b/website/common/script/libs/shops.js @@ -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); } diff --git a/website/common/script/ops/buy/purchase.js b/website/common/script/ops/buy/purchase.js index 8e83574850..1938939fe9 100644 --- a/website/common/script/ops/buy/purchase.js +++ b/website/common/script/ops/buy/purchase.js @@ -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));