@lyxa.ai/core 1.0.76 → 1.0.77
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/libraries/mongo/models/embedded/courier-order-finance.model.d.ts +1 -1
- package/dist/libraries/mongo/models/embedded/courier-order-finance.model.js +1 -1
- package/dist/libraries/mongo/models/embedded/courier-order-finance.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/order-pricing.model.d.ts +3 -3
- package/dist/libraries/mongo/models/embedded/order-pricing.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/regular-order-finance.model.d.ts +1 -1
- package/dist/libraries/mongo/models/embedded/regular-order-finance.model.js +1 -1
- package/dist/libraries/mongo/models/embedded/regular-order-finance.model.js.map +1 -1
- package/dist/libraries/mongo/plugins/soft-delete-plugin.d.ts +2 -0
- package/dist/libraries/mongo/plugins/soft-delete-plugin.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,6 +2,6 @@ import { OrderFinance } from './order-finance.model';
|
|
|
2
2
|
import { CourierOrderProfit } from '../embedded/profit.model';
|
|
3
3
|
import { OrderPricing } from './order-pricing.model';
|
|
4
4
|
export declare class CourierOrderFinance extends OrderFinance {
|
|
5
|
-
pricing
|
|
5
|
+
pricing: OrderPricing;
|
|
6
6
|
companyProfit?: CourierOrderProfit;
|
|
7
7
|
}
|
|
@@ -20,7 +20,7 @@ class CourierOrderFinance extends order_finance_model_1.OrderFinance {
|
|
|
20
20
|
}
|
|
21
21
|
exports.CourierOrderFinance = CourierOrderFinance;
|
|
22
22
|
__decorate([
|
|
23
|
-
(0, typegoose_1.prop)({ type: () => order_pricing_model_1.OrderPricing }),
|
|
23
|
+
(0, typegoose_1.prop)({ required: true, type: () => order_pricing_model_1.OrderPricing }),
|
|
24
24
|
__metadata("design:type", order_pricing_model_1.OrderPricing)
|
|
25
25
|
], CourierOrderFinance.prototype, "pricing", void 0);
|
|
26
26
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"courier-order-finance.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/courier-order-finance.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAC5C,+DAAqD;AACrD,2DAA8D;AAC9D,+DAAqD;AAErD,MAAa,mBAAoB,SAAQ,kCAAY;IAE7C,OAAO,
|
|
1
|
+
{"version":3,"file":"courier-order-finance.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/courier-order-finance.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAC5C,+DAAqD;AACrD,2DAA8D;AAC9D,+DAAqD;AAErD,MAAa,mBAAoB,SAAQ,kCAAY;IAE7C,OAAO,CAAe;IAGtB,aAAa,CAAsB;CAC1C;AAND,kDAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,kCAAY,EAAE,CAAC;8BACnC,kCAAY;oDAAC;AAGtB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,iCAAkB,EAAE,CAAC;8BAClB,iCAAkB;0DAAC","sourcesContent":["import { prop } from '@typegoose/typegoose';\nimport { OrderFinance } from './order-finance.model';\nimport { CourierOrderProfit } from '../embedded/profit.model';\nimport { OrderPricing } from './order-pricing.model';\n\nexport class CourierOrderFinance extends OrderFinance {\n\t@prop({ required: true, type: () => OrderPricing })\n\tpublic pricing: OrderPricing;\n\n\t@prop({ type: () => CourierOrderProfit })\n\tpublic companyProfit?: CourierOrderProfit;\n}\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare class OrderPricing {
|
|
2
|
-
subtotal
|
|
2
|
+
subtotal: number;
|
|
3
3
|
secondarySubtotal?: number;
|
|
4
|
-
deliveryFee
|
|
4
|
+
deliveryFee: number;
|
|
5
5
|
secondaryDeliveryFee?: number;
|
|
6
6
|
riderTips?: number;
|
|
7
7
|
secondaryRiderTips?: number;
|
|
8
|
-
total
|
|
8
|
+
total: number;
|
|
9
9
|
secondaryTotal?: number;
|
|
10
10
|
wallet?: number;
|
|
11
11
|
secondaryWallet?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-pricing.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-pricing.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,YAAY;IAExB,QAAQ,
|
|
1
|
+
{"version":3,"file":"order-pricing.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-pricing.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,YAAY;IAExB,QAAQ,CAAS;IAGjB,iBAAiB,CAAU;IAG3B,WAAW,CAAS;IAGpB,oBAAoB,CAAU;IAG9B,SAAS,CAAU;IAGnB,kBAAkB,CAAU;IAG5B,KAAK,CAAS;IAGd,cAAc,CAAU;IAGxB,MAAM,CAAU;IAGhB,eAAe,CAAU;IAGzB,UAAU,CAAU;IAGpB,mBAAmB,CAAU;CAC7B;AApCD,oCAoCC;AAlCA;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;8CAClB;AAGjB;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;uDACR;AAG3B;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;iDACf;AAGpB;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0DACL;AAG9B;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;+CAChB;AAGnB;IADC,IAAA,gBAAI,EAA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AE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;0EACI;AAGvC;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;2DACX;AAGxB;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;oEACF;AAGjC;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;mEACH;AAGhC;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;4EACM","sourcesContent":["import { prop } from '@typegoose/typegoose';\n\nexport class OrderPricing {\n\t@prop({ type: Number, default: 0 })\n\tsubtotal: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondarySubtotal?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tdeliveryFee: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryDeliveryFee?: number;\n\n\t@prop({ type: Number, default: 0 })\n\triderTips?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryRiderTips?: number;\n\n\t@prop({ type: Number, default: 0 })\n\ttotal: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryTotal?: number;\n\n\t@prop({ type: Number, default: 0 })\n\twallet?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryWallet?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpaidAmount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryPaidAmount?: number;\n}\n\nexport class RegularOrderPricing extends OrderPricing {\n\t@prop({ type: Number, default: 0 })\n\tdiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tloyaltyPointDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryLoyaltyPointDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tcouponDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryCouponDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpunchMarketingDiscount?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryPunchMarketingDiscount?: number;\n}\n"]}
|
|
@@ -4,7 +4,7 @@ import { Vat } from '../embedded/vat.model';
|
|
|
4
4
|
import { CouponDetails, LoyaltyPoint, MarketingCut } from '../embedded/marketing-cut.model';
|
|
5
5
|
import { RegularOrderPricing } from './order-pricing.model';
|
|
6
6
|
export declare class RegularOrderFinance extends OrderFinance {
|
|
7
|
-
pricing
|
|
7
|
+
pricing: RegularOrderPricing;
|
|
8
8
|
companyProfit?: RegularOrderProfit;
|
|
9
9
|
shopProfit?: RegularOrderProfit;
|
|
10
10
|
vat?: Vat;
|
|
@@ -31,7 +31,7 @@ class RegularOrderFinance extends order_finance_model_1.OrderFinance {
|
|
|
31
31
|
}
|
|
32
32
|
exports.RegularOrderFinance = RegularOrderFinance;
|
|
33
33
|
__decorate([
|
|
34
|
-
(0, typegoose_1.prop)({ type: () => order_pricing_model_1.RegularOrderPricing }),
|
|
34
|
+
(0, typegoose_1.prop)({ required: true, type: () => order_pricing_model_1.RegularOrderPricing }),
|
|
35
35
|
__metadata("design:type", order_pricing_model_1.RegularOrderPricing)
|
|
36
36
|
], RegularOrderFinance.prototype, "pricing", void 0);
|
|
37
37
|
__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regular-order-finance.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/regular-order-finance.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAC5C,+DAAqD;AACrD,2DAA8D;AAC9D,qDAA4C;AAC5C,yEAA4F;AAC5F,+DAA4D;AAE5D,MAAa,mBAAoB,SAAQ,kCAAY;IAE7C,OAAO,
|
|
1
|
+
{"version":3,"file":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C;8BACb,kCAAY;yDAAC;AAG5B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,mCAAa,EAAE,CAAC;8BACpB,mCAAa;mDAAC;AAGvB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,kCAAY,EAAE,CAAC;8BACb,kCAAY;yDAAC;AAG5B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,kCAAY,EAAE,CAAC;8BACT,kCAAY;6DAAC;AAGhC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,kCAAY,EAAE,CAAC;8BACd,kCAAY;wDAAC","sourcesContent":["import { prop } from '@typegoose/typegoose';\nimport { OrderFinance } from './order-finance.model';\nimport { RegularOrderProfit } from '../embedded/profit.model';\nimport { Vat } from '../embedded/vat.model';\nimport { CouponDetails, LoyaltyPoint, MarketingCut } from '../embedded/marketing-cut.model';\nimport { RegularOrderPricing } from './order-pricing.model';\n\nexport class RegularOrderFinance extends OrderFinance {\n\t@prop({ required: true, type: () => RegularOrderPricing })\n\tpublic pricing: RegularOrderPricing;\n\t\n\t@prop({ type: () => RegularOrderProfit })\n\tpublic companyProfit?: RegularOrderProfit;\n\n\t@prop({ type: () => RegularOrderProfit })\n\tpublic shopProfit?: RegularOrderProfit;\n\n\t@prop({ type: () => Vat })\n\tpublic vat?: Vat;\n\n\t@prop({ type: () => MarketingCut })\n\tpublic discount?: MarketingCut;\n\n\t@prop({ type: () => MarketingCut })\n\tpublic buy1get1?: MarketingCut;\n\n\t@prop({ type: () => LoyaltyPoint })\n\tpublic loyaltyPoint?: LoyaltyPoint;\n\n\t@prop({ type: () => CouponDetails })\n\tpublic coupon?: CouponDetails;\n\n\t@prop({ type: () => MarketingCut })\n\tpublic freeDelivery?: MarketingCut;\n\n\t@prop({ type: () => MarketingCut })\n\tpublic replacementOrder?: MarketingCut;\n\n\t@prop({ type: () => MarketingCut })\n\tpublic endorseLoss?: MarketingCut;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Schema, Model } from 'mongoose';
|
|
2
2
|
import { ReturnModelType, mongoose } from '@typegoose/typegoose';
|
|
3
3
|
import { AnyParamConstructor } from '@typegoose/typegoose/lib/types';
|
|
4
|
+
import { GetByIdInputDTO } from '../../../utilities/validation';
|
|
4
5
|
export interface SoftDeleteModel<T> extends Model<T> {
|
|
5
6
|
softDelete(_id: mongoose.Types.ObjectId): Promise<any>;
|
|
6
7
|
softDeleteOne(filter: object): Promise<any>;
|
|
@@ -12,6 +13,7 @@ export interface SoftDeleteModel<T> extends Model<T> {
|
|
|
12
13
|
restoreMany(filter?: object): Promise<any>;
|
|
13
14
|
findWithDeleted(filter?: object): any;
|
|
14
15
|
findDeleted(filter?: object): any;
|
|
16
|
+
findRecordById(data: GetByIdInputDTO): Promise<any>;
|
|
15
17
|
}
|
|
16
18
|
export declare class SoftDeleteBase {
|
|
17
19
|
deletedAt?: Date | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"soft-delete-plugin.js","sourceRoot":"/","sources":["libraries/mongo/plugins/soft-delete-plugin.ts"],"names":[],"mappings":";;;AACA,oDAAmF;AAuBnF,MAAa,cAAc;IAC1B,SAAS,CAAe;CACxB;AAFD,wCAEC;AAKD,MAAa,UAAU;IAKf,MAAM,CAAC,aAAa,CAAC,MAAc;QAEzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/B,MAAM,CAAC,GAAG,CAAC;gBACV,SAAS,EAAE;oBACV,IAAI,EAAE,IAAI;oBACV,OAAO,EAAE,IAAI;oBACb,KAAK,EAAE,IAAI;iBACX;aACD,CAAC,CAAC;QACJ,CAAC;QAGD,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAGhC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAGhC,IA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,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC,CAAC;IACH,CAAC;CACD;AA3KD,gCA2KC;AAGM,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAQ,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AAA9E,QAAA,gBAAgB,oBAA8D;AACpF,MAAM,qBAAqB,GAAG,GAAS,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;AAA/D,QAAA,qBAAqB,yBAA0C;AACrE,MAAM,qBAAqB,GAAG,CACpC,UAAkC,EAC6B,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;AAFzF,QAAA,qBAAqB,yBAEoE","sourcesContent":["import { Schema, Query, Model } from 'mongoose';\nimport { getModelForClass, ReturnModelType, mongoose } from '@typegoose/typegoose';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { GetByIdInputDTO } from '../../../utilities/validation';\n\n/**\n * Interface for models with soft delete capabilities\n */\nexport interface SoftDeleteModel<T> extends Model<T> {\n\tsoftDelete(_id: mongoose.Types.ObjectId): Promise<any>;\n\tsoftDeleteOne(filter: object): Promise<any>;\n\tsoftDeleteMany(filter?: object): Promise<any>;\n\tdeleteRecord(filter: object, softDelete: boolean): Promise<any>;\n\tdeleteRecords(filter: object, softDelete: boolean): Promise<any>;\n\trestore(_id: mongoose.Types.ObjectId): Promise<any>;\n\trestoreOne(filter: object): Promise<any>;\n\trestoreMany(filter?: object): Promise<any>;\n\tfindWithDeleted(filter?: object): any;\n\tfindDeleted(filter?: object): any;\n}\n\n/**\n * Base class for models with soft delete functionality\n */\nexport class SoftDeleteBase {\n\tdeletedAt?: Date | null;\n}\n\n/**\n * SoftDelete class providing soft deletion functionality for mongoose models\n */\nexport class SoftDelete {\n\t/**\n\t * Apply soft delete plugin to a specific schema\n\t * @param schema Mongoose schema to enhance with soft delete functionality\n\t */\n\tpublic static applyToSchema(schema: Schema): void {\n\t\t// Add deletedAt field if it doesn't exist\n\t\tif (!schema.path('deletedAt')) {\n\t\t\tschema.add({\n\t\t\t\tdeletedAt: {\n\t\t\t\t\ttype: Date,\n\t\t\t\t\tdefault: null,\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Add schema middleware\n\t\tthis.addQueryMiddleware(schema);\n\n\t\t// Add instance methods\n\t\tthis.addInstanceMethods(schema);\n\n\t\t// Add static methods\n\t\tthis.addStaticMethods(schema);\n\t}\n\n\t/**\n\t * Apply soft delete plugin globally to all mongoose schemas\n\t */\n\tpublic static applyGlobally(): void {\n\t\tconst mongoose = require('mongoose');\n\t\tmongoose.plugin((schema: Schema) => this.applyToSchema(schema));\n\t}\n\n\t/**\n\t * Create a model with soft delete capabilities and proper TypeScript types\n\t * @param modelClass The class to create a model from\n\t * @returns A model with soft delete functionality\n\t */\n\tpublic static createModel<T extends SoftDeleteBase>(\n\t\tmodelClass: AnyParamConstructor<T>\n\t): SoftDeleteModel<T> & ReturnModelType<AnyParamConstructor<T>> {\n\t\tconst model = getModelForClass(modelClass);\n\t\treturn model as any; // The plugin adds the methods, we just need to tell TypeScript they exist\n\t}\n\n\t/**\n\t * Add query middleware to filter out soft-deleted documents\n\t * @param schema Schema to add middleware to\n\t */\n\tprivate static addQueryMiddleware(schema: Schema): void {\n\t\tconst queryMiddleware = function (this: Query<any, any>) {\n\t\t\tif (!this.getQuery().deletedAt) {\n\t\t\t\tthis.where({ deletedAt: null });\n\t\t\t}\n\t\t};\n\n\t\t// Apply middleware to relevant query methods\n\t\tschema.pre('find', queryMiddleware);\n\t\tschema.pre('findOne', queryMiddleware);\n\t\tschema.pre('findOneAndUpdate', queryMiddleware);\n\t\tschema.pre('findOneAndDelete', queryMiddleware);\n\t\tschema.pre('findOneAndReplace', queryMiddleware);\n\t\tschema.pre('updateOne', queryMiddleware);\n\t\tschema.pre('updateMany', queryMiddleware);\n\t\t// TypeScript workaround for count hook\n\t\t(schema as any).pre('count', queryMiddleware);\n\t\tschema.pre('countDocuments', queryMiddleware);\n\t\t(schema as any).pre('exists', queryMiddleware);\n\n\t\t// Override findById to respect soft delete\n\t\tschema.statics.findById = function (_id: mongoose.Types.ObjectId, projection?: any, options?: any) {\n\t\t\treturn this.findOne({ _id, deletedAt: null }, projection, options);\n\t\t};\n\t}\n\n\t/**\n\t * Add instance methods for soft delete operations\n\t * @param schema Schema to add methods to\n\t */\n\tprivate static addInstanceMethods(schema: Schema): void {\n\t\tschema.methods.softDelete = function () {\n\t\t\tthis.deletedAt = new Date();\n\t\t\treturn this.save();\n\t\t};\n\n\t\tschema.methods.restore = function () {\n\t\t\tthis.deletedAt = null;\n\t\t\treturn this.save();\n\t\t};\n\t}\n\n\t/**\n\t * Add static methods for soft delete operations\n\t * @param schema Schema to add methods to\n\t */\n\tprivate static addStaticMethods(schema: Schema): void {\n\t\tschema.statics.softDelete = async function (_id: mongoose.Types.ObjectId) {\n\t\t\tconst result = await this.updateOne({ _id }, { deletedAt: new Date() });\n\t\t\treturn result.modifiedCount > 0;\n\t\t};\n\n\t\tschema.statics.softDeleteOne = async function (filter: object) {\n\t\t\tconst result = await this.updateOne(filter, { deletedAt: new Date() });\n\t\t\treturn result.modifiedCount > 0;\n\t\t};\n\n\t\tschema.statics.softDeleteMany = function (filter = {}) {\n\t\t\treturn this.updateMany(filter, { deletedAt: new Date() });\n\t\t};\n\n\t\tschema.statics.deleteRecord = async function (filter: object, softDelete: boolean) {\n\t\t\tif (softDelete) {\n\t\t\t\tconst result = await this.updateOne({ ...filter, deletedAt: null }, { deletedAt: new Date() }).lean();\n\t\t\t\treturn Boolean(result.modifiedCount);\n\t\t\t} else {\n\t\t\t\tconst result = await this.deleteOne(filter).lean();\n\t\t\t\treturn Boolean(result.deletedCount);\n\t\t\t}\n\t\t};\n\n\t\tschema.statics.deleteRecords = async function (filter: object, softDelete: boolean) {\n\t\t\tif (softDelete) {\n\t\t\t\tconst result = await this.updateMany(\n\t\t\t\t\t{ ...filter, deletedAt: null },\n\t\t\t\t\t{ deletedAt: new Date() }\n\t\t\t\t).lean();\n\t\t\t\treturn Boolean(result.modifiedCount);\n\t\t\t} else {\n\t\t\t\tconst result = await this.deleteMany(filter).lean();\n\t\t\t\treturn Boolean(result.deletedCount);\n\t\t\t}\n\t\t};\n\n\t\tschema.statics.restore = function (_id: mongoose.Types.ObjectId) {\n\t\t\treturn this.updateOne({ _id }, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.restoreOne = function (filter: object) {\n\t\t\treturn this.updateOne(filter, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.restoreMany = function (filter = {}) {\n\t\t\treturn this.updateMany(filter, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.findWithDeleted = function (filter = {}) {\n\t\t\treturn this.find(filter);\n\t\t};\n\n\t\tschema.statics.findDeleted = function (filter = {}) {\n\t\t\treturn this.find({ ...filter, deletedAt: { $ne: null } });\n\t\t};\n\n\t\tschema.statics.findRecordById = async function (data: GetByIdInputDTO) {\n\t\t\tconst { _id, select, populate } = data;\n\n\t\t\tlet result = this.findById(_id);\n\n\t\t\tif (select) {\n\t\t\t\tresult = result.select(select) as any;\n\t\t\t}\n\n\t\t\tif (populate) {\n\t\t\t\tresult = result.populate(populate);\n\t\t\t}\n\n\t\t\treturn await result.exec();\n\t\t};\n\t}\n}\n\n// Export convenience functions with the same names as before for backward compatibility\nexport const softDeletePlugin = (schema: Schema): void => SoftDelete.applyToSchema(schema);\nexport const applySoftDeletePlugin = (): void => SoftDelete.applyGlobally();\nexport const createSoftDeleteModel = <T extends SoftDeleteBase>(\n\tmodelClass: AnyParamConstructor<T>\n): SoftDeleteModel<T> & ReturnModelType<AnyParamConstructor<T>> => SoftDelete.createModel(modelClass);\n"]}
|
|
1
|
+
{"version":3,"file":"soft-delete-plugin.js","sourceRoot":"/","sources":["libraries/mongo/plugins/soft-delete-plugin.ts"],"names":[],"mappings":";;;AACA,oDAAmF;AAwBnF,MAAa,cAAc;IAC1B,S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M,CAAC,OAAO,CAAC,cAAc,GAAG,KAAK,WAAW,IAAqB;YACpE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC;YAEvC,IAAI,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YAEhC,IAAI,MAAM,EAAE,CAAC;gBACZ,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAQ,CAAC;YACvC,CAAC;YAED,IAAI,QAAQ,EAAE,CAAC;gBACd,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACpC,CAAC;YAED,OAAO,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,CAAC,CAAC;IACH,CAAC;CACD;AA3KD,gCA2KC;AAGM,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAQ,EAAE,CAAC,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AAA9E,QAAA,gBAAgB,oBAA8D;AACpF,MAAM,qBAAqB,GAAG,GAAS,EAAE,CAAC,UAAU,CAAC,aAAa,EAAE,CAAC;AAA/D,QAAA,qBAAqB,yBAA0C;AACrE,MAAM,qBAAqB,GAAG,CACpC,UAAkC,EAC6B,EAAE,CAAC,UAAU,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;AAFzF,QAAA,qBAAqB,yBAEoE","sourcesContent":["import { Schema, Query, Model } from 'mongoose';\nimport { getModelForClass, ReturnModelType, mongoose } from '@typegoose/typegoose';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { GetByIdInputDTO } from '../../../utilities/validation';\n\n/**\n * Interface for models with soft delete capabilities\n */\nexport interface SoftDeleteModel<T> extends Model<T> {\n\tsoftDelete(_id: mongoose.Types.ObjectId): Promise<any>;\n\tsoftDeleteOne(filter: object): Promise<any>;\n\tsoftDeleteMany(filter?: object): Promise<any>;\n\tdeleteRecord(filter: object, softDelete: boolean): Promise<any>;\n\tdeleteRecords(filter: object, softDelete: boolean): Promise<any>;\n\trestore(_id: mongoose.Types.ObjectId): Promise<any>;\n\trestoreOne(filter: object): Promise<any>;\n\trestoreMany(filter?: object): Promise<any>;\n\tfindWithDeleted(filter?: object): any;\n\tfindDeleted(filter?: object): any;\n\tfindRecordById(data: GetByIdInputDTO): Promise<any>;\n}\n\n/**\n * Base class for models with soft delete functionality\n */\nexport class SoftDeleteBase {\n\tdeletedAt?: Date | null;\n}\n\n/**\n * SoftDelete class providing soft deletion functionality for mongoose models\n */\nexport class SoftDelete {\n\t/**\n\t * Apply soft delete plugin to a specific schema\n\t * @param schema Mongoose schema to enhance with soft delete functionality\n\t */\n\tpublic static applyToSchema(schema: Schema): void {\n\t\t// Add deletedAt field if it doesn't exist\n\t\tif (!schema.path('deletedAt')) {\n\t\t\tschema.add({\n\t\t\t\tdeletedAt: {\n\t\t\t\t\ttype: Date,\n\t\t\t\t\tdefault: null,\n\t\t\t\t\tindex: true,\n\t\t\t\t},\n\t\t\t});\n\t\t}\n\n\t\t// Add schema middleware\n\t\tthis.addQueryMiddleware(schema);\n\n\t\t// Add instance methods\n\t\tthis.addInstanceMethods(schema);\n\n\t\t// Add static methods\n\t\tthis.addStaticMethods(schema);\n\t}\n\n\t/**\n\t * Apply soft delete plugin globally to all mongoose schemas\n\t */\n\tpublic static applyGlobally(): void {\n\t\tconst mongoose = require('mongoose');\n\t\tmongoose.plugin((schema: Schema) => this.applyToSchema(schema));\n\t}\n\n\t/**\n\t * Create a model with soft delete capabilities and proper TypeScript types\n\t * @param modelClass The class to create a model from\n\t * @returns A model with soft delete functionality\n\t */\n\tpublic static createModel<T extends SoftDeleteBase>(\n\t\tmodelClass: AnyParamConstructor<T>\n\t): SoftDeleteModel<T> & ReturnModelType<AnyParamConstructor<T>> {\n\t\tconst model = getModelForClass(modelClass);\n\t\treturn model as any; // The plugin adds the methods, we just need to tell TypeScript they exist\n\t}\n\n\t/**\n\t * Add query middleware to filter out soft-deleted documents\n\t * @param schema Schema to add middleware to\n\t */\n\tprivate static addQueryMiddleware(schema: Schema): void {\n\t\tconst queryMiddleware = function (this: Query<any, any>) {\n\t\t\tif (!this.getQuery().deletedAt) {\n\t\t\t\tthis.where({ deletedAt: null });\n\t\t\t}\n\t\t};\n\n\t\t// Apply middleware to relevant query methods\n\t\tschema.pre('find', queryMiddleware);\n\t\tschema.pre('findOne', queryMiddleware);\n\t\tschema.pre('findOneAndUpdate', queryMiddleware);\n\t\tschema.pre('findOneAndDelete', queryMiddleware);\n\t\tschema.pre('findOneAndReplace', queryMiddleware);\n\t\tschema.pre('updateOne', queryMiddleware);\n\t\tschema.pre('updateMany', queryMiddleware);\n\t\t// TypeScript workaround for count hook\n\t\t(schema as any).pre('count', queryMiddleware);\n\t\tschema.pre('countDocuments', queryMiddleware);\n\t\t(schema as any).pre('exists', queryMiddleware);\n\n\t\t// Override findById to respect soft delete\n\t\tschema.statics.findById = function (_id: mongoose.Types.ObjectId, projection?: any, options?: any) {\n\t\t\treturn this.findOne({ _id, deletedAt: null }, projection, options);\n\t\t};\n\t}\n\n\t/**\n\t * Add instance methods for soft delete operations\n\t * @param schema Schema to add methods to\n\t */\n\tprivate static addInstanceMethods(schema: Schema): void {\n\t\tschema.methods.softDelete = function () {\n\t\t\tthis.deletedAt = new Date();\n\t\t\treturn this.save();\n\t\t};\n\n\t\tschema.methods.restore = function () {\n\t\t\tthis.deletedAt = null;\n\t\t\treturn this.save();\n\t\t};\n\t}\n\n\t/**\n\t * Add static methods for soft delete operations\n\t * @param schema Schema to add methods to\n\t */\n\tprivate static addStaticMethods(schema: Schema): void {\n\t\tschema.statics.softDelete = async function (_id: mongoose.Types.ObjectId) {\n\t\t\tconst result = await this.updateOne({ _id }, { deletedAt: new Date() });\n\t\t\treturn result.modifiedCount > 0;\n\t\t};\n\n\t\tschema.statics.softDeleteOne = async function (filter: object) {\n\t\t\tconst result = await this.updateOne(filter, { deletedAt: new Date() });\n\t\t\treturn result.modifiedCount > 0;\n\t\t};\n\n\t\tschema.statics.softDeleteMany = function (filter = {}) {\n\t\t\treturn this.updateMany(filter, { deletedAt: new Date() });\n\t\t};\n\n\t\tschema.statics.deleteRecord = async function (filter: object, softDelete: boolean) {\n\t\t\tif (softDelete) {\n\t\t\t\tconst result = await this.updateOne({ ...filter, deletedAt: null }, { deletedAt: new Date() }).lean();\n\t\t\t\treturn Boolean(result.modifiedCount);\n\t\t\t} else {\n\t\t\t\tconst result = await this.deleteOne(filter).lean();\n\t\t\t\treturn Boolean(result.deletedCount);\n\t\t\t}\n\t\t};\n\n\t\tschema.statics.deleteRecords = async function (filter: object, softDelete: boolean) {\n\t\t\tif (softDelete) {\n\t\t\t\tconst result = await this.updateMany(\n\t\t\t\t\t{ ...filter, deletedAt: null },\n\t\t\t\t\t{ deletedAt: new Date() }\n\t\t\t\t).lean();\n\t\t\t\treturn Boolean(result.modifiedCount);\n\t\t\t} else {\n\t\t\t\tconst result = await this.deleteMany(filter).lean();\n\t\t\t\treturn Boolean(result.deletedCount);\n\t\t\t}\n\t\t};\n\n\t\tschema.statics.restore = function (_id: mongoose.Types.ObjectId) {\n\t\t\treturn this.updateOne({ _id }, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.restoreOne = function (filter: object) {\n\t\t\treturn this.updateOne(filter, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.restoreMany = function (filter = {}) {\n\t\t\treturn this.updateMany(filter, { deletedAt: null });\n\t\t};\n\n\t\tschema.statics.findWithDeleted = function (filter = {}) {\n\t\t\treturn this.find(filter);\n\t\t};\n\n\t\tschema.statics.findDeleted = function (filter = {}) {\n\t\t\treturn this.find({ ...filter, deletedAt: { $ne: null } });\n\t\t};\n\n\t\tschema.statics.findRecordById = async function (data: GetByIdInputDTO) {\n\t\t\tconst { _id, select, populate } = data;\n\n\t\t\tlet result = this.findById(_id);\n\n\t\t\tif (select) {\n\t\t\t\tresult = result.select(select) as any;\n\t\t\t}\n\n\t\t\tif (populate) {\n\t\t\t\tresult = result.populate(populate);\n\t\t\t}\n\n\t\t\treturn await result.exec();\n\t\t};\n\t}\n}\n\n// Export convenience functions with the same names as before for backward compatibility\nexport const softDeletePlugin = (schema: Schema): void => SoftDelete.applyToSchema(schema);\nexport const applySoftDeletePlugin = (): void => SoftDelete.applyGlobally();\nexport const createSoftDeleteModel = <T extends SoftDeleteBase>(\n\tmodelClass: AnyParamConstructor<T>\n): SoftDeleteModel<T> & ReturnModelType<AnyParamConstructor<T>> => SoftDelete.createModel(modelClass);\n"]}
|