Skip to content

Commit

Permalink
Merge pull request novuhq#4004 from novuhq/execution-detail-no-write-…
Browse files Browse the repository at this point in the history
…concern

feat: execution detail no write concern
  • Loading branch information
djabarovgeorge authored Aug 22, 2023
2 parents 53d2acd + fa84003 commit 602f83b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class CreateExecutionDetails {
command.channel
);

await this.executionDetailsRepository.create(executionDetailsEntity);
await this.executionDetailsRepository.create(executionDetailsEntity, { writeConcern: 1 });
}

private mapWebhookEventIntoEntity(
Expand Down
11 changes: 9 additions & 2 deletions libs/dal/src/repositories/base-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,16 @@ export class BaseRepository<T_DBModel, T_MappedEntity, T_Enforcement = object> {
}
}

async create(data: FilterQuery<T_DBModel> & T_Enforcement): Promise<T_MappedEntity> {
async create(data: FilterQuery<T_DBModel> & T_Enforcement, options: IOptions = {}): Promise<T_MappedEntity> {
const expireAt = this.calcExpireDate(this.MongooseModel.modelName, data);
if (expireAt) {
data = { ...data, expireAt };
}
const newEntity = new this.MongooseModel(data);
const saved = await newEntity.save();

const saveOptions = options?.writeConcern ? { w: options?.writeConcern } : {};

const saved = await newEntity.save(saveOptions);

return this.mapEntity(saved);
}
Expand Down Expand Up @@ -175,3 +178,7 @@ export class BaseRepository<T_DBModel, T_MappedEntity, T_Enforcement = object> {
return plainToInstance<T_MappedEntity, T_MappedEntity[]>(this.entity, JSON.parse(JSON.stringify(data)));
}
}

interface IOptions {
writeConcern?: number | 'majority';
}

0 comments on commit 602f83b

Please sign in to comment.