@punks/backend-entity-manager 0.0.401 → 0.0.402

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,8 @@ export interface IEntityRepository<TEntity, TEntityId, TGetConditions, TFindCond
9
9
  getBy(condition: TGetConditions): Promise<TEntity | undefined>;
10
10
  all(): Promise<TEntity[]>;
11
11
  find(condition: TFindCondition): Promise<TEntity[]>;
12
+ findOne(condition: TFindCondition): Promise<TEntity | undefined>;
13
+ findOneOrFail(condition: TFindCondition): Promise<TEntity>;
12
14
  findById(id: TEntityId[]): Promise<TEntity[]>;
13
15
  count(condition: TFindCondition): Promise<number>;
14
16
  delete(id: TEntityId): Promise<void>;
@@ -18,7 +18,8 @@ export declare class TypeOrmRepository<TEntity extends ObjectLiteral, TEntityId>
18
18
  all(): Promise<TEntity[]>;
19
19
  count(condition: FindManyOptions<TEntity>): Promise<number>;
20
20
  find(condition: FindManyOptions<TEntity>): Promise<TEntity[]>;
21
- findOne(condition: FindManyOptions<TEntity>): Promise<TEntity>;
21
+ findOne(condition: FindManyOptions<TEntity>): Promise<TEntity | undefined>;
22
+ findOneOrFail(condition: FindManyOptions<TEntity>): Promise<TEntity>;
22
23
  findById(id: TEntityId[]): Promise<TEntity[]>;
23
24
  delete(id: TEntityId): Promise<void>;
24
25
  deleteBy(condition: DeleteCriteria<TEntity>): Promise<IEntitiesDeleteResult>;
@@ -8,6 +8,8 @@ export declare class InMemoryRepository<TEntity> implements IEntityRepository<TE
8
8
  getBy(condition: FilterExpression<TEntity>): Promise<TEntity | undefined>;
9
9
  all(): Promise<TEntity[]>;
10
10
  find(condition: FilterExpression<TEntity>): Promise<TEntity[]>;
11
+ findOne(condition: FilterExpression<TEntity>): Promise<TEntity | undefined>;
12
+ findOneOrFail(condition: FilterExpression<TEntity>): Promise<TEntity>;
11
13
  count(condition: FilterExpression<TEntity>): Promise<number>;
12
14
  findById(id: string[]): Promise<TEntity[]>;
13
15
  delete(id: string): Promise<void>;
package/dist/esm/index.js CHANGED
@@ -4040,6 +4040,14 @@ class TypeOrmRepository {
4040
4040
  const items = await this.innerRepository.find(condition);
4041
4041
  return items[0];
4042
4042
  }
4043
+ async findOneOrFail(condition) {
4044
+ this.logger.debug("Finding entity by condition", { condition });
4045
+ const items = await this.innerRepository.find(condition);
4046
+ if (items.length === 0) {
4047
+ throw new Error("Entity not found");
4048
+ }
4049
+ return items[0];
4050
+ }
4043
4051
  async findById(id) {
4044
4052
  this.logger.debug("Finding entities by id", { id });
4045
4053
  return await this.innerRepository.findBy({