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
60 lines
1.2 KiB
Plaintext
60 lines
1.2 KiB
Plaintext
import { sanitizeID } from '@payloadcms/ui/shared';
|
|
import { logError } from 'payload';
|
|
export const getDocumentData = async ({
|
|
id: idArg,
|
|
collectionSlug,
|
|
globalSlug,
|
|
locale,
|
|
payload,
|
|
req,
|
|
segments,
|
|
user
|
|
}) => {
|
|
const id = sanitizeID(idArg);
|
|
let resolvedData = null;
|
|
const {
|
|
transactionID,
|
|
...rest
|
|
} = req;
|
|
const isTrashedDoc = segments?.[2] === 'trash' && typeof segments?.[3] === 'string' // id exists at segment 3
|
|
;
|
|
try {
|
|
if (collectionSlug && id) {
|
|
resolvedData = await payload.findByID({
|
|
id,
|
|
collection: collectionSlug,
|
|
depth: 0,
|
|
draft: true,
|
|
fallbackLocale: false,
|
|
locale: locale?.code,
|
|
overrideAccess: false,
|
|
req: {
|
|
...rest
|
|
},
|
|
trash: isTrashedDoc ? true : false,
|
|
user
|
|
});
|
|
}
|
|
if (globalSlug) {
|
|
resolvedData = await payload.findGlobal({
|
|
slug: globalSlug,
|
|
depth: 0,
|
|
draft: true,
|
|
fallbackLocale: false,
|
|
locale: locale?.code,
|
|
overrideAccess: false,
|
|
req: {
|
|
...rest
|
|
},
|
|
user
|
|
});
|
|
}
|
|
} catch (err) {
|
|
logError({
|
|
err,
|
|
payload
|
|
});
|
|
}
|
|
return resolvedData;
|
|
};
|
|
//# sourceMappingURL=getDocumentData.js.map |