import { FieldHook } from "payload";

const setAuthor: FieldHook = ({ value, req, data, field, operation }) => {
  if (req.user && !!data) {
    if (operation === "create") {
      return req.user.id;
    } else {
      if (field.name === "updatedBy") {
        return req.user.id;
      }
    }
  }

  return value;
};

export default setAuthor;
