@decaf-ts/core
Version:
Core persistence module for the decaf framework
30 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createdByOnRamCreateUpdate = createdByOnRamCreateUpdate;
const persistence_1 = require("./../persistence/index.cjs");
/**
* @description Sets the created by field on a model during RAM create/update operations
* @summary Automatically populates a model field with the UUID from the context during create or update operations.
* This function is designed to be used as a handler for RAM operations to track entity creation.
* @template M - Type of the model being created/updated
* @template R - Type of the repository handling the model
* @template V - Type of the relations metadata
* @template F - Type of the RAM flags
* @template C - Type of the context
* @param {R} this - The repository instance
* @param {Context<F>} context - The operation context containing user identification
* @param {V} data - The relations metadata
* @param key - The property key to set with the UUID
* @param {M} model - The model instance being created/updated
* @return {Promise<void>} A promise that resolves when the field has been set
* @function createdByOnRamCreateUpdate
* @memberOf module:core
* @category Ram
*/
async function createdByOnRamCreateUpdate(context, data, key, model) {
const uuid = context.get("UUID");
if (!uuid)
throw new persistence_1.UnsupportedError("This adapter does not support user identification");
model[key] = uuid;
}
//# sourceMappingURL=handlers.js.map