mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
changes
This commit is contained in:
committed by
Sabe Jones
parent
a50c0eb1e7
commit
c18e06f071
@@ -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 {
|
try {
|
||||||
await purchase(user, { params: { type: 'gear', key: 'randomKey' } });
|
await purchase(user, { params: { type: 'gear', key: 'randomKey' } });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -181,7 +181,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<countdown-banner
|
<countdown-banner
|
||||||
v-if="item.event && item.owned == null"
|
v-if="item.end && item.owned == null"
|
||||||
:end-date="endDate"
|
:end-date="endDate"
|
||||||
class="limitedTime available"
|
class="limitedTime available"
|
||||||
/>
|
/>
|
||||||
@@ -741,7 +741,7 @@ export default {
|
|||||||
return (!this.user.purchased.plan.customerId && !this.user.purchased.plan.consecutive.trinkets && this.getPriceClass() === 'hourglasses');
|
return (!this.user.purchased.plan.customerId && !this.user.purchased.plan.consecutive.trinkets && this.getPriceClass() === 'hourglasses');
|
||||||
},
|
},
|
||||||
endDate () {
|
endDate () {
|
||||||
return moment(this.item.event.end);
|
return moment(this.item.end);
|
||||||
},
|
},
|
||||||
totalOwned () {
|
totalOwned () {
|
||||||
return this.user.items[this.item.purchaseType][this.item.key] || 0;
|
return this.user.items[this.item.purchaseType][this.item.key] || 0;
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ export default {
|
|||||||
return this.icons.gems;
|
return this.icons.gems;
|
||||||
},
|
},
|
||||||
endDate () {
|
endDate () {
|
||||||
return moment(this.item.event.end);
|
return moment(this.item.end);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-if="quest.event && !abbreviated"
|
v-if="quest.end && !abbreviated"
|
||||||
class="m-auto"
|
class="m-auto"
|
||||||
>
|
>
|
||||||
{{ limitedString }}
|
{{ limitedString }}
|
||||||
@@ -210,14 +210,14 @@ export default {
|
|||||||
return collect.text;
|
return collect.text;
|
||||||
},
|
},
|
||||||
countdownString () {
|
countdownString () {
|
||||||
if (!this.quest.event || this.purchased) return;
|
if (!this.quest.end || this.purchased) return;
|
||||||
const diffDuration = moment.duration(moment(this.quest.event.end).diff(moment()));
|
const diffDuration = moment.duration(moment(this.quest.end).diff(moment()));
|
||||||
|
|
||||||
if (diffDuration.asSeconds() <= 0) {
|
if (diffDuration.asSeconds() <= 0) {
|
||||||
this.limitedString = this.$t('noLongerAvailable');
|
this.limitedString = this.$t('noLongerAvailable');
|
||||||
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
|
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
|
||||||
this.limitedString = this.$t('limitedAvailabilityDays', {
|
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(),
|
hours: diffDuration.hours(),
|
||||||
minutes: diffDuration.minutes(),
|
minutes: diffDuration.minutes(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
:emptyItem="emptyItem"
|
:emptyItem="emptyItem"
|
||||||
></slot>
|
></slot>
|
||||||
<span
|
<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"
|
class="badge badge-round badge-item badge-clock"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
@@ -114,7 +114,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</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'"
|
:class="item.purchaseType === 'gear' ? 'mt-4' : 'mt-2'"
|
||||||
>
|
>
|
||||||
{{ limitedString }}
|
{{ limitedString }}
|
||||||
@@ -370,14 +370,14 @@ export default {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
countdownString () {
|
countdownString () {
|
||||||
if (!this.item.event) return;
|
if (!this.item.end) return;
|
||||||
const diffDuration = moment.duration(moment(this.item.event.end).diff(moment()));
|
const diffDuration = moment.duration(moment(this.item.end).diff(moment()));
|
||||||
|
|
||||||
if (diffDuration.asSeconds() <= 0) {
|
if (diffDuration.asSeconds() <= 0) {
|
||||||
this.limitedString = this.$t('noLongerAvailable');
|
this.limitedString = this.$t('noLongerAvailable');
|
||||||
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
|
} else if (diffDuration.days() > 0 || diffDuration.months() > 0) {
|
||||||
this.limitedString = this.$t('limitedAvailabilityDays', {
|
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(),
|
hours: diffDuration.hours(),
|
||||||
minutes: diffDuration.minutes(),
|
minutes: diffDuration.minutes(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -800,19 +800,8 @@ export function assembleScheduledMatchers (date) {
|
|||||||
|
|
||||||
let cachedScheduleMatchers = null;
|
let cachedScheduleMatchers = null;
|
||||||
|
|
||||||
export function getScheduleMatchingGroup (type, date) {
|
function makeMatcherClass () {
|
||||||
const checkedDate = date || new Date();
|
return {
|
||||||
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] = {
|
|
||||||
matchers: [],
|
matchers: [],
|
||||||
items: [],
|
items: [],
|
||||||
match (key) {
|
match (key) {
|
||||||
@@ -828,7 +817,25 @@ export function getScheduleMatchingGroup (type, date) {
|
|||||||
}
|
}
|
||||||
return false;
|
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) {
|
if (matcher.matcher instanceof Function) {
|
||||||
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
|
cachedScheduleMatchers[matcher.type].matchers.push(matcher.matcher);
|
||||||
|
|||||||
@@ -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) {
|
if (officialPinnedItems === undefined) {
|
||||||
officialPinnedItems = getOfficialPinnedItems(user); // eslint-disable-line no-param-reassign
|
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));
|
throw new BadRequest(i18n.t('wrongItemType', { type }, language));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (matcher) {
|
||||||
|
itemInfo.end = matcher.getEndDate();
|
||||||
|
console.log(itemInfo);
|
||||||
|
}
|
||||||
|
|
||||||
return itemInfo;
|
return itemInfo;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ shops.getMarketCategories = function getMarket (user, language) {
|
|||||||
premiumHatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
premiumHatchingPotionsCategory.items = sortBy(values(content.hatchingPotions)
|
||||||
.filter(hp => hp.limited
|
.filter(hp => hp.limited
|
||||||
&& matchers.match(hp.key))
|
&& 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) {
|
if (premiumHatchingPotionsCategory.items.length > 0) {
|
||||||
categories.push(premiumHatchingPotionsCategory);
|
categories.push(premiumHatchingPotionsCategory);
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ shops.getQuestShopCategories = function getQuestShopCategories (user, language)
|
|||||||
bundleCategory.items = sortBy(values(content.bundles)
|
bundleCategory.items = sortBy(values(content.bundles)
|
||||||
.filter(bundle => bundle.type === 'quests'
|
.filter(bundle => bundle.type === 'quests'
|
||||||
&& bundleMatchers.match(bundle.key))
|
&& 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) {
|
if (bundleCategory.items.length > 0) {
|
||||||
categories.push(bundleCategory);
|
categories.push(bundleCategory);
|
||||||
@@ -489,13 +489,12 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
|||||||
|
|
||||||
category.items = map(
|
category.items = map(
|
||||||
spells,
|
spells,
|
||||||
spell => getItemInfo(user, 'seasonalSpell', spell, officialPinnedItems, language),
|
spell => getItemInfo(user, 'seasonalSpell', spell, officialPinnedItems, language, spellMatcher),
|
||||||
);
|
);
|
||||||
|
|
||||||
categories.push(category);
|
categories.push(category);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(questMatcher);
|
|
||||||
const quests = pickBy(content.quests, (quest, key) => questMatcher.match(key));
|
const quests = pickBy(content.quests, (quest, key) => questMatcher.match(key));
|
||||||
|
|
||||||
if (keys(quests).length > 0) {
|
if (keys(quests).length > 0) {
|
||||||
@@ -504,7 +503,7 @@ shops.getSeasonalShopCategories = function getSeasonalShopCategories (user, lang
|
|||||||
text: i18n.t('quests', language),
|
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);
|
categories.push(category);
|
||||||
}
|
}
|
||||||
@@ -541,7 +540,7 @@ shops.getBackgroundShopSets = function getBackgroundShopSets (language) {
|
|||||||
text: i18n.t(key, 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);
|
sets.push(set);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ export default async function purchase (user, req = {}, analytics) {
|
|||||||
if (!matchers.match(item.key)) {
|
if (!matchers.match(item.key)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
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');
|
const matchers = getScheduleMatchingGroup('seasonalGear');
|
||||||
if (!matchers.match(item.set)) {
|
if (!matchers.match(item.set)) {
|
||||||
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
throw new NotAuthorized(i18n.t('messageNotAvailable', req.language));
|
||||||
|
|||||||
Reference in New Issue
Block a user