From 501ebe6719f896f91541768f2933ac4aeef221f2 Mon Sep 17 00:00:00 2001 From: Anton Sylka Date: Thu, 12 Dec 2024 10:44:59 +0700 Subject: [PATCH] Refs #33623: Rush upgrades - add support for old resource --- src/api/extensions/budsies/index.js | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/api/extensions/budsies/index.js b/src/api/extensions/budsies/index.js index c435a0fe..92257424 100644 --- a/src/api/extensions/budsies/index.js +++ b/src/api/extensions/budsies/index.js @@ -355,6 +355,39 @@ module.exports = ({ config, db }) => { }); budsiesApi.get('/plushies/rush-upgrades', async (req, res) => { + if (req.query.productId === undefined) { + apiStatus(res, 'The field productId is required', 400); + } + + const query = { + index: config.elasticsearch.index, + type: 'rush_upgrade', + body: { + query: { + terms: { + 'product_id': Array.isArray(req.query.productId) ? req.query.productId : [req.query.productId] + } + } + } + }; + + try { + const response = await es.search(query) + const hits = response.body ? response.body.hits : response.hits; + + const rushUpgrades = hits.hits.map((hit) => { + delete hit._source.tsk; + return hit._source; + }); + + apiStatus(res, rushUpgrades); + } catch (error) { + console.log(error); + apiStatus(res, error.toString(), error.code); + } + }); + + budsiesApi.get('/plushies/products-rush-upgrades', async (req, res) => { const query = { index: config.elasticsearch.index, type: 'rush_upgrade',