payload
Version:
Node, React, Headless CMS and Application Framework built on Next.js
30 lines (29 loc) • 1.12 kB
JavaScript
// @ts-strict-ignore
import { APIError } from '../../../errors/index.js';
import { createLocalReq } from '../../../utilities/createLocalReq.js';
import { duplicateOperation } from '../duplicate.js';
export async function duplicate(payload, options) {
const { id, collection: collectionSlug, data, depth, disableTransaction, draft, overrideAccess = true, populate, select, showHiddenFields } = options;
const collection = payload.collections[collectionSlug];
if (!collection) {
throw new APIError(`The collection with slug ${String(collectionSlug)} can't be found. Duplicate Operation.`);
}
if (collection.config.disableDuplicate === true) {
throw new APIError(`The collection with slug ${String(collectionSlug)} cannot be duplicated.`, 400);
}
const req = await createLocalReq(options, payload);
return duplicateOperation({
id,
collection,
data,
depth,
disableTransaction,
draft,
overrideAccess,
populate,
req,
select,
showHiddenFields
});
}
//# sourceMappingURL=duplicate.js.map