Skip to content

Commit

Permalink
fix: getByIdOrEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 4, 2022
1 parent 4ed92a3 commit a53187b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/commondao/common.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,22 @@ export class CommonDao<
return bm || null
}

async getByIdOrEmpty(id: string, part: Partial<BM>, opt?: CommonDaoOptions): Promise<Saved<BM>> {
async getByIdOrEmpty(
id: string,
part: Partial<BM> = {},
opt?: CommonDaoOptions,
): Promise<Saved<BM>> {
const bm = await this.getById(id, opt)
if (bm) return bm

return this.create({ ...part, id }, opt)
}

async getByIdAsDBMOrEmpty(id: string, part: Partial<BM>, opt?: CommonDaoOptions): Promise<DBM> {
async getByIdAsDBMOrEmpty(
id: string,
part: Partial<BM> = {},
opt?: CommonDaoOptions,
): Promise<DBM> {
const dbm = await this.getByIdAsDBM(id, opt)
if (dbm) return dbm

Expand Down

0 comments on commit a53187b

Please sign in to comment.