mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Add API calls for shop inventories (#7810)
* Add API call for market inventory * changes to shop api calls * optimize shop categories * add API call for quests * add api call for time travelers shop * fic buying items in shops * fix linting errors * shop adjustments for iOS app * add tests to shops * fix syntax issues * Code formatting * correct indentation * add tests for api routes * fix time travelers and seasonal * Increase test coverage for shop routes * refactor: Pull out trinket count in time traveler route * refactor: Clarify instructions for seasonal shop script * lint: Remove extra new line * Adjust shops common test
This commit is contained in:
committed by
Sabe Jones
parent
aa00893f6c
commit
24d25026cf
123
website/server/controllers/api-v3/shops.js
Normal file
123
website/server/controllers/api-v3/shops.js
Normal file
@@ -0,0 +1,123 @@
|
||||
import { authWithHeaders } from '../../middlewares/api-v3/auth';
|
||||
import shops from '../../../../common/script/libs/shops';
|
||||
|
||||
let api = {};
|
||||
|
||||
/**
|
||||
* @apiIgnore
|
||||
* @api {get} /api/v3/shops/market get the available items for the market
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName GetMarketItems
|
||||
* @apiGroup Shops
|
||||
*
|
||||
* @apiSuccess {Object} data List of push devices
|
||||
* @apiSuccess {string} message Success message
|
||||
*/
|
||||
api.getMarketItems = {
|
||||
method: 'GET',
|
||||
url: '/shops/market',
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
let resObject = {
|
||||
identifier: 'market',
|
||||
text: res.t('market'),
|
||||
notes: res.t('welcomeMarketMobile'),
|
||||
imageName: 'npc_alex',
|
||||
categories: shops.getMarketCategories(user, req.language),
|
||||
};
|
||||
|
||||
res.respond(200, resObject);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @apiIgnore
|
||||
* @api {get} /api/v3/shops/quests get the available items for the quests shop
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName GetQuestShopItems
|
||||
* @apiGroup Shops
|
||||
*
|
||||
* @apiSuccess {Object} data List of push devices
|
||||
* @apiSuccess {string} message Success message
|
||||
*/
|
||||
api.getQuestShopItems = {
|
||||
method: 'GET',
|
||||
url: '/shops/quests',
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
let resObject = {
|
||||
identifier: 'questShop',
|
||||
text: res.t('quests'),
|
||||
notes: res.t('ianTextMobile'),
|
||||
imageName: 'npc_ian',
|
||||
categories: shops.getQuestShopCategories(user, req.language),
|
||||
};
|
||||
|
||||
res.respond(200, resObject);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @apiIgnore
|
||||
* @api {get} /api/v3/shops/time-travelers get the available items for the time travelers shop
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName GetTimeTravelersShopItems
|
||||
* @apiGroup Shops
|
||||
*
|
||||
* @apiSuccess {Object} data List of push devices
|
||||
* @apiSuccess {string} message Success message
|
||||
*/
|
||||
api.getTimeTravelerShopItems = {
|
||||
method: 'GET',
|
||||
url: '/shops/time-travelers',
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
let hasTrinkets = user.purchased.plan.consecutive.trinkets > 0;
|
||||
|
||||
let resObject = {
|
||||
identifier: 'timeTravelersShop',
|
||||
text: res.t('timeTravelers'),
|
||||
notes: hasTrinkets ? res.t('timeTravelersPopover') : res.t('timeTravelersPopoverNoSubMobile'),
|
||||
imageName: hasTrinkets ? 'npc_timetravelers_active' : 'npc_timetravelers',
|
||||
categories: shops.getTimeTravelersCategories(user, req.language),
|
||||
};
|
||||
|
||||
res.respond(200, resObject);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @apiIgnore
|
||||
* @api {get} /api/v3/shops/seasonal get the available items for the seasonal shop
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName GetSeasonalShopItems
|
||||
* @apiGroup Shops
|
||||
*
|
||||
* @apiSuccess {Object} data List of push devices
|
||||
* @apiSuccess {string} message Success message
|
||||
*/
|
||||
api.getSeasonalShopItems = {
|
||||
method: 'GET',
|
||||
url: '/shops/seasonal',
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
|
||||
let resObject = {
|
||||
identifier: 'seasonalShop',
|
||||
text: res.t('seasonalShop'),
|
||||
notes: res.t('seasonalShopSummerText'),
|
||||
imageName: 'seasonalshop_open',
|
||||
categories: shops.getSeasonalShopCategories(user, req.language),
|
||||
};
|
||||
|
||||
res.respond(200, resObject);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
Reference in New Issue
Block a user