UNPKG

als-mongo-list

Version:

A flexible, lightweight MongoDB query utility for Node.js applications. Simplifies database operations with intuitive filtering, pagination, sorting, and field selection. Ideal for REST API endpoints, providing a primary List class that abstracts complex

16 lines (15 loc) 882 B
function isValidDate(v, search, subKey, key) { if (!v || !/^\d{4}-\d{2}-\d{2}$/.test(v)) return; const [year, month, day] = v.split('-').map(Number); const date = new Date(Date.UTC(year, month - 1, day)); // Явно устанавливаем UTC if (!search[key]) search[key] = {}; search[key][subKey] = date; }; function date(key, item, obj) { if (item.type !== Date) return obj.validators[`${key}_gte`] = (v, search) => isValidDate(v, search, '$gte', key); // Дата больше или равна obj.validators[`${key}_lte`] = (v, search) => isValidDate(v, search, '$lte', key); // Дата меньше или равна obj.inputs[`${key}_gte`] = { tag: 'input', type: 'date', name: `${key}_gte`, key } obj.inputs[`${key}_lte`] = { tag: 'input', type: 'date', name: `${key}_lte`, key } } module.exports = { date, isValidDate }