@punks/backend-entity-manager 0.0.401 → 0.0.404

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.
package/dist/cjs/index.js CHANGED
@@ -4055,6 +4055,14 @@ class TypeOrmRepository {
4055
4055
  const items = await this.innerRepository.find(condition);
4056
4056
  return items[0];
4057
4057
  }
4058
+ async findOneOrFail(condition) {
4059
+ this.logger.debug("Finding entity by condition", { condition });
4060
+ const items = await this.innerRepository.find(condition);
4061
+ if (items.length === 0) {
4062
+ throw new Error("Entity not found");
4063
+ }
4064
+ return items[0];
4065
+ }
4058
4066
  async findById(id) {
4059
4067
  this.logger.debug("Finding entities by id", { id });
4060
4068
  return await this.innerRepository.findBy({
@@ -4121,6 +4129,21 @@ class TypeOrmRepository {
4121
4129
  id,
4122
4130
  });
4123
4131
  }
4132
+ async upsertBy({ data, filter, }) {
4133
+ this.logger.debug("Upsert entities by condition", { filter, data });
4134
+ const current = await this.find(filter);
4135
+ if (current) {
4136
+ const id = current.id;
4137
+ await this.update(id, data);
4138
+ return {
4139
+ id,
4140
+ };
4141
+ }
4142
+ const entity = await this.create(data);
4143
+ return {
4144
+ id: entity.id,
4145
+ };
4146
+ }
4124
4147
  }
4125
4148
 
4126
4149
  class NestEntityAuthorizationMiddleware {