@lyxa.ai/core 1.1.89 → 1.1.90
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/order-pricing.model.d.ts +2 -0
- package/dist/libraries/mongo/models/embedded/order-pricing.model.js +10 -0
- package/dist/libraries/mongo/models/embedded/order-pricing.model.js.map +1 -1
- package/dist/libraries/mongo/models/embedded/wallet.model.d.ts +5 -0
- package/dist/libraries/mongo/models/embedded/wallet.model.js +32 -0
- package/dist/libraries/mongo/models/embedded/wallet.model.js.map +1 -0
- package/dist/libraries/mongo/models/user.model.d.ts +3 -2
- package/dist/libraries/mongo/models/user.model.js +8 -7
- package/dist/libraries/mongo/models/user.model.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/utilities/wallet.d.ts +4 -0
- package/dist/utilities/wallet.js +13 -0
- package/dist/utilities/wallet.js.map +1 -0
- package/package.json +1 -1
|
@@ -22,6 +22,8 @@ class OrderPricing {
|
|
|
22
22
|
secondaryTotal;
|
|
23
23
|
wallet;
|
|
24
24
|
secondaryWallet;
|
|
25
|
+
reserveWallet;
|
|
26
|
+
secondaryReserveWallet;
|
|
25
27
|
paidAmount;
|
|
26
28
|
secondaryPaidAmount;
|
|
27
29
|
}
|
|
@@ -66,6 +68,14 @@ __decorate([
|
|
|
66
68
|
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
67
69
|
__metadata("design:type", Number)
|
|
68
70
|
], OrderPricing.prototype, "secondaryWallet", void 0);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
73
|
+
__metadata("design:type", Number)
|
|
74
|
+
], OrderPricing.prototype, "reserveWallet", void 0);
|
|
75
|
+
__decorate([
|
|
76
|
+
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
77
|
+
__metadata("design:type", Number)
|
|
78
|
+
], OrderPricing.prototype, "secondaryReserveWallet", void 0);
|
|
69
79
|
__decorate([
|
|
70
80
|
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
71
81
|
__metadata("design:type", 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,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;
|
|
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,aAAa,CAAU;IAGvB,sBAAsB,CAAU;IAGhC,UAAU,CAAU;IAGpB,mBAAmB,CAAU;CAC7B;AA1CD,oCA0CC;AAxCA;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,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CAAU;IAGjC,sBAAsB,CAAU;IAGhC,+BAA+B,CAAU;CACzC;AAlBD,kDAkBC;AAhBA;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;qDACjB;AAGlB;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;8DACR;AAG3B;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\treserveWallet?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tsecondaryReserveWallet?: 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\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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Wallet = void 0;
|
|
13
|
+
const typegoose_1 = require("@typegoose/typegoose");
|
|
14
|
+
class Wallet {
|
|
15
|
+
main;
|
|
16
|
+
reserve;
|
|
17
|
+
total;
|
|
18
|
+
}
|
|
19
|
+
exports.Wallet = Wallet;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
22
|
+
__metadata("design:type", Number)
|
|
23
|
+
], Wallet.prototype, "main", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
26
|
+
__metadata("design:type", Number)
|
|
27
|
+
], Wallet.prototype, "reserve", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
30
|
+
__metadata("design:type", Number)
|
|
31
|
+
], Wallet.prototype, "total", void 0);
|
|
32
|
+
//# sourceMappingURL=wallet.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/wallet.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA4C;AAE5C,MAAa,MAAM;IAEX,IAAI,CAAU;IAGd,OAAO,CAAU;IAGjB,KAAK,CAAU;CACtB;AATD,wBASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;oCACd;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;uCACX;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;qCACb","sourcesContent":["import { prop } from '@typegoose/typegoose';\n\nexport class Wallet {\n\t@prop({ type: Number, default: 0 }) // top-up + refund\n\tpublic main?: number;\n\n\t@prop({ type: Number, default: 0 }) // cashback + add-credit\n\tpublic reserve?: number;\n\n\t@prop({ type: Number, default: 0 }) // main + reserve\n\tpublic total?: number;\n}\n"]}
|
|
@@ -9,6 +9,7 @@ import { Subscription } from './subscription.model';
|
|
|
9
9
|
import { OnlineStatus } from '../../../utilities/enum';
|
|
10
10
|
import { OTPFields } from './embedded/otp-fields.model';
|
|
11
11
|
import { GeoLocation } from './shared/geo-location.model';
|
|
12
|
+
import { Wallet } from './embedded/wallet.model';
|
|
12
13
|
export declare class User extends TimeStamps {
|
|
13
14
|
coreUser: Ref<CoreUser>;
|
|
14
15
|
userId: string;
|
|
@@ -18,7 +19,6 @@ export declare class User extends TimeStamps {
|
|
|
18
19
|
location?: GeoLocation;
|
|
19
20
|
orderCompleted?: number;
|
|
20
21
|
repeatedOrderAt?: Date;
|
|
21
|
-
walletBalance?: number;
|
|
22
22
|
coupons?: Ref<Coupon>[];
|
|
23
23
|
newUserCouponDiscountType?: string;
|
|
24
24
|
newUserCouponValue?: number;
|
|
@@ -32,7 +32,8 @@ export declare class User extends TimeStamps {
|
|
|
32
32
|
isPhoneVerified?: boolean;
|
|
33
33
|
onlineStatus?: OnlineStatus;
|
|
34
34
|
fcmTokens?: string[];
|
|
35
|
-
|
|
35
|
+
wallet?: Wallet;
|
|
36
|
+
static updateWallet(this: ReturnModelType<typeof User>, userId: string, main?: number, reserve?: number): Promise<(import("mongoose").Document<unknown, import("@typegoose/typegoose/lib/types").BeAnObject, User, import("@typegoose/typegoose/lib/types").BeAnyObject, {}> & Omit<User & {
|
|
36
37
|
_id: import("mongoose").Types.ObjectId;
|
|
37
38
|
} & {
|
|
38
39
|
__v: number;
|
|
@@ -24,6 +24,7 @@ const otp_fields_model_1 = require("./embedded/otp-fields.model");
|
|
|
24
24
|
const geo_location_model_1 = require("./shared/geo-location.model");
|
|
25
25
|
const id_generator_1 = require("../../../utilities/id-generator");
|
|
26
26
|
const _1 = require(".");
|
|
27
|
+
const wallet_model_1 = require("./embedded/wallet.model");
|
|
27
28
|
let User = User_1 = class User extends defaultClasses_1.TimeStamps {
|
|
28
29
|
coreUser;
|
|
29
30
|
userId;
|
|
@@ -33,7 +34,6 @@ let User = User_1 = class User extends defaultClasses_1.TimeStamps {
|
|
|
33
34
|
location;
|
|
34
35
|
orderCompleted;
|
|
35
36
|
repeatedOrderAt;
|
|
36
|
-
walletBalance;
|
|
37
37
|
coupons;
|
|
38
38
|
newUserCouponDiscountType;
|
|
39
39
|
newUserCouponValue;
|
|
@@ -47,8 +47,9 @@ let User = User_1 = class User extends defaultClasses_1.TimeStamps {
|
|
|
47
47
|
isPhoneVerified;
|
|
48
48
|
onlineStatus;
|
|
49
49
|
fcmTokens;
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
wallet;
|
|
51
|
+
static async updateWallet(userId, main = 0, reserve = 0) {
|
|
52
|
+
return this.findByIdAndUpdate(userId, { $inc: { 'wallet.main': main, 'wallet.reserve': reserve, 'wallet.total': main + reserve } }, { new: true });
|
|
52
53
|
}
|
|
53
54
|
};
|
|
54
55
|
exports.User = User;
|
|
@@ -84,10 +85,6 @@ __decorate([
|
|
|
84
85
|
(0, typegoose_1.prop)({ type: Date }),
|
|
85
86
|
__metadata("design:type", Date)
|
|
86
87
|
], User.prototype, "repeatedOrderAt", void 0);
|
|
87
|
-
__decorate([
|
|
88
|
-
(0, typegoose_1.prop)({ type: Number, default: 0 }),
|
|
89
|
-
__metadata("design:type", Number)
|
|
90
|
-
], User.prototype, "walletBalance", void 0);
|
|
91
88
|
__decorate([
|
|
92
89
|
(0, typegoose_1.prop)({ ref: () => coupon_model_1.Coupon }),
|
|
93
90
|
__metadata("design:type", Array)
|
|
@@ -144,6 +141,10 @@ __decorate([
|
|
|
144
141
|
(0, typegoose_1.prop)({ type: () => [String], default: [] }),
|
|
145
142
|
__metadata("design:type", Array)
|
|
146
143
|
], User.prototype, "fcmTokens", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
(0, typegoose_1.prop)({ type: wallet_model_1.Wallet }),
|
|
146
|
+
__metadata("design:type", wallet_model_1.Wallet)
|
|
147
|
+
], User.prototype, "wallet", void 0);
|
|
147
148
|
exports.User = User = User_1 = __decorate([
|
|
148
149
|
(0, typegoose_1.pre)('save', async function () {
|
|
149
150
|
if (this.isNew) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.model.js","sourceRoot":"/","sources":["libraries/mongo/models/user.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAA4F;AAC5F,4EAAqE;AACrE,uDAA6C;AAC7C,mDAA0C;AAC1C,6CAAoC;AACpC,0DAAqD;AACrD,iDAAwC;AACxC,6DAAoD;AACpD,kDAAoE;AACpE,kEAAwD;AACxD,oEAA0D;AAC1D,kEAA6D;AAC7D,wBAAiC;
|
|
1
|
+
{"version":3,"file":"user.model.js","sourceRoot":"/","sources":["libraries/mongo/models/user.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,oDAA4F;AAC5F,4EAAqE;AACrE,uDAA6C;AAC7C,mDAA0C;AAC1C,6CAAoC;AACpC,0DAAqD;AACrD,iDAAwC;AACxC,6DAAoD;AACpD,kDAAoE;AACpE,kEAAwD;AACxD,oEAA0D;AAC1D,kEAA6D;AAC7D,wBAAiC;AACjC,0DAAiD;AAU1C,IAAM,IAAI,YAAV,MAAM,IAAK,SAAQ,2BAAU;IAE5B,QAAQ,CAAiB;IAGzB,MAAM,CAAS;IAGf,gBAAgB,CAAkB;IAGlC,aAAa,CAAe;IAG5B,SAAS,CAAiB;IAG1B,QAAQ,CAAe;IAGvB,cAAc,CAAU;IAGxB,eAAe,CAAQ;IAGvB,OAAO,CAAiB;IAGxB,yBAAyB,CAAU;IAGnC,kBAAkB,CAAU;IAG5B,iCAAiC,CAAU;IAG3C,qBAAqB,CAAW;IAGhC,YAAY,CAAe;IAG3B,YAAY,CAAqB;IAGjC,YAAY,CAAW;IAGvB,WAAW,CAAU;IAGrB,YAAY,CAAa;IAGzB,eAAe,CAAW;IAO1B,YAAY,CAAgB;IAG5B,SAAS,CAAY;IAGrB,MAAM,CAAU;IAEhB,MAAM,CAAC,KAAK,CAAC,YAAY,CAE/B,MAAc,EACd,IAAI,GAAG,CAAC,EACR,OAAO,GAAG,CAAC;QAEX,OAAO,IAAI,CAAC,iBAAiB,CAC5B,MAAM,EACN,EAAE,IAAI,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C,EAAE,IAAI,EAAE,qBAAM,EAAE,CAAC;8BACP,qBAAM;oCAAC;eArEX,IAAI;IARhB,IAAA,eAAG,EAAO,MAAM,EAAE,KAAK;QACvB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,GAAG,MAAM,IAAA,yBAAU,EAAC,eAAY,EAAE,kBAAW,CAAC,IAAI,CAAC,CAAC;QAChE,CAAC;IACF,CAAC,CAAC;IACD,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;IACxD,IAAA,iBAAK,EAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC;IAC/B,IAAA,iBAAK,EAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;GACzB,IAAI,CAmFhB","sourcesContent":["import { index, modelOptions, pre, prop, Ref, ReturnModelType } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { CoreUser } from './core-user.model';\nimport { Product } from './product.model';\nimport { Shop } from './shop.model';\nimport { UserAddress } from './shared/address.model';\nimport { Coupon } from './coupon.model';\nimport { Subscription } from './subscription.model';\nimport { CounterType, OnlineStatus } from '../../../utilities/enum';\nimport { OTPFields } from './embedded/otp-fields.model';\nimport { GeoLocation } from './shared/geo-location.model';\nimport { generateId } from '../../../utilities/id-generator';\nimport { CounterModel } from '.';\nimport { Wallet } from './embedded/wallet.model';\n\n@pre<User>('save', async function () {\n\tif (this.isNew) {\n\t\tthis.userId = await generateId(CounterModel, CounterType.USER);\n\t}\n})\n@modelOptions({ schemaOptions: { collection: 'users' } })\n@index({ location: '2dsphere' })\n@index({ createdAt: 1, addresses: 1 })\nexport class User extends TimeStamps {\n\t@prop({ required: true, ref: () => CoreUser })\n\tpublic coreUser!: Ref<CoreUser>;\n\n\t@prop({ type: String, unique: true })\n\tpublic userId: string;\n\n\t@prop({ type: () => [String], ref: () => Product })\n\tpublic favoriteProducts?: Ref<Product>[];\n\n\t@prop({ type: () => [String], ref: () => Shop })\n\tpublic favoriteShops?: Ref<Shop>[];\n\n\t@prop({ type: () => [UserAddress], default: [] })\n\tpublic addresses?: UserAddress[];\n\n\t@prop({ type: GeoLocation }) // Last order location for finding user zone\n\tpublic location?: GeoLocation;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic orderCompleted?: number;\n\n\t@prop({ type: Date })\n\tpublic repeatedOrderAt?: Date;\n\n\t@prop({ ref: () => Coupon })\n\tpublic coupons?: Ref<Coupon>[];\n\n\t@prop({ type: String })\n\tpublic newUserCouponDiscountType?: string;\n\n\t@prop({ type: Number })\n\tpublic newUserCouponValue?: number;\n\n\t@prop({ type: Number })\n\tpublic newUserCouponMaximumDiscountLimit?: number;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isNewUserCouponShowed?: boolean;\n\n\t@prop({ ref: () => Coupon })\n\tpublic referralCode?: Ref<Coupon>;\n\n\t@prop({ type: String, ref: () => Subscription })\n\tpublic subscription?: Ref<Subscription>;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isSubscribed?: boolean;\n\n\t@prop({ type: String, unique: true, sparse: true })\n\tpublic phoneNumber?: string;\n\n\t@prop({ type: () => OTPFields })\n\tpublic phoneOtpInfo?: OTPFields;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isPhoneVerified?: boolean;\n\n\t@prop({\n\t\ttype: String,\n\t\tenum: OnlineStatus,\n\t\tdefault: OnlineStatus.OFFLINE,\n\t})\n\tpublic onlineStatus?: OnlineStatus;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic fcmTokens?: string[];\n\n\t@prop({ type: Wallet })\n\tpublic wallet?: Wallet;\n\n\tpublic static async updateWallet(\n\t\tthis: ReturnModelType<typeof User>,\n\t\tuserId: string,\n\t\tmain = 0,\n\t\treserve = 0\n\t) {\n\t\treturn this.findByIdAndUpdate(\n\t\t\tuserId,\n\t\t\t{ $inc: { 'wallet.main': main, 'wallet.reserve': reserve, 'wallet.total': main + reserve } },\n\t\t\t{ new: true }\n\t\t);\n\t}\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateWalletDeduction = calculateWalletDeduction;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
function calculateWalletDeduction(currentMainBalance, deductionAmount, isDualCurrencyEnabled) {
|
|
6
|
+
const round = isDualCurrencyEnabled ? shared_1.roundSecondaryCurrency : shared_1.roundBaseCurrency;
|
|
7
|
+
const remainingAfterMain = round(currentMainBalance - deductionAmount);
|
|
8
|
+
if (remainingAfterMain >= 0) {
|
|
9
|
+
return { mainWalletChange: -deductionAmount, reserveWalletChange: 0 };
|
|
10
|
+
}
|
|
11
|
+
return { mainWalletChange: -currentMainBalance, reserveWalletChange: remainingAfterMain };
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"/","sources":["utilities/wallet.ts"],"names":[],"mappings":";;AAOA,4DAkBC;AAzBD,qCAAqE;AAOrE,SAAgB,wBAAwB,CACvC,kBAA0B,EAC1B,eAAuB,EACvB,qBAA4B;IAK5B,MAAM,KAAK,GAAG,qBAAqB,CAAC,CAAC,CAAC,+BAAsB,CAAC,CAAC,CAAC,0BAAiB,CAAC;IACjF,MAAM,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,GAAG,eAAe,CAAC,CAAC;IAGvE,IAAI,kBAAkB,IAAI,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,gBAAgB,EAAE,CAAC,eAAe,EAAE,mBAAmB,EAAE,CAAC,EAAE,CAAC;IACvE,CAAC;IAGD,OAAO,EAAE,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;AAC3F,CAAC","sourcesContent":["import { roundBaseCurrency, roundSecondaryCurrency } from './shared';\n\n/**\n * Calculates how much to deduct from a user's wallets.\n * Deducts from the main wallet first, then from the reserve wallet if needed.\n * Returns negative values (for use with $inc updates in MongoDB).\n */\nexport function calculateWalletDeduction(\n\tcurrentMainBalance: number,\n\tdeductionAmount: number,\n\tisDualCurrencyEnabled?: true\n): {\n\tmainWalletChange: number;\n\treserveWalletChange: number;\n} {\n\tconst round = isDualCurrencyEnabled ? roundSecondaryCurrency : roundBaseCurrency;\n\tconst remainingAfterMain = round(currentMainBalance - deductionAmount);\n\n\t// If main has enough, reserve doesn't change\n\tif (remainingAfterMain >= 0) {\n\t\treturn { mainWalletChange: -deductionAmount, reserveWalletChange: 0 };\n\t}\n\n\t// Otherwise, deduct all from main and the remainder (negative) from reserve\n\treturn { mainWalletChange: -currentMainBalance, reserveWalletChange: remainingAfterMain };\n}\n"]}
|