From d58783e2307b82be8bcd454240a72c6584bfcfd4 Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Fri, 19 Jan 2024 10:58:00 +0100 Subject: [PATCH] feat: rename CommonDaoCfg.created/updated options to more verbose --- src/commondao/common.dao.model.ts | 4 ++-- src/commondao/common.dao.ts | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/commondao/common.dao.model.ts b/src/commondao/common.dao.model.ts index 6678352..2ce1a36 100644 --- a/src/commondao/common.dao.model.ts +++ b/src/commondao/common.dao.model.ts @@ -200,13 +200,13 @@ export interface CommonDaoCfg< * Defaults to true * Set to false to disable `created` field management. */ - created?: boolean + useCreatedProperty?: boolean /** * Defaults to true * Set to false to disable `updated` field management. */ - updated?: boolean + useUpdatedProperty?: boolean /** * Default is false. diff --git a/src/commondao/common.dao.ts b/src/commondao/common.dao.ts index d269c59..decbc1d 100644 --- a/src/commondao/common.dao.ts +++ b/src/commondao/common.dao.ts @@ -88,8 +88,8 @@ export class CommonDao< logLevel: isGAE || isCI ? CommonDaoLogLevel.NONE : CommonDaoLogLevel.OPERATIONS, createId: true, assignGeneratedIds: false, - created: true, - updated: true, + useCreatedProperty: true, + useUpdatedProperty: true, logger: console, ...cfg, hooks: { @@ -680,11 +680,11 @@ export class CommonDao< assignIdCreatedUpdated(obj: DBM | BM | Unsaved, opt: CommonDaoOptions = {}): DBM | Saved { const now = Math.floor(Date.now() / 1000) - if (this.cfg.created) { + if (this.cfg.useCreatedProperty) { ;(obj as any)['created'] ||= (obj as any)['updated'] || now } - if (this.cfg.updated) { + if (this.cfg.useUpdatedProperty) { ;(obj as any)['updated'] = opt.preserveUpdatedCreated && (obj as any)['updated'] ? (obj as any)['updated'] : now } @@ -1347,7 +1347,7 @@ export class CommonDao< try { await fn(daoTx) } catch (err) { - await daoTx.rollback() + await daoTx.rollback() // graceful rollback that "never throws" throw err } }, opt)