move old to legacy folder

This commit is contained in:
Primakov Alexandr Alexandrovich
2025-01-19 21:09:17 +03:00
parent 8a2afc3f1b
commit 270fe51500
289 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
const router = require('express').Router()
// The code in this folder is partially based on the code from this repo:
// https://bitbucket.org/online-mentor/auth-system/src/master/stubs/api/
const wait = (time = "100") => (req, res, next) => setTimeout(next, time)
const stubs = [
['cart', 'get', 'success'],
// ['search', 'get', 'success'],
['cart', 'post', 'success'],
]
for (let [func, method, mock] of stubs) {
router[method](`/${func}`, wait(), (req, res) => {
res.send(require(`./mocks/${func}_${method}/${mock}`))
})
}
router.get('/search', wait(), (req, res, _) => {
let data = require('./mocks/search_get/success.json')
let { items } = data
const filters = req.query.filters.length > 0 ? req.query.filters.split(',') : []
const query = req.query.query.toLowerCase()
const chairsToSend = []
for (const chair of items) {
if (chair.model.toLowerCase().includes(query) && filters.every((tag) => chair.tags.includes(tag))) {
chairsToSend.push(chair)
}
}
res.send(
{
success: true,
items: chairsToSend,
},
)
})
module.exports = router