@@ -13,6 +13,7 @@ import {
1313 AnyObject ,
1414 AppError ,
1515 AsyncMapper ,
16+ BaseDBEntity ,
1617 CommonLogger ,
1718 ErrorMode ,
1819 JsonSchemaObject ,
@@ -116,7 +117,7 @@ export class CommonDao<
116117 create ( part : Partial < BM > = { } , opt : CommonDaoOptions = { } ) : Saved < BM > {
117118 const bm = this . cfg . hooks ! . beforeCreate ! ( part )
118119 // First assignIdCreatedUpdated, then validate!
119- this . assignIdCreatedUpdated ( bm as BM , opt )
120+ this . assignIdCreatedUpdated ( bm , opt )
120121 return this . validateAndConvert ( bm , this . cfg . bmSchema , DBModelType . BM , opt )
121122 }
122123
@@ -674,28 +675,22 @@ export class CommonDao<
674675 * Mutates!
675676 * "Returns", just to have a type of "Saved"
676677 */
677- assignIdCreatedUpdated ( obj : Partial < DBM > , opt ?: CommonDaoOptions ) : Saved < Partial < DBM > >
678- assignIdCreatedUpdated ( obj : Partial < BM > , opt ?: CommonDaoOptions ) : Saved < Partial < BM > >
679- assignIdCreatedUpdated (
680- obj : Partial < DBM > | Partial < BM > ,
681- opt : CommonDaoOptions = { } ,
682- ) : Saved < Partial < DBM > > | Saved < Partial < BM > > {
678+ assignIdCreatedUpdated < T extends BaseDBEntity > ( obj : T , opt : CommonDaoOptions = { } ) : Saved < T > {
683679 const now = Math . floor ( Date . now ( ) / 1000 )
684680
685681 if ( this . cfg . useCreatedProperty ) {
686- ; ( obj as any ) [ ' created' ] ||= ( obj as any ) [ ' updated' ] || now
682+ obj . created ||= obj . updated || now
687683 }
688684
689685 if ( this . cfg . useUpdatedProperty ) {
690- ; ( obj as any ) [ 'updated' ] =
691- opt . preserveUpdatedCreated && ( obj as any ) [ 'updated' ] ? ( obj as any ) [ 'updated' ] : now
686+ obj . updated = opt . preserveUpdatedCreated && obj . updated ? obj . updated : now
692687 }
693688
694689 if ( this . cfg . createId ) {
695- obj . id ||= this . cfg . hooks ! . createNaturalId ?.( obj as BM ) || this . cfg . hooks ! . createRandomId ! ( )
690+ obj . id ||= this . cfg . hooks ! . createNaturalId ?.( obj as any ) || this . cfg . hooks ! . createRandomId ! ( )
696691 }
697692
698- return obj as any
693+ return obj as Saved < T >
699694 }
700695
701696 // SAVE
0 commit comments