Files
klz-cables.com/.pnpm-store/v10/files/ae/41ffa8f95544e1f7c1e71435250517f25b72289de432d5791cedc1f008a4070b76b0c78379ad3d622a442d5abe695dc60b6ce4394fdbab5ba34dcd10eb79bf
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

60 lines
2.0 KiB
Plaintext

import { APIError } from '../errors/APIError.js';
export const getRequestCollection = (req)=>{
const collectionSlug = req.routeParams?.collection;
if (typeof collectionSlug !== 'string') {
throw new APIError(`No collection was specified`, 400);
}
const collection = req.payload.collections[collectionSlug];
if (!collection) {
throw new APIError(`Collection with the slug ${collectionSlug} was not found`, 404);
}
return collection;
};
export const getRequestCollectionWithID = (req, { disableSanitize, optionalID } = {})=>{
const collection = getRequestCollection(req);
const id = req.routeParams?.id;
if (typeof id !== 'string') {
if (optionalID) {
return {
id: undefined,
collection
};
}
throw new APIError(`ID was not specified`, 400);
}
if (disableSanitize === true) {
return {
id,
collection
};
}
let sanitizedID = id;
// If default db ID type is a number, we should sanitize
let shouldSanitize = Boolean(req.payload.db.defaultIDType === 'number');
// UNLESS the customIDType for this collection is text.... then we leave it
if (shouldSanitize && collection.customIDType === 'text') {
shouldSanitize = false;
}
// If we still should sanitize, parse float
if (shouldSanitize) {
sanitizedID = parseFloat(sanitizedID);
}
return {
// @ts-expect-error generic return
id: sanitizedID,
collection
};
};
export const getRequestGlobal = (req)=>{
const globalSlug = req.routeParams?.global;
if (typeof globalSlug !== 'string') {
throw new APIError(`No global was specified`, 400);
}
const globalConfig = req.payload.globals.config.find((each)=>each.slug === globalSlug);
if (!globalConfig) {
throw new APIError(`Global with the slug ${globalSlug} was not found`, 404);
}
return globalConfig;
};
//# sourceMappingURL=getRequestEntity.js.map