Skip to content

Duplicate file from collection to collection #487

Answered by denolfe
quornik asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @quornik, this is definitely possible by combining the use of a beforeChange hook and the local API operations.

Here is an example of how it can be done:

import { CollectionBeforeChangeHook, CollectionConfig } from 'payload/types'

const performOperationIfReviewed: CollectionBeforeChangeHook = async ({
  data, // incoming data to update or create with
  req, // full express request
  operation, // name of the operation ie. 'create', 'update'
  originalDoc, // original document
}) => {
  if (
    req?.user?.collection === 'admins' && // Admins collection only
    operation === 'update' && // Only on update operations
    !originalDoc.reviewed && data.reviewed // Transitioning from not …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by denolfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants