UNPKG

prisma-criteria

Version:

Parses, validates, and creates a criteria object that can be passed to the Prisma "findMany" method to query a list of resources matching the given filters, pagination and order.

13 lines 758 B
import { validationError, validationOk } from './shared/validation.util.js'; export function validateOrder(orderByProspect, orderDirProspect, allowedFieldsToOrderBy) { if (typeof orderByProspect !== 'string' || typeof orderDirProspect !== 'string') return validationError(undefined); const isOrderByProspectAllowed = allowedFieldsToOrderBy.includes(orderByProspect); if (!isOrderByProspectAllowed) return validationError(undefined); const isOrderDirProspectValid = orderDirProspect === 'asc' || orderDirProspect === 'desc'; if (!isOrderDirProspectValid) return validationError(undefined); return validationOk({ orderBy: { [orderByProspect]: orderDirProspect } }); } //# sourceMappingURL=order-validation.js.map