UpdatedBy() function
Stamps the decorated column with the acting user id on INSERT and UPDATE, taken from the in-flight IMQ request metadata (currentMetadata()?.userId).
A property decorator, reusable on any model field. It mirrors @UpdatedAt: - on INSERT it is set to the creating actor (just as updatedAt is set equal to createdAt on insert), without overwriting an explicit value; - on UPDATE it always overwrites with the current actor — "last modified by" must reflect who actually ran the update and not be caller-spoofable.
Four hooks are registered, because models are written in four ways: - single INSERT → beforeCreate (set-if-empty) - Model.bulkCreate(records, …) → beforeBulkCreate (set-if-empty on the built instances; a plain bulkCreate does not fire beforeCreate, so the per-instance hook alone would be bypassed) - instance save() / update() → beforeUpdate (receives the instance) - static Model.update(values, …) → beforeBulkUpdate (receives options; the values to write live on options.attributes, and Sequelize filters the written columns down to options.fields, computed before this hook from the caller's values — so an injected field is dropped unless also added there).
No-op when there is no acting user (system / unattributed writes).
Signature:
export declare function UpdatedBy(target: any, propertyName: string): void;
Parameters
|
Parameter |
Type |
Description |
|---|---|---|
|
target |
any |
the decorated model's prototype |
|
propertyName |
string |
the decorated column property name |
Returns:
void