/********* START OF METHOD LOGIC *********/
const updateObject: Jsm.Core.Utils.Entity.General.IItemUpdate = {
  updated_by_system: !authData?.current?.user,
  updated_by: getUserSnapshot(authData?.current?.user),
  date: new Date(),
  action: "deleted",
  updates: [],
};

const old = await this.{{SUB_MODULE_ENTITY_CAMELCASED_SINGULAR}}Model.findById(id);
if (!old) throw new exceptions.ItemNotFoundException("{{capitalize ENTITY_NAMING.entityWords}} not found");
if (old.is_deleted)
  throw new exceptions.UnauthorizedException("{{capitalize ENTITY_NAMING.entityWords}} already deleted");

const userGranted = await userCan.deleteObject(this.ENTITY, old, authData);
if (!userGranted){
  throw new exceptions.UnauthorizedException(
    "You are not allowed to delete this {{ENTITY_NAMING.entityWords}}"
  );
}

const doc = await this.{{SUB_MODULE_ENTITY_CAMELCASED_SINGULAR}}Model.findByIdAndUpdate(
  id,
  {
    is_deleted: true,
    deleted_at: new Date(),
    $addToSet: {
      updates: updateObject,
    },
  },
  { new: true }
);

/**
  * Fill the result object
  */
result = {
  data: {
    deleted: true,
  },
};
/********* END OF METHOD LOGIC *********/