@kipicore/dbcore 1.1.159 → 1.1.160

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.
@@ -30,6 +30,11 @@ export declare class MongooseCommonService<T extends Document> implements IMongo
30
30
  userId?: string;
31
31
  session?: ClientSession;
32
32
  }): Promise<UpdateWriteOpResult | null>;
33
+ hardDelete(filter: FilterQuery<T>, options?: MongooseUpdateQueryOptions<T> & {
34
+ session?: ClientSession;
35
+ }): Promise<{
36
+ deletedCount?: number;
37
+ }>;
33
38
  aggregate(pipeline: PipelineStage[]): Promise<{
34
39
  [key: string]: string | number | object;
35
40
  }[]>;
@@ -99,6 +99,13 @@ class MongooseCommonService {
99
99
  async delete(filter, options = {}) {
100
100
  return this.model.updateMany(filter, { deletedBy: options.userId, deletedAt: new Date() }, options).exec();
101
101
  }
102
+ async hardDelete(filter, options) {
103
+ return this.model
104
+ .deleteMany(filter, {
105
+ session: options?.session,
106
+ })
107
+ .exec();
108
+ }
102
109
  async aggregate(pipeline) {
103
110
  return this.model.aggregate(pipeline).exec();
104
111
  }
@@ -13,5 +13,6 @@ export declare class SequelizeCommonService<T extends Model> implements ISequeli
13
13
  create: (createData: T["_creationAttributes"], options?: CreateOptions) => Promise<T["_attributes"]>;
14
14
  bulkCreate: (createData: T["_creationAttributes"][], options?: BulkCreateOptions<T["_attributes"]>) => Promise<T["_attributes"][]>;
15
15
  delete: (where: WhereOptions<T["_attributes"]>, options?: DestroyOptions<T["_attributes"]>) => Promise<number>;
16
+ hardDelete: (where: WhereOptions<T["_attributes"]>, options?: Omit<DestroyOptions<T["_attributes"]>, "where">) => Promise<number>;
16
17
  count: (where: WhereOptions<T["_attributes"]>, options?: CountOptions<T["_attributes"]>) => Promise<number>;
17
18
  }
@@ -102,6 +102,14 @@ class SequelizeCommonService {
102
102
  throw err;
103
103
  }
104
104
  };
105
+ this.hardDelete = async (where, options) => {
106
+ try {
107
+ return this.model.destroy({ where, force: true, ...options });
108
+ }
109
+ catch (err) {
110
+ throw err;
111
+ }
112
+ };
105
113
  this.count = (where, options) => {
106
114
  try {
107
115
  return this.model.count({ where, ...options });
@@ -30,6 +30,11 @@ interface IDeleteService<T extends Document> {
30
30
  userId?: string;
31
31
  session?: ClientSession;
32
32
  }): Promise<UpdateWriteOpResult | null>;
33
+ hardDelete(filter: FilterQuery<T>, options?: MongooseUpdateQueryOptions<T> & {
34
+ session?: ClientSession;
35
+ }): Promise<{
36
+ deletedCount?: number;
37
+ }>;
33
38
  }
34
39
  export interface IMongooseCommonService<T extends Document> extends IReadService<T>, IWriteService<T>, IDeleteService<T> {
35
40
  }
@@ -15,6 +15,7 @@ interface IWriteService<T extends Model> {
15
15
  }
16
16
  interface IDeleteService<T extends Model> {
17
17
  delete(where: WhereOptions<T['_attributes']>, options?: DestroyOptions<T['_attributes']>): Promise<number>;
18
+ hardDelete(where: WhereOptions<T['_attributes']>, options?: DestroyOptions<T['_attributes']>): Promise<number>;
18
19
  }
19
20
  export interface ISequelizeCommonService<T extends Model> extends IReadService<T>, IWriteService<T>, IDeleteService<T> {
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kipicore/dbcore",
3
- "version": "1.1.159",
3
+ "version": "1.1.160",
4
4
  "description": "Reusable DB core package with Postgres, MongoDB, models, services, interfaces, and types",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",