UNPKG

express-crud-router

Version:

React Admin backend for Express. 1 line per resource! ORM agnostic.

39 lines (33 loc) 825 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getOne = void 0; var _getList = require("./getList"); const getOne = (doGetList, options) => async (req, res, next) => { try { const { rows } = await doGetList({ filter: { id: req.params.id }, limit: 1, offset: 0, order: [] }, { req, res }); if (rows.length === 0) { return res.status(404).json({ error: 'Record not found' }); } const populatedRows = options?.additionalAttributes ? await (0, _getList.computeAdditionalAttributes)(options.additionalAttributes, options.additionalAttributesConcurrency ?? 1, req)(rows) : rows; res.json(populatedRows[0]); } catch (error) { next(error); } }; exports.getOne = getOne;