$ open source · GPL-3.0 — need a commercial license? imqueue.com →

DeletedBy() function

Stamps the decorated column with the acting user id on soft-delete (and clears it on restore), taken from the in-flight IMQ request metadata (currentMetadata()?.userId). Mirrors @DeletedAt: set on delete, cleared on restore, and a delete touches neither updatedAt nor an @UpdatedBy column.

A property decorator for paranoid models, reusable on any field. Soft-delete runs through Model.destroy, which Sequelize turns into a deletedAt-only UPDATE whose value hash is built internally and is unreachable from any hook. So instead of mutating that statement, the beforeBulkDestroy hook stamps the column with a sibling UPDATE over the same still-live rows (same where, same transaction) just before the soft-delete sets deletedAt; beforeBulkRestore does the inverse, clearing it as deletedAt is cleared.

The sibling UPDATE runs on this — the concrete model the hook fires for, bound by Sequelize at call time (runHookshook.apply(model, ...)) — rather than the class captured at decoration time. That lets the decorator be declared on an abstract base model (e.g. a shared BaseParanoid) and still resolve to the real subclass; the captured constructor would be the (unregistered) base and break with "model not initialized".

hooks: false avoids hook re-entrancy and keeps the delete from bumping an @UpdatedBy column; silent: true keeps it from bumping updatedAt, so the delete writes exactly deletedBy + deletedAt (like the native paranoid delete writes only deletedAt). No-op when there is no acting user.

Signature:

export declare function DeletedBy(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