UNPKG

@windingtree/wt-search-api

Version:

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

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