/
mmr97
/
laba1_API
Обзор
Документация
Войти
/
mmr97
/
laba1_API
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/middleware/fields.js
24 строки
699 B
mmr97
lab2 updates
01 дек 2025, 14:26
01 дек 2025, 14:26
d4567aa
Код
Авторство
О чём код?
function parseInclude(req, res, next) { const raw = req.query.include; if (!raw) { req.includeFields = null; return next(); } // split by comma, trim, filter empty req.includeFields = raw.split(',').map(s => s.trim()).filter(Boolean); next(); } function pickFields(obj, includeFields) { if (!includeFields) return obj; // always include id, title and ownerId, createdAt, updatedAt const base = ['id','title','ownerId','createdAt','updatedAt']; const fields = Array.from(new Set([...base, ...includeFields])); const out = {}; for (const f of fields) { if (obj[f] !== undefined) out[f] = obj[f]; } return out; } module.exports = { parseInclude, pickFields };