payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
24 lines (23 loc) • 762 B
JavaScript
/**
* Resolves the target key when the client sends the temporary `pending` marker.
*/ export async function resolvePendingTargetKey(args) {
const { collectionSlug, orderableFieldName, req, targetDoc, targetID, targetKey } = args;
if (targetKey !== 'pending') {
return targetKey;
}
const targetDocKey = targetDoc?.[orderableFieldName];
if (typeof targetDocKey === 'string') {
return targetDocKey;
}
const beforeDoc = await req.payload.findByID({
id: targetID,
collection: collectionSlug,
depth: 0,
req,
select: {
[]: true
}
});
return beforeDoc?.[orderableFieldName] || null;
}
//# sourceMappingURL=resolvePendingTargetKey.js.map