UNPKG

@tasolutions/express-core

Version:
30 lines (26 loc) 871 B
const Response = require('../../utils/v1Response'); module.exports = { /** * This crud getByIds */ getByIds: async (req, res, Collection) => { const moduleName = Collection.collection.collectionName; try { const hash = req.body; let option = {}; for (var key of Object.keys(hash)) { option[`${key}`] = { $in: hash[key] }; } const result = Object.entries(option).length ? await Collection.find(option) : []; const crudOptions = { type: 'CRUD', action: 'GET_BY_IDS', typeName: moduleName, options: {} }; return Response.success(req, res, result, {}, crudOptions); } catch (e) { return Response.error(req, res, e.message); } } }