All files / src/decorators timestamp-decorators.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                            131x 1x                           131x 1x                             131x 1x    
import { decorate } from './decorator-factory.ts';
import type { ModelPropertyDecorator } from './decorator-types.ts';
 
/**
 * Names the attribute that holds the creation time (`createdAt: '<attribute>'`).
 *
 * @example
 * ```ts
 * class User extends Model {
 *   @CreatedAt
 *   creationDate!: Date;
 * }
 * ```
 */
export const CreatedAt: ModelPropertyDecorator = decorate.forProperty((meta, key) => {
  meta.timestamps.createdAt = key;
});
 
/**
 * Names the attribute that holds the last update time (`updatedAt: '<attribute>'`).
 *
 * @example
 * ```ts
 * class User extends Model {
 *   @UpdatedAt
 *   updatedOn!: Date;
 * }
 * ```
 */
export const UpdatedAt: ModelPropertyDecorator = decorate.forProperty((meta, key) => {
  meta.timestamps.updatedAt = key;
});
 
/**
 * Names the attribute that holds the deletion time (`deletedAt: '<attribute>'`) and makes the
 * model paranoid unless `@Table` sets `paranoid` explicitly.
 *
 * @example
 * ```ts
 * class User extends Model {
 *   @DeletedAt
 *   removedAt!: Date | null;
 * }
 * ```
 */
export const DeletedAt: ModelPropertyDecorator = decorate.forProperty((meta, key) => {
  meta.timestamps.deletedAt = key;
});