Skip to content

Commit

Permalink
feat: rename CommonDaoCfg.created/updated options
Browse files Browse the repository at this point in the history
to more verbose
  • Loading branch information
kirillgroshkov committed Jan 19, 2024
1 parent 8a05493 commit d58783e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/commondao/common.dao.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/commondao/common.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -680,11 +680,11 @@ export class CommonDao<
assignIdCreatedUpdated(obj: DBM | BM | Unsaved<BM>, opt: CommonDaoOptions = {}): DBM | Saved<BM> {
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
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit d58783e

Please sign in to comment.