UNPKG

@windingtree/wt-search-api

Version:

NodeJS app that enables quick search over data from Winding Tree platform

42 lines (37 loc) 889 B
const Category = require('../../../db/indexed/models/category'); function getFiltering (query) { if (!query.filters) { return undefined; } const filters = query.filters.filter((f) => f.type === 'category'); if (!filters.length) { return undefined; } return filters.map((filter) => { return { table: Category.TABLE, condition: function () { this.where(`${Category.TABLE}.category`, '=', `${filter.condition}`); }, }; }); } /** * This does not support any sorting. */ function getSorting (query) { return undefined; } async function indexHotel (hotel) { const category = hotel.data.description && hotel.data.description.category; if (category) { await Category.upsert(hotel.address, category); } else { await Category.delete(hotel.address); } } module.exports = { getFiltering, getSorting, indexHotel, };