@lyxa.ai/core 1.3.201 → 1.3.203
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/cash-settlement/cashSettlementService.d.ts +0 -5
- package/dist/libraries/cash-settlement/cashSettlementService.js +0 -15
- package/dist/libraries/cash-settlement/cashSettlementService.js.map +1 -1
- package/dist/libraries/cash-settlement/interfaces/ICashSettlement.d.ts +0 -5
- package/dist/libraries/cash-settlement/interfaces/ICashSettlement.js.map +1 -1
- package/dist/libraries/cash-settlement/providers/bob.d.ts +0 -7
- package/dist/libraries/cash-settlement/providers/bob.js +3 -86
- package/dist/libraries/cash-settlement/providers/bob.js.map +1 -1
- package/dist/libraries/firebase/fcmService.js +15 -14
- package/dist/libraries/firebase/fcmService.js.map +1 -1
- package/dist/libraries/mongo/models/banner.model.d.ts +1 -2
- package/dist/libraries/mongo/models/banner.model.js +0 -5
- package/dist/libraries/mongo/models/banner.model.js.map +1 -1
- package/dist/libraries/trpc/middlewares/auth.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +1 -1
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/enum.d.ts +1 -2
- package/dist/types/utilities/enum.js +0 -1
- package/dist/types/utilities/enum.js.map +1 -1
- package/dist/utilities/enum.d.ts +1 -2
- package/dist/utilities/enum.js +0 -1
- package/dist/utilities/enum.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,9 +10,4 @@ export declare class CashSettlementService {
|
|
|
10
10
|
markSettlementAsPaid(reference: string): Promise<boolean>;
|
|
11
11
|
hasPendingSettlements(reference: string): Promise<boolean>;
|
|
12
12
|
getLastSettlement(reference: string): Promise<ISettlementInfo | null>;
|
|
13
|
-
markSettlementAsPaidBySettlementId(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
14
|
-
revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
|
|
15
|
-
hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
16
|
-
getLastRiderSettlement(riderId: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;
|
|
17
|
-
markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
18
13
|
}
|
|
@@ -35,21 +35,6 @@ let CashSettlementService = class CashSettlementService {
|
|
|
35
35
|
async getLastSettlement(reference) {
|
|
36
36
|
return await this.service.getLastSettlement(reference);
|
|
37
37
|
}
|
|
38
|
-
async markSettlementAsPaidBySettlementId(settlementId) {
|
|
39
|
-
return await this.service.markSettlementAsPaidBySettlementId(settlementId);
|
|
40
|
-
}
|
|
41
|
-
async revokeRiderSettlements(rider) {
|
|
42
|
-
return await this.service.revokeRiderSettlements(rider);
|
|
43
|
-
}
|
|
44
|
-
async hasPendingRiderSettlements(riderId) {
|
|
45
|
-
return await this.service.hasPendingRiderSettlements(riderId);
|
|
46
|
-
}
|
|
47
|
-
async getLastRiderSettlement(riderId) {
|
|
48
|
-
return await this.service.getLastRiderSettlement(riderId);
|
|
49
|
-
}
|
|
50
|
-
async markRiderSettlementsAsPaid(riderId) {
|
|
51
|
-
return await this.service.markRiderSettlementsAsPaid(riderId);
|
|
52
|
-
}
|
|
53
38
|
};
|
|
54
39
|
exports.CashSettlementService = CashSettlementService;
|
|
55
40
|
exports.CashSettlementService = CashSettlementService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cashSettlementService.js","sourceRoot":"/","sources":["libraries/cash-settlement/cashSettlementService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAK1B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACb;IAApB,YAAoB,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAWhD,KAAK,CAAC,kBAAkB,CAC9B,MAAc,EACd,QAAgB,EAChB,SAAiB,EACjB,YAAoB,EAAE,EACtB,WAAmB,EAAE,EACrB,OAAgC,EAChC,QAAiB;QAEjB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAC3C,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,QAAQ,CACR,CAAC;IACH,CAAC;IAQM,KAAK,CAAC,qBAAqB,CAAC,YAAoB;IAEvD,CAAC;IAQM,KAAK,CAAC,cAAc,CAAC,MAAY;IAExC,CAAC;IAQM,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QAC9C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAQM,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAClD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAQM,KAAK,CAAC,qBAAqB,CAAC,SAAiB;QACnD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAQM,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QAC/C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;
|
|
1
|
+
{"version":3,"file":"cashSettlementService.js","sourceRoot":"/","sources":["libraries/cash-settlement/cashSettlementService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAK1B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACb;IAApB,YAAoB,OAA+B;QAA/B,YAAO,GAAP,OAAO,CAAwB;IAAG,CAAC;IAWhD,KAAK,CAAC,kBAAkB,CAC9B,MAAc,EACd,QAAgB,EAChB,SAAiB,EACjB,YAAoB,EAAE,EACtB,WAAmB,EAAE,EACrB,OAAgC,EAChC,QAAiB;QAEjB,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,kBAAkB,CAC3C,MAAM,EACN,QAAQ,EACR,SAAS,EACT,SAAS,EACT,QAAQ,EACR,OAAO,EACP,QAAQ,CACR,CAAC;IACH,CAAC;IAQM,KAAK,CAAC,qBAAqB,CAAC,YAAoB;IAEvD,CAAC;IAQM,KAAK,CAAC,cAAc,CAAC,MAAY;IAExC,CAAC;IAQM,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QAC9C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IACvD,CAAC;IAQM,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAClD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;IAQM,KAAK,CAAC,qBAAqB,CAAC,SAAiB;QACnD,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAQM,KAAK,CAAC,iBAAiB,CAAC,SAAiB;QAC/C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;IACxD,CAAC;CACD,CAAA;AA3FY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,gBAAO,GAAE;;GACG,qBAAqB,CA2FjC","sourcesContent":["import { Service } from 'typedi';\nimport { ICashSettlementService, ISettlementInfo } from './interfaces/ICashSettlement';\nimport { mongoose } from '@typegoose/typegoose';\n\n@Service()\nexport class CashSettlementService {\n\tconstructor(private service: ICashSettlementService) {}\n\n\t/**\n\t * Initiates a cash settlement process\n\t *\n\t * @param amount - The amount to be settled\n\t * @param currency - The currency of the amount\n\t * @param firstName - The first name of the settler\n\t * @param lastName - The last name of the settler\n\t * @returns Confirmation of the settlement initiation\n\t */\n\tpublic async initiateSettlement(\n\t\tamount: number,\n\t\tcurrency: string,\n\t\treference: string,\n\t\tfirstName: string = '',\n\t\tlastName: string = '',\n\t\triderId: mongoose.Types.ObjectId,\n\t\tlocation?: string\n\t): Promise<any> {\n\t\treturn await this.service.initiateSettlement(\n\t\t\tamount,\n\t\t\tcurrency,\n\t\t\treference,\n\t\t\tfirstName,\n\t\t\tlastName,\n\t\t\triderId,\n\t\t\tlocation\n\t\t);\n\t}\n\n\t/**\n\t * Checks the status of a cash settlement\n\t *\n\t * @param settlementId - The ID of the settlement to check\n\t * @returns Status of the settlement\n\t */\n\tpublic async checkSettlementStatus(settlementId: string): Promise<any> {\n\t\t// return await this.service.checkSettlementStatus(settlementId);\n\t}\n\n\t/**\n\t * Get a filtered list of cash settlements\n\t *\n\t * @param filter - Optional filter criteria for the settlements\n\t * @returns List of settlements matching the filter criteria\n\t */\n\tpublic async getSettlements(filter?: any): Promise<any> {\n\t\t// return await this.service.getSettlements(filter);\n\t}\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeSettlement(reference: string): Promise<any> {\n\t\treturn await this.service.revokeSettlement(reference);\n\t}\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param reference - The reference ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(reference: string): Promise<boolean> {\n\t\treturn await this.service.markSettlementAsPaid(reference);\n\t}\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\tpublic async hasPendingSettlements(reference: string): Promise<boolean> {\n\t\treturn await this.service.hasPendingSettlements(reference);\n\t}\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tpublic async getLastSettlement(reference: string): Promise<ISettlementInfo | null> {\n\t\treturn await this.service.getLastSettlement(reference);\n\t}\n}\n"]}
|
|
@@ -18,9 +18,4 @@ export interface ICashSettlementService {
|
|
|
18
18
|
markSettlementAsPaid(reference: string): Promise<boolean>;
|
|
19
19
|
hasPendingSettlements(reference: string): Promise<boolean>;
|
|
20
20
|
getLastSettlement(reference: string): Promise<ISettlementInfo | null>;
|
|
21
|
-
markSettlementAsPaidBySettlementId(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
22
|
-
revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
|
|
23
|
-
hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
24
|
-
getLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;
|
|
25
|
-
markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
26
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ICashSettlement.js","sourceRoot":"/","sources":["libraries/cash-settlement/interfaces/ICashSettlement.ts"],"names":[],"mappings":";;;AAEA,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC5B,0CAAqB,CAAA;IACrB,kCAAa,CAAA;IACb,wCAAmB,CAAA;AACpB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B","sourcesContent":["import { mongoose } from '@typegoose/typegoose';\n\nexport enum ISettlementStatus {\n\tNOT_PAID = 'not_paid',\n\tPAID = 'paid',\n\tREVOKED = 'revoked',\n}\n\nexport type ISettlementInfo = {\n\tamount: number;\n\tcurrency: string;\n\tstatus: ISettlementStatus;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n\treferenceNumber: string;\n};\n\nexport interface ICashSettlementService {\n\t/**\n\t * Initiates a cash settlement process\n\t *\n\t * @param amount - The amount to be settled\n\t * @param currency - The currency of the amount\n\t * @param reference - A unique reference for the settlement\n\t * @param firstName - The first name of the settler\n\t * @param lastName - The last name of the settler\n\t * @param location - Optional location of the settler\n\t * @returns Confirmation of the settlement initiation\n\t */\n\tinitiateSettlement(\n\t\tamount: number,\n\t\tcurrency: string,\n\t\treference: string,\n\t\tfirstName: string,\n\t\tlastName: string,\n\t\triderId: mongoose.Types.ObjectId,\n\t\tlocation?: string\n\t): Promise<boolean>;\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\trevokeSettlement(reference: string): Promise<boolean>;\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param reference - The reference ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tmarkSettlementAsPaid(reference: string): Promise<boolean>;\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\thasPendingSettlements(reference: string): Promise<boolean>;\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tgetLastSettlement(reference: string): Promise<ISettlementInfo | null>;\n
|
|
1
|
+
{"version":3,"file":"ICashSettlement.js","sourceRoot":"/","sources":["libraries/cash-settlement/interfaces/ICashSettlement.ts"],"names":[],"mappings":";;;AAEA,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC5B,0CAAqB,CAAA;IACrB,kCAAa,CAAA;IACb,wCAAmB,CAAA;AACpB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B","sourcesContent":["import { mongoose } from '@typegoose/typegoose';\n\nexport enum ISettlementStatus {\n\tNOT_PAID = 'not_paid',\n\tPAID = 'paid',\n\tREVOKED = 'revoked',\n}\n\nexport type ISettlementInfo = {\n\tamount: number;\n\tcurrency: string;\n\tstatus: ISettlementStatus;\n\tcreatedAt: Date;\n\tupdatedAt: Date;\n\treferenceNumber: string;\n};\n\nexport interface ICashSettlementService {\n\t/**\n\t * Initiates a cash settlement process\n\t *\n\t * @param amount - The amount to be settled\n\t * @param currency - The currency of the amount\n\t * @param reference - A unique reference for the settlement\n\t * @param firstName - The first name of the settler\n\t * @param lastName - The last name of the settler\n\t * @param location - Optional location of the settler\n\t * @returns Confirmation of the settlement initiation\n\t */\n\tinitiateSettlement(\n\t\tamount: number,\n\t\tcurrency: string,\n\t\treference: string,\n\t\tfirstName: string,\n\t\tlastName: string,\n\t\triderId: mongoose.Types.ObjectId,\n\t\tlocation?: string\n\t): Promise<boolean>;\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\trevokeSettlement(reference: string): Promise<boolean>;\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param reference - The reference ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tmarkSettlementAsPaid(reference: string): Promise<boolean>;\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\thasPendingSettlements(reference: string): Promise<boolean>;\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tgetLastSettlement(reference: string): Promise<ISettlementInfo | null>;\n}\n"]}
|
|
@@ -17,20 +17,13 @@ export declare class BOBService implements ICashSettlementService {
|
|
|
17
17
|
private BOB_PASSWORD;
|
|
18
18
|
private BOB_URL;
|
|
19
19
|
constructor(secrets: BOBSecrets);
|
|
20
|
-
private autoIncrementCRMCounter;
|
|
21
|
-
private convertNumberToCode;
|
|
22
20
|
initiateSettlement(amount: number, currency: string, reference: string, firstName: string, lastName: string, riderId: mongoose.Types.ObjectId, location?: string): Promise<boolean>;
|
|
23
21
|
private createBullMQJobForStatusCheck;
|
|
24
22
|
markSettlementAsPaid(reference: string): Promise<boolean>;
|
|
25
|
-
markSettlementAsPaidBySettlementId(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
26
|
-
markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
27
23
|
private settlePayment;
|
|
28
24
|
revokeSettlement(reference: string): Promise<boolean>;
|
|
29
|
-
revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
|
|
30
25
|
private removeTransfer;
|
|
31
26
|
hasPendingSettlements(reference: string): Promise<boolean>;
|
|
32
|
-
hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;
|
|
33
27
|
getLastSettlement(reference: string): Promise<ISettlementInfo | null>;
|
|
34
|
-
getLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;
|
|
35
28
|
private decompressResponse;
|
|
36
29
|
}
|
|
@@ -42,29 +42,10 @@ let BOBService = class BOBService {
|
|
|
42
42
|
this.riderModel = models_1.RiderModel;
|
|
43
43
|
this.financeSettlementModel = models_1.FinanceSettlementModel;
|
|
44
44
|
}
|
|
45
|
-
async autoIncrementCRMCounter() {
|
|
46
|
-
return await models_1.CounterModel.findOneAndUpdate({ counterType: enum_1.CounterType.CRM_NUMBER }, { $inc: { value: 1 } }, { new: true, upsert: true });
|
|
47
|
-
}
|
|
48
|
-
convertNumberToCode(num) {
|
|
49
|
-
const letters = 'abcdefghijklmnopqrstuvwxyz';
|
|
50
|
-
const lettersLength = letters.length;
|
|
51
|
-
const firstCharIndex = Math.floor(num / lettersLength) % lettersLength;
|
|
52
|
-
const secondCharIndex = num % lettersLength;
|
|
53
|
-
const digits = num % 100;
|
|
54
|
-
return digits.toString().padStart(2, '0') + letters[firstCharIndex] + letters[secondCharIndex];
|
|
55
|
-
}
|
|
56
45
|
async initiateSettlement(amount, currency, reference, firstName, lastName, riderId, location) {
|
|
57
46
|
if (amount > 20000000) {
|
|
58
47
|
(0, error_common_1.badRequestError)('Please provide a value between 0 and 20000000');
|
|
59
48
|
}
|
|
60
|
-
const crmCounter = await this.autoIncrementCRMCounter();
|
|
61
|
-
const crmNumber = this.convertNumberToCode(crmCounter.value);
|
|
62
|
-
if (!crmNumber) {
|
|
63
|
-
throw new server_1.TRPCError({
|
|
64
|
-
code: 'INTERNAL_SERVER_ERROR',
|
|
65
|
-
message: 'Failed to generate CRM number for BOB settlement.',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
49
|
const bobData = {
|
|
69
50
|
ChannelType: enum_1.BobChannelType.CO,
|
|
70
51
|
Credentials: {
|
|
@@ -74,7 +55,7 @@ let BOBService = class BOBService {
|
|
|
74
55
|
Model: enum_1.BobModel.C2B,
|
|
75
56
|
FirstName: firstName,
|
|
76
57
|
LastName: lastName,
|
|
77
|
-
CRMNumber:
|
|
58
|
+
CRMNumber: reference,
|
|
78
59
|
Amount: String(amount),
|
|
79
60
|
Currency: currency,
|
|
80
61
|
};
|
|
@@ -99,7 +80,7 @@ let BOBService = class BOBService {
|
|
|
99
80
|
const bobSettlement = await this.model.create({
|
|
100
81
|
amount: currency === 'USD' ? amount : 0,
|
|
101
82
|
secondaryAmount: currency === 'USD' ? 0 : amount,
|
|
102
|
-
crmNumber:
|
|
83
|
+
crmNumber: reference,
|
|
103
84
|
rider: riderId,
|
|
104
85
|
bobLocation: location,
|
|
105
86
|
status: enum_1.BobSettlementStatus.NOT_PAID,
|
|
@@ -107,7 +88,7 @@ let BOBService = class BOBService {
|
|
|
107
88
|
bobModel: enum_1.BobModel.C2B,
|
|
108
89
|
bobType: enum_1.BobType.INWARD,
|
|
109
90
|
});
|
|
110
|
-
await this.createBullMQJobForStatusCheck(
|
|
91
|
+
await this.createBullMQJobForStatusCheck(reference);
|
|
111
92
|
return true;
|
|
112
93
|
}
|
|
113
94
|
async createBullMQJobForStatusCheck(crmNumber) {
|
|
@@ -185,33 +166,6 @@ let BOBService = class BOBService {
|
|
|
185
166
|
await this.removeTransfer(reference);
|
|
186
167
|
return true;
|
|
187
168
|
}
|
|
188
|
-
async markSettlementAsPaidBySettlementId(settlementId) {
|
|
189
|
-
const settlement = await this.model.findOne({
|
|
190
|
-
_id: settlementId,
|
|
191
|
-
status: enum_1.BobSettlementStatus.NOT_PAID,
|
|
192
|
-
});
|
|
193
|
-
if (!settlement) {
|
|
194
|
-
console.error(`Settlement with ID ${settlementId} not found.`);
|
|
195
|
-
throw new server_1.TRPCError({
|
|
196
|
-
code: 'NOT_FOUND',
|
|
197
|
-
message: 'Settlement not found.',
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
await this.settlePayment(settlement.crmNumber, settlement);
|
|
201
|
-
await this.removeTransfer(settlement.crmNumber);
|
|
202
|
-
return true;
|
|
203
|
-
}
|
|
204
|
-
async markRiderSettlementsAsPaid(riderId) {
|
|
205
|
-
const settlements = await this.model.find({
|
|
206
|
-
rider: riderId,
|
|
207
|
-
status: enum_1.BobSettlementStatus.NOT_PAID,
|
|
208
|
-
});
|
|
209
|
-
for (const settlement of settlements) {
|
|
210
|
-
await this.settlePayment(settlement.crmNumber, settlement);
|
|
211
|
-
await this.removeTransfer(settlement.crmNumber);
|
|
212
|
-
}
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
169
|
async settlePayment(reference, settlement) {
|
|
216
170
|
await this.model.findOneAndUpdate({ crmNumber: reference, status: enum_1.BobSettlementStatus.NOT_PAID }, { status: enum_1.BobSettlementStatus.PAID }, { new: true, runValidators: true });
|
|
217
171
|
await this.financeSettlementModel.create({
|
|
@@ -259,19 +213,6 @@ let BOBService = class BOBService {
|
|
|
259
213
|
}, { new: true, runValidators: true });
|
|
260
214
|
return true;
|
|
261
215
|
}
|
|
262
|
-
async revokeRiderSettlements(rider) {
|
|
263
|
-
const settlements = await this.model.find({
|
|
264
|
-
rider: rider,
|
|
265
|
-
status: enum_1.BobSettlementStatus.NOT_PAID,
|
|
266
|
-
});
|
|
267
|
-
for (const settlement of settlements) {
|
|
268
|
-
await this.removeTransfer(settlement.crmNumber);
|
|
269
|
-
await this.model.findByIdAndUpdate(settlement._id, {
|
|
270
|
-
status: enum_1.BobSettlementStatus.REVOKED,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return true;
|
|
274
|
-
}
|
|
275
216
|
async removeTransfer(crmNumber) {
|
|
276
217
|
const bobData = {
|
|
277
218
|
ChannelType: enum_1.BobChannelType.CO,
|
|
@@ -311,13 +252,6 @@ let BOBService = class BOBService {
|
|
|
311
252
|
});
|
|
312
253
|
return pendingSettlements.length > 0;
|
|
313
254
|
}
|
|
314
|
-
async hasPendingRiderSettlements(riderId) {
|
|
315
|
-
const pendingSettlements = await this.model.find({
|
|
316
|
-
rider: riderId,
|
|
317
|
-
status: enum_1.BobSettlementStatus.NOT_PAID,
|
|
318
|
-
});
|
|
319
|
-
return pendingSettlements.length > 0;
|
|
320
|
-
}
|
|
321
255
|
async getLastSettlement(reference) {
|
|
322
256
|
const pendingSettlements = await this.model
|
|
323
257
|
.findOne({
|
|
@@ -335,23 +269,6 @@ let BOBService = class BOBService {
|
|
|
335
269
|
updatedAt: pendingSettlements.createdAt ?? new Date(),
|
|
336
270
|
};
|
|
337
271
|
}
|
|
338
|
-
async getLastRiderSettlement(rider) {
|
|
339
|
-
const lastSettlement = await this.model
|
|
340
|
-
.findOne({
|
|
341
|
-
rider: rider,
|
|
342
|
-
})
|
|
343
|
-
.sort({ createdAt: -1 });
|
|
344
|
-
if (!lastSettlement)
|
|
345
|
-
return null;
|
|
346
|
-
return {
|
|
347
|
-
amount: lastSettlement.amount || lastSettlement.secondaryAmount || 0,
|
|
348
|
-
currency: lastSettlement.amount ? 'USD' : 'LBP',
|
|
349
|
-
referenceNumber: lastSettlement.crmNumber,
|
|
350
|
-
status: (lastSettlement.status ?? enum_1.BobSettlementStatus.NOT_PAID),
|
|
351
|
-
createdAt: lastSettlement.createdAt ?? new Date(),
|
|
352
|
-
updatedAt: lastSettlement.updatedAt ?? new Date(),
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
272
|
async decompressResponse(response) {
|
|
356
273
|
return new Promise((resolve, reject) => {
|
|
357
274
|
const decodedBuffer = Buffer.from(response, 'base64');
|
|
@@ -1 +1 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AAC,CAAC;IACJ,CAAC;CACD,CAAA;AArgBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAqgBtB","sourcesContent":["import axios from 'axios';\nimport { ICashSettlementService, ISettlementInfo, ISettlementStatus } from '../interfaces/ICashSettlement';\nimport { SoftDeleteModel } from '../../mongo/plugins/soft-delete-plugin';\nimport {\n\tBOBFinance,\n\tBOBFinanceModel,\n\tCounter,\n\tCounterModel,\n\tFinanceSettlement,\n\tFinanceSettlementModel,\n\tRider,\n\tRiderModel,\n} from '../../mongo/models';\nimport { Service } from 'typedi';\nimport https from 'https';\nimport zlib from 'zlib';\nimport { TRPCError } from '@trpc/server';\nimport {\n\tAccountType,\n\tBobChannelType,\n\tBobModel,\n\tBobSettlementStatus,\n\tBobSettlementType,\n\tBobType,\n\tCounterType,\n\tSettlementType,\n} from '../../../utilities/enum';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport { getLibraries } from '../../..';\nimport { badRequestError } from '../../../utilities/error-common';\n\nexport type BOBSecrets = {\n\tBOB_USER_NAME: string;\n\tBOB_PASSWORD: string;\n\tBOB_URL: string;\n};\n\nexport enum BOBTransferStatus {\n\tNOT_PAID = 'NOT PAID',\n\tPAID = 'PAID',\n}\n\n@Service()\nexport class BOBService implements ICashSettlementService {\n\tprivate model: typeof BOBFinanceModel & SoftDeleteModel<BOBFinance>;\n\tprivate riderModel: typeof RiderModel & SoftDeleteModel<Rider>;\n\tprivate financeSettlementModel: typeof FinanceSettlementModel & SoftDeleteModel<FinanceSettlement>;\n\n\tprivate BOB_USER_NAME: string;\n\tprivate BOB_PASSWORD: string;\n\tprivate BOB_URL: string;\n\n\tconstructor(secrets: BOBSecrets) {\n\t\tthis.BOB_USER_NAME = secrets.BOB_USER_NAME;\n\t\tthis.BOB_PASSWORD = secrets.BOB_PASSWORD;\n\t\tthis.BOB_URL = secrets.BOB_URL;\n\n\t\tthis.model = BOBFinanceModel as typeof BOBFinanceModel & SoftDeleteModel<BOBFinance>;\n\t\tthis.riderModel = RiderModel as typeof RiderModel & SoftDeleteModel<Rider>;\n\t\tthis.financeSettlementModel = FinanceSettlementModel as typeof FinanceSettlementModel &\n\t\t\tSoftDeleteModel<FinanceSettlement>;\n\t}\n\n\tprivate async autoIncrementCRMCounter(): Promise<DocumentType<Counter>> {\n\t\treturn await CounterModel.findOneAndUpdate(\n\t\t\t{ counterType: CounterType.CRM_NUMBER },\n\t\t\t{ $inc: { value: 1 } },\n\t\t\t{ new: true, upsert: true }\n\t\t);\n\t}\n\n\tprivate convertNumberToCode(num: number): string {\n\t\t// convert a number to a code (e.g. 0 -> aa00)\n\t\tconst letters = 'abcdefghijklmnopqrstuvwxyz';\n\t\tconst lettersLength = letters.length;\n\n\t\tconst firstCharIndex = Math.floor(num / lettersLength) % lettersLength;\n\t\tconst secondCharIndex = num % lettersLength;\n\n\t\tconst digits = num % 100; // Ensures two digits (00 to 99)\n\t\treturn digits.toString().padStart(2, '0') + letters[firstCharIndex] + letters[secondCharIndex];\n\t}\n\n\t/**\n\t * Initiates a cash settlement process\n\t *\n\t * @param amount - The amount to be settled\n\t * @param currency - The currency of the amount\n\t * @param reference - A unique reference for the settlement\n\t * @param firstName - The first name of the settler\n\t * @param lastName - The last name of the settler\n\t * @param riderId - The ID of the rider associated with the settlement\n\t * @param location - Optional location of the settler\n\t * @returns Confirmation of the settlement initiation\n\t */\n\tpublic async initiateSettlement(\n\t\tamount: number,\n\t\tcurrency: string,\n\t\treference: string,\n\t\tfirstName: string,\n\t\tlastName: string,\n\t\triderId: mongoose.Types.ObjectId,\n\t\tlocation?: string\n\t): Promise<boolean> {\n\t\t// BOB cannot handle amount > 20000000\n\t\tif (amount > 20000000) {\n\t\t\tbadRequestError('Please provide a value between 0 and 20000000');\n\t\t}\n\n\t\tconst crmCounter = await this.autoIncrementCRMCounter();\n\t\tconst crmNumber = this.convertNumberToCode(crmCounter.value);\n\t\tif (!crmNumber) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to generate CRM number for BOB settlement.',\n\t\t\t});\n\t\t}\n\n\t\tconst bobData = {\n\t\t\tChannelType: BobChannelType.CO,\n\t\t\tCredentials: {\n\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t},\n\t\t\tModel: BobModel.C2B,\n\t\t\tFirstName: firstName,\n\t\t\tLastName: lastName,\n\t\t\tCRMNumber: crmNumber,\n\t\t\tAmount: String(amount),\n\t\t\tCurrency: currency,\n\t\t};\n\n\t\tconst { data } = await axios.post(`${this.BOB_URL}InsertTransferData`, bobData, {\n\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t});\n\n\t\tif (data.ErrorCode != 100) {\n\t\t\tconsole.error(`Error in BOB initiateSettlement: ${data.ErrorDescription}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t});\n\t\t}\n\n\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\tif (!responseObject || !responseObject.isSuccess) {\n\t\t\tconsole.error('Failed to initiate settlement in BOB');\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to initiate settlement in BOB.',\n\t\t\t});\n\t\t}\n\n\t\tconst bobSettlement = await this.model.create({\n\t\t\tamount: currency === 'USD' ? amount : 0,\n\t\t\tsecondaryAmount: currency === 'USD' ? 0 : amount,\n\t\t\tcrmNumber: crmNumber,\n\t\t\trider: riderId,\n\t\t\tbobLocation: location,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\tsettlementType: BobSettlementType.SETTLE_CASH,\n\t\t\tbobModel: BobModel.C2B,\n\t\t\tbobType: BobType.INWARD,\n\t\t});\n\n\t\tawait this.createBullMQJobForStatusCheck(crmNumber);\n\n\t\treturn true;\n\t}\n\n\tprivate async createBullMQJobForStatusCheck(crmNumber: string) {\n\t\tconst bullmq = getLibraries().getBullMQService();\n\t\tconst queueId = `bob-settlement-status-check-queue-crm-${crmNumber}`;\n\t\tconst queue = bullmq.createQueue(queueId);\n\t\tconst jobName = `bob-settlement-status-check-job-crm-${crmNumber}`;\n\t\tconst schedulerId = `bob-settlement-status-check-scheduler-crm-${crmNumber}`;\n\n\t\tawait queue.upsertJobScheduler(\n\t\t\tschedulerId,\n\t\t\t{ pattern: '* * * * *' },\n\t\t\t{ name: jobName, data: { crmNumber } }\n\t\t);\n\n\t\tconst worker = bullmq.createWorker(queueId, async (job: any) => {\n\t\t\tconsole.log(`🔥 [${new Date().toISOString()}] Job triggered:`, job.name, job.data);\n\n\t\t\tconst settlement = await this.model.findOne({\n\t\t\t\tcrmNumber: job.data.crmNumber,\n\t\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\t});\n\n\t\t\tif (!settlement) {\n\t\t\t\tconsole.log(`Settlement with CRM number ${job.data.crmNumber} not found.`);\n\t\t\t\tawait queue.removeJobScheduler(schedulerId);\n\t\t\t\tconsole.log(`Removed job scheduler: ${schedulerId}`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst bobData = {\n\t\t\t\tChannelType: BobChannelType.CO,\n\t\t\t\tCredentials: {\n\t\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t\t},\n\t\t\t\tModel: BobModel.C2B,\n\t\t\t\tCRMNumber: job.data.crmNumber,\n\t\t\t};\n\t\t\tconst { data } = await axios.post(`${this.BOB_URL}GetTransferStatus`, bobData, {\n\t\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t\t});\n\n\t\t\tif (data.ErrorCode != 100) {\n\t\t\t\tconsole.error(`Error in BOB getTransferStatus: ${data.ErrorDescription}`);\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\t\tif (!responseObject) {\n\t\t\t\tconsole.error('Failed to get settlement status in BOB');\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'Failed to get settlement status in BOB.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst hasUnpaidTransfer = responseObject.some(\n\t\t\t\t(item: any) => item.CRMNumber == crmNumber && item.Status == BOBTransferStatus.NOT_PAID\n\t\t\t);\n\n\t\t\tif (!hasUnpaidTransfer) {\n\t\t\t\tthis.settlePayment(job.data.crmNumber, settlement);\n\t\t\t}\n\n\t\t\tconsole.log(\n\t\t\t\t`🔥 [${new Date().toISOString()}] Settlement status for ${job.data.crmNumber}:`,\n\t\t\t\tresponseObject\n\t\t\t);\n\t\t});\n\n\t\tworker.on('completed', (job: any) => {\n\t\t\tconsole.log(`✅ Job completed: ${job.id}`);\n\t\t});\n\n\t\tworker.on('failed', (job: any, err: any) => {\n\t\t\tconsole.error(`❌ Job failed: ${job?.id} -`, err);\n\t\t});\n\t}\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param reference - The reference ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(reference: string): Promise<boolean> {\n\t\tconst settlement = await this.model.findOne({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with reference ${reference} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Settlement not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.settlePayment(reference, settlement);\n\n\t\tawait this.removeTransfer(reference); // Remove the transfer from BOB so future settlements with the same reference do not fail\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaidBySettlementId(settlementId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst settlement = await this.model.findOne({\n\t\t\t_id: settlementId,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with ID ${settlementId} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Settlement not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.settlePayment(settlement.crmNumber, settlement);\n\n\t\tawait this.removeTransfer(settlement.crmNumber); // Remove the transfer from BOB so future settlements with the same reference do not fail\n\n\t\treturn true;\n\t}\n\n\t// mark rider settlements as paid by rider id\n\tpublic async markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst settlements = await this.model.find({\n\t\t\trider: riderId,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tfor (const settlement of settlements) {\n\t\t\tawait this.settlePayment(settlement.crmNumber, settlement);\n\t\t\tawait this.removeTransfer(settlement.crmNumber); // Remove the transfer from BOB so future settlements with the same reference do not fail\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate async settlePayment(reference: string, settlement: DocumentType<BOBFinance>) {\n\t\tawait this.model.findOneAndUpdate(\n\t\t\t{ crmNumber: reference, status: BobSettlementStatus.NOT_PAID },\n\t\t\t{ status: BobSettlementStatus.PAID },\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\n\t\tawait this.financeSettlementModel.create({\n\t\t\tamount: settlement.amount,\n\t\t\tsecondaryAmount: settlement.secondaryAmount,\n\t\t\trider: settlement.rider,\n\t\t\tsettlementType: SettlementType.RIDER_SETTLE_CASH,\n\t\t\taccountType: AccountType.RIDER,\n\t\t});\n\n\t\tconst rider = await this.riderModel.findById(settlement.rider);\n\t\tif (!rider) {\n\t\t\tconsole.error(`Rider with ID ${settlement.rider} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Rider not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.riderModel.findByIdAndUpdate(\n\t\t\trider._id,\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tcashInHand: {\n\t\t\t\t\t\tamount: (rider.cashInHand?.amount || 0) - (settlement.amount || 0),\n\t\t\t\t\t\tsecondaryAmount: (rider.cashInHand?.secondaryAmount || 0) - (settlement.secondaryAmount || 0),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\t}\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeSettlement(reference: string): Promise<boolean> {\n\t\tconst settlement = await this.model.findOne({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with reference ${reference} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Settlement not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.removeTransfer(reference);\n\n\t\tconst result = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\tcrmNumber: reference,\n\t\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstatus: BobSettlementStatus.REVOKED,\n\t\t\t},\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\n\t\treturn true;\n\t}\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst settlements = await this.model.find({\n\t\t\trider: rider,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tfor (const settlement of settlements) {\n\t\t\tawait this.removeTransfer(settlement.crmNumber);\n\t\t\tawait this.model.findByIdAndUpdate(settlement._id, {\n\t\t\t\tstatus: BobSettlementStatus.REVOKED,\n\t\t\t});\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tprivate async removeTransfer(crmNumber: string) {\n\t\tconst bobData = {\n\t\t\tChannelType: BobChannelType.CO,\n\t\t\tCredentials: {\n\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t},\n\t\t\tModel: BobModel.C2B,\n\t\t\tCRMNumber: crmNumber,\n\t\t};\n\n\t\tconst { data } = await axios.post(`${this.BOB_URL}RemoveTransfer`, bobData, {\n\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t});\n\n\t\tif (data.ErrorCode == 213) {\n\t\t\t// Record does not exist\n\t\t\treturn;\n\t\t}\n\n\t\tif (data.ErrorCode != 100) {\n\t\t\tconsole.error(`Error in BOB removeTransfer: ${data.ErrorDescription}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t});\n\t\t}\n\n\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\tif (!responseObject || !responseObject.isSuccess) {\n\t\t\tconsole.error('Failed to remove transfer in BOB');\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to remove transfer in BOB.',\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\tpublic async hasPendingSettlements(reference: string): Promise<boolean> {\n\t\tconst pendingSettlements = await this.model.find({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\t\treturn pendingSettlements.length > 0;\n\t}\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param riderId - The ID of the rider to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\tpublic async hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst pendingSettlements = await this.model.find({\n\t\t\trider: riderId,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\t\treturn pendingSettlements.length > 0;\n\t}\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tpublic async getLastSettlement(reference: string): Promise<ISettlementInfo | null> {\n\t\tconst pendingSettlements = await this.model\n\t\t\t.findOne({\n\t\t\t\tcrmNumber: reference,\n\t\t\t})\n\t\t\t.sort({ createdAt: -1 });\n\n\t\tif (!pendingSettlements) return null;\n\n\t\treturn {\n\t\t\tamount: pendingSettlements.amount || pendingSettlements.secondaryAmount || 0,\n\t\t\tcurrency: pendingSettlements.amount ? 'USD' : 'LBP',\n\t\t\treferenceNumber: pendingSettlements.crmNumber,\n\t\t\tstatus: (pendingSettlements.status ?? BobSettlementStatus.NOT_PAID) as unknown as ISettlementStatus,\n\t\t\tcreatedAt: pendingSettlements.createdAt ?? new Date(),\n\t\t\tupdatedAt: pendingSettlements.createdAt ?? new Date(),\n\t\t};\n\t}\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param riderId - The ID of the rider to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tpublic async getLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null> {\n\t\tconst lastSettlement = await this.model\n\t\t\t.findOne({\n\t\t\t\trider: rider,\n\t\t\t})\n\t\t\t.sort({ createdAt: -1 });\n\n\t\tif (!lastSettlement) return null;\n\n\t\treturn {\n\t\t\tamount: lastSettlement.amount || lastSettlement.secondaryAmount || 0,\n\t\t\tcurrency: lastSettlement.amount ? 'USD' : 'LBP',\n\t\t\treferenceNumber: lastSettlement.crmNumber,\n\t\t\tstatus: (lastSettlement.status ?? BobSettlementStatus.NOT_PAID) as unknown as ISettlementStatus,\n\t\t\tcreatedAt: lastSettlement.createdAt ?? new Date(),\n\t\t\tupdatedAt: lastSettlement.updatedAt ?? new Date(),\n\t\t};\n\t}\n\n\tprivate async decompressResponse(response: string): Promise<any> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t// Step 1: Decode Base64\n\t\t\tconst decodedBuffer = Buffer.from(response, 'base64');\n\n\t\t\t// Step 2: Decompress GZIP\n\t\t\tzlib.gunzip(decodedBuffer, (err, decompressedBuffer) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tconsole.error('Error decompressing GZIP:', err);\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\t\tmessage: 'Failed to decompress data from BOB API.',\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// Step 3: Convert decompressed buffer to string\n\t\t\t\t\tconst decodedString = decompressedBuffer.toString('utf-8');\n\n\t\t\t\t\t// Step 4: Parse the JSON string to a JavaScript object\n\t\t\t\t\tconst responseObject = JSON.parse(decodedString);\n\n\t\t\t\t\tresolve(responseObject);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bob.js","sourceRoot":"/","sources":["libraries/cash-settlement/providers/bob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,+CAO4B;AAC5B,mCAAiC;AACjC,kDAA0B;AAC1B,gDAAwB;AACxB,yCAAyC;AACzC,kDAQiC;AAEjC,gCAAwC;AACxC,kEAAkE;AAQlE,IAAY,iBA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AAC;IACJ,CAAC;CACD,CAAA;AAjYY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAiYtB","sourcesContent":["import axios from 'axios';\nimport { ICashSettlementService, ISettlementInfo, ISettlementStatus } from '../interfaces/ICashSettlement';\nimport { SoftDeleteModel } from '../../mongo/plugins/soft-delete-plugin';\nimport {\n\tBOBFinance,\n\tBOBFinanceModel,\n\tFinanceSettlement,\n\tFinanceSettlementModel,\n\tRider,\n\tRiderModel,\n} from '../../mongo/models';\nimport { Service } from 'typedi';\nimport https from 'https';\nimport zlib from 'zlib';\nimport { TRPCError } from '@trpc/server';\nimport {\n\tAccountType,\n\tBobChannelType,\n\tBobModel,\n\tBobSettlementStatus,\n\tBobSettlementType,\n\tBobType,\n\tSettlementType,\n} from '../../../utilities/enum';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport { getLibraries } from '../../..';\nimport { badRequestError } from '../../../utilities/error-common';\n\nexport type BOBSecrets = {\n\tBOB_USER_NAME: string;\n\tBOB_PASSWORD: string;\n\tBOB_URL: string;\n};\n\nexport enum BOBTransferStatus {\n\tNOT_PAID = 'NOT PAID',\n\tPAID = 'PAID',\n}\n\n@Service()\nexport class BOBService implements ICashSettlementService {\n\tprivate model: typeof BOBFinanceModel & SoftDeleteModel<BOBFinance>;\n\tprivate riderModel: typeof RiderModel & SoftDeleteModel<Rider>;\n\tprivate financeSettlementModel: typeof FinanceSettlementModel & SoftDeleteModel<FinanceSettlement>;\n\n\tprivate BOB_USER_NAME: string;\n\tprivate BOB_PASSWORD: string;\n\tprivate BOB_URL: string;\n\n\tconstructor(secrets: BOBSecrets) {\n\t\tthis.BOB_USER_NAME = secrets.BOB_USER_NAME;\n\t\tthis.BOB_PASSWORD = secrets.BOB_PASSWORD;\n\t\tthis.BOB_URL = secrets.BOB_URL;\n\n\t\tthis.model = BOBFinanceModel as typeof BOBFinanceModel & SoftDeleteModel<BOBFinance>;\n\t\tthis.riderModel = RiderModel as typeof RiderModel & SoftDeleteModel<Rider>;\n\t\tthis.financeSettlementModel = FinanceSettlementModel as typeof FinanceSettlementModel &\n\t\t\tSoftDeleteModel<FinanceSettlement>;\n\t}\n\n\t/**\n\t * Initiates a cash settlement process\n\t *\n\t * @param amount - The amount to be settled\n\t * @param currency - The currency of the amount\n\t * @param reference - A unique reference for the settlement\n\t * @param firstName - The first name of the settler\n\t * @param lastName - The last name of the settler\n\t * @param riderId - The ID of the rider associated with the settlement\n\t * @param location - Optional location of the settler\n\t * @returns Confirmation of the settlement initiation\n\t */\n\tpublic async initiateSettlement(\n\t\tamount: number,\n\t\tcurrency: string,\n\t\treference: string,\n\t\tfirstName: string,\n\t\tlastName: string,\n\t\triderId: mongoose.Types.ObjectId,\n\t\tlocation?: string\n\t): Promise<boolean> {\n\t\t// BOB cannot handle amount > 20000000\n\t\tif (amount > 20000000) {\n\t\t\tbadRequestError('Please provide a value between 0 and 20000000');\n\t\t}\n\n\t\tconst bobData = {\n\t\t\tChannelType: BobChannelType.CO,\n\t\t\tCredentials: {\n\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t},\n\t\t\tModel: BobModel.C2B,\n\t\t\tFirstName: firstName,\n\t\t\tLastName: lastName,\n\t\t\tCRMNumber: reference,\n\t\t\tAmount: String(amount),\n\t\t\tCurrency: currency,\n\t\t};\n\n\t\tconst { data } = await axios.post(`${this.BOB_URL}InsertTransferData`, bobData, {\n\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t});\n\n\t\tif (data.ErrorCode != 100) {\n\t\t\tconsole.error(`Error in BOB initiateSettlement: ${data.ErrorDescription}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t});\n\t\t}\n\n\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\tif (!responseObject || !responseObject.isSuccess) {\n\t\t\tconsole.error('Failed to initiate settlement in BOB');\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to initiate settlement in BOB.',\n\t\t\t});\n\t\t}\n\n\t\tconst bobSettlement = await this.model.create({\n\t\t\tamount: currency === 'USD' ? amount : 0,\n\t\t\tsecondaryAmount: currency === 'USD' ? 0 : amount,\n\t\t\tcrmNumber: reference,\n\t\t\trider: riderId,\n\t\t\tbobLocation: location,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\tsettlementType: BobSettlementType.SETTLE_CASH,\n\t\t\tbobModel: BobModel.C2B,\n\t\t\tbobType: BobType.INWARD,\n\t\t});\n\n\t\tawait this.createBullMQJobForStatusCheck(reference);\n\n\t\treturn true;\n\t}\n\n\tprivate async createBullMQJobForStatusCheck(crmNumber: string) {\n\t\tconst bullmq = getLibraries().getBullMQService();\n\t\tconst queueId = `bob-settlement-status-check-queue-crm-${crmNumber}`;\n\t\tconst queue = bullmq.createQueue(queueId);\n\t\tconst jobName = `bob-settlement-status-check-job-crm-${crmNumber}`;\n\t\tconst schedulerId = `bob-settlement-status-check-scheduler-crm-${crmNumber}`;\n\n\t\tawait queue.upsertJobScheduler(\n\t\t\tschedulerId,\n\t\t\t{ pattern: '* * * * *' },\n\t\t\t{ name: jobName, data: { crmNumber } }\n\t\t);\n\n\t\tconst worker = bullmq.createWorker(queueId, async (job: any) => {\n\t\t\tconsole.log(`🔥 [${new Date().toISOString()}] Job triggered:`, job.name, job.data);\n\n\t\t\tconst settlement = await this.model.findOne({\n\t\t\t\tcrmNumber: job.data.crmNumber,\n\t\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\t});\n\n\t\t\tif (!settlement) {\n\t\t\t\tconsole.log(`Settlement with CRM number ${job.data.crmNumber} not found.`);\n\t\t\t\tawait queue.removeJobScheduler(schedulerId);\n\t\t\t\tconsole.log(`Removed job scheduler: ${schedulerId}`);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst bobData = {\n\t\t\t\tChannelType: BobChannelType.CO,\n\t\t\t\tCredentials: {\n\t\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t\t},\n\t\t\t\tModel: BobModel.C2B,\n\t\t\t\tCRMNumber: job.data.crmNumber,\n\t\t\t};\n\t\t\tconst { data } = await axios.post(`${this.BOB_URL}GetTransferStatus`, bobData, {\n\t\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t\t});\n\n\t\t\tif (data.ErrorCode != 100) {\n\t\t\t\tconsole.error(`Error in BOB getTransferStatus: ${data.ErrorDescription}`);\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\t\tif (!responseObject) {\n\t\t\t\tconsole.error('Failed to get settlement status in BOB');\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'Failed to get settlement status in BOB.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst hasUnpaidTransfer = responseObject.some(\n\t\t\t\t(item: any) => item.CRMNumber == crmNumber && item.Status == BOBTransferStatus.NOT_PAID\n\t\t\t);\n\n\t\t\tif (!hasUnpaidTransfer) {\n\t\t\t\tthis.settlePayment(job.data.crmNumber, settlement);\n\t\t\t}\n\n\t\t\tconsole.log(\n\t\t\t\t`🔥 [${new Date().toISOString()}] Settlement status for ${job.data.crmNumber}:`,\n\t\t\t\tresponseObject\n\t\t\t);\n\t\t});\n\n\t\tworker.on('completed', (job: any) => {\n\t\t\tconsole.log(`✅ Job completed: ${job.id}`);\n\t\t});\n\n\t\tworker.on('failed', (job: any, err: any) => {\n\t\t\tconsole.error(`❌ Job failed: ${job?.id} -`, err);\n\t\t});\n\t}\n\n\t/**\n\t * Mark a settlement as paid\n\t *\n\t * @param reference - The reference ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(reference: string): Promise<boolean> {\n\t\tconst settlement = await this.model.findOne({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with reference ${reference} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Settlement not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.settlePayment(reference, settlement);\n\n\t\tawait this.removeTransfer(reference); // Remove the transfer from BOB so future settlements with the same reference do not fail\n\n\t\treturn true;\n\t}\n\n\tprivate async settlePayment(reference: string, settlement: DocumentType<BOBFinance>) {\n\t\tawait this.model.findOneAndUpdate(\n\t\t\t{ crmNumber: reference, status: BobSettlementStatus.NOT_PAID },\n\t\t\t{ status: BobSettlementStatus.PAID },\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\n\t\tawait this.financeSettlementModel.create({\n\t\t\tamount: settlement.amount,\n\t\t\tsecondaryAmount: settlement.secondaryAmount,\n\t\t\trider: settlement.rider,\n\t\t\tsettlementType: SettlementType.RIDER_SETTLE_CASH,\n\t\t\taccountType: AccountType.RIDER,\n\t\t});\n\n\t\tconst rider = await this.riderModel.findById(settlement.rider);\n\t\tif (!rider) {\n\t\t\tconsole.error(`Rider with ID ${settlement.rider} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Rider not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.riderModel.findByIdAndUpdate(\n\t\t\trider._id,\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tcashInHand: {\n\t\t\t\t\t\tamount: (rider.cashInHand?.amount || 0) - (settlement.amount || 0),\n\t\t\t\t\t\tsecondaryAmount: (rider.cashInHand?.secondaryAmount || 0) - (settlement.secondaryAmount || 0),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\t}\n\n\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param reference - The reference ID of the settlement to revoke\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeSettlement(reference: string): Promise<boolean> {\n\t\tconst settlement = await this.model.findOne({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with reference ${reference} not found.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Settlement not found.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.removeTransfer(reference);\n\n\t\tconst result = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\tcrmNumber: reference,\n\t\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t\t},\n\t\t\t{\n\t\t\t\tstatus: BobSettlementStatus.REVOKED,\n\t\t\t},\n\t\t\t{ new: true, runValidators: true }\n\t\t);\n\n\t\treturn true;\n\t}\n\n\tprivate async removeTransfer(crmNumber: string) {\n\t\tconst bobData = {\n\t\t\tChannelType: BobChannelType.CO,\n\t\t\tCredentials: {\n\t\t\t\tUser: this.BOB_USER_NAME,\n\t\t\t\tPassword: this.BOB_PASSWORD,\n\t\t\t},\n\t\t\tModel: BobModel.C2B,\n\t\t\tCRMNumber: crmNumber,\n\t\t};\n\n\t\tconst { data } = await axios.post(`${this.BOB_URL}RemoveTransfer`, bobData, {\n\t\t\thttpsAgent: new https.Agent({ rejectUnauthorized: false }),\n\t\t});\n\n\t\tif (data.ErrorCode == 213) {\n\t\t\t// Record does not exist\n\t\t\treturn;\n\t\t}\n\n\t\tif (data.ErrorCode != 100) {\n\t\t\tconsole.error(`Error in BOB removeTransfer: ${data.ErrorDescription}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to post data to BOB API.',\n\t\t\t});\n\t\t}\n\n\t\tconst responseObject = await this.decompressResponse(data.Response);\n\n\t\tif (!responseObject || !responseObject.isSuccess) {\n\t\t\tconsole.error('Failed to remove transfer in BOB');\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to remove transfer in BOB.',\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are pending settlements\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns true if there are pending settlements, false otherwise\n\t */\n\tpublic async hasPendingSettlements(reference: string): Promise<boolean> {\n\t\tconst pendingSettlements = await this.model.find({\n\t\t\tcrmNumber: reference,\n\t\t\tstatus: BobSettlementStatus.NOT_PAID,\n\t\t});\n\t\treturn pendingSettlements.length > 0;\n\t}\n\n\t/**\n\t * Get latest settlement info\n\t *\n\t * @param reference - The reference ID of the settlement to check\n\t * @returns the latest settlement if it exists, null otherwise\n\t */\n\tpublic async getLastSettlement(reference: string): Promise<ISettlementInfo | null> {\n\t\tconst pendingSettlements = await this.model\n\t\t\t.findOne({\n\t\t\t\tcrmNumber: reference,\n\t\t\t})\n\t\t\t.sort({ createdAt: -1 });\n\n\t\tif (!pendingSettlements) return null;\n\n\t\treturn {\n\t\t\tamount: pendingSettlements.amount || pendingSettlements.secondaryAmount || 0,\n\t\t\tcurrency: pendingSettlements.amount ? 'USD' : 'LBP',\n\t\t\treferenceNumber: pendingSettlements.crmNumber,\n\t\t\tstatus: (pendingSettlements.status ?? BobSettlementStatus.NOT_PAID) as unknown as ISettlementStatus,\n\t\t\tcreatedAt: pendingSettlements.createdAt ?? new Date(),\n\t\t\tupdatedAt: pendingSettlements.createdAt ?? new Date(),\n\t\t};\n\t}\n\n\tprivate async decompressResponse(response: string): Promise<any> {\n\t\treturn new Promise((resolve, reject) => {\n\t\t\t// Step 1: Decode Base64\n\t\t\tconst decodedBuffer = Buffer.from(response, 'base64');\n\n\t\t\t// Step 2: Decompress GZIP\n\t\t\tzlib.gunzip(decodedBuffer, (err, decompressedBuffer) => {\n\t\t\t\tif (err) {\n\t\t\t\t\tconsole.error('Error decompressing GZIP:', err);\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\t\tmessage: 'Failed to decompress data from BOB API.',\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\t// Step 3: Convert decompressed buffer to string\n\t\t\t\t\tconst decodedString = decompressedBuffer.toString('utf-8');\n\n\t\t\t\t\t// Step 4: Parse the JSON string to a JavaScript object\n\t\t\t\t\tconst responseObject = JSON.parse(decodedString);\n\n\t\t\t\t\tresolve(responseObject);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n"]}
|
|
@@ -34,10 +34,20 @@ let FCMService = class FCMService {
|
|
|
34
34
|
}
|
|
35
35
|
buildMessage(payload, batchTokens) {
|
|
36
36
|
const isInvisible = payload.invisible === true;
|
|
37
|
+
const channelId = payload.sound ? 'order_alert' : 'default';
|
|
37
38
|
const message = {
|
|
38
|
-
data: payload.data
|
|
39
|
+
data: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },
|
|
40
|
+
notification: {
|
|
41
|
+
title: payload.title,
|
|
42
|
+
body: payload.body,
|
|
43
|
+
},
|
|
39
44
|
tokens: batchTokens,
|
|
40
|
-
android: {
|
|
45
|
+
android: {
|
|
46
|
+
priority: 'high',
|
|
47
|
+
notification: {
|
|
48
|
+
channelId: 'silent',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
41
51
|
apns: {
|
|
42
52
|
payload: {
|
|
43
53
|
aps: {
|
|
@@ -45,20 +55,11 @@ let FCMService = class FCMService {
|
|
|
45
55
|
contentAvailable: true,
|
|
46
56
|
},
|
|
47
57
|
},
|
|
58
|
+
headers: {
|
|
59
|
+
'apns-push-type': 'background',
|
|
60
|
+
},
|
|
48
61
|
},
|
|
49
62
|
};
|
|
50
|
-
if (!isInvisible) {
|
|
51
|
-
message.notification = {
|
|
52
|
-
title: payload.title,
|
|
53
|
-
body: payload.body,
|
|
54
|
-
};
|
|
55
|
-
message.android = {
|
|
56
|
-
priority: 'high',
|
|
57
|
-
notification: {
|
|
58
|
-
channelId: payload.sound ? 'android_Push_Notification_Channel_1' : 'default',
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
63
|
return message;
|
|
63
64
|
}
|
|
64
65
|
async sendNotification(payload, tokens) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fcmService.js","sourceRoot":"/","sources":["libraries/firebase/fcmService.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,mDAA2C;AAC3C,6BAAqC;AACrC,mCAAiC;AAWpB,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AACvC,QAAA,kBAAkB,GAAG,mBAAmB,CAAC;AACzC,QAAA,iBAAiB,GAAG,kBAAkB,CAAC;AAG7C,IAAM,UAAU,GAAhB,MAAM,UAAU;;IACd,SAAS,CAAuB;IAChC,MAAM,CAAU,SAAS,GAAG,GAAG,CAAC;IAExC,YAAY,GAAS;QACpB,MAAM,WAAW,GAAG,GAAG,IAAI,IAAA,gBAAY,GAAE,CAAC,kBAAkB,EAAE,CAAC,QAAQ,CAAC;QACxE,IAAI,CAAC,SAAS,GAAG,IAAA,0BAAS,EAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAKO,UAAU,CAAI,GAAQ,EAAE,IAAY;QAC3C,MAAM,MAAM,GAAU,EAAE,CAAC;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE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,gBAAO,GAAE;;GACG,UAAU,CAmHtB","sourcesContent":["import { messaging } from 'firebase-admin';\nimport { getLibraries } from '../..';\nimport { Service } from 'typedi';\nimport { App } from 'firebase-admin/app';\n\nexport interface FCMNotificationPayload {\n\ttitle?: string;\n\tbody?: string;\n\tdata?: Record<string, string>;\n\tsound?: string;\n\tinvisible?: boolean;\n}\n\nexport const FCMServiceForUser = 'fcm.service.user';\nexport const FCMServiceForRider = 'fcm.service.rider';\nexport const FCMServiceForShop = 'fcm.service.shop';\n\n@Service()\nexport class FCMService {\n\tprivate messaging!: messaging.Messaging;\n\tprivate static readonly MAX_BATCH = 500;\n\n\tconstructor(app?: App) {\n\t\tconst firebaseApp = app ?? getLibraries().getFirebaseService().superApp;\n\t\tthis.messaging = messaging(firebaseApp);\n\t}\n\n\t/**\n\t * Split array into chunks of fixed size\n\t */\n\tprivate chunkArray<T>(arr: T[], size: number): T[][] {\n\t\tconst chunks: T[][] = [];\n\t\tfor (let i = 0; i < arr.length; i += size) {\n\t\t\tchunks.push(arr.slice(i, i + size));\n\t\t}\n\t\treturn chunks;\n\t}\n\n\t/**\n\t * Build multicast message safely\n\t */\n\tprivate buildMessage(payload: FCMNotificationPayload, batchTokens: string[]): messaging.MulticastMessage {\n\t\tconst isInvisible = payload.invisible === true;\n\t\tconst channelId = payload.sound ? 'order_alert' : 'default';\n\n\t\tconst message: messaging.MulticastMessage = {\n\t\t\tdata: { ...payload.data, channelId: isInvisible ? 'silent' : channelId },\n\t\t\tnotification: {\n\t\t\t\ttitle: payload.title,\n\t\t\t\tbody: payload.body,\n\t\t\t},\n\t\t\ttokens: batchTokens,\n\t\t\tandroid: {\n\t\t\t\tpriority: 'high',\n\t\t\t\tnotification: {\n\t\t\t\t\tchannelId: 'silent',\n\t\t\t\t},\n\t\t\t},\n\t\t\tapns: {\n\t\t\t\tpayload: {\n\t\t\t\t\taps: {\n\t\t\t\t\t\tsound: payload.sound || 'default',\n\t\t\t\t\t\tcontentAvailable: true,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\theaders: {\n\t\t\t\t\t'apns-push-type': 'background',\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\n\t\treturn message;\n\t}\n\n\t/**\n\t * Sends a push notification (visible or invisible) to multiple device tokens\n\t * @param payload - Notification title, body, and optional data\n\t * @param tokens - FCM device tokens\n\t * @returns Object containing success and invalid tokens\n\t */\n\tasync sendNotification(\n\t\tpayload: FCMNotificationPayload,\n\t\ttokens: string[]\n\t): Promise<{ successTokens: string[]; failedTokens: string[] }> {\n\t\tif (!tokens.length) return { successTokens: [], failedTokens: [] };\n\n\t\tconst tokenChunks = this.chunkArray(tokens, FCMService.MAX_BATCH);\n\n\t\tlet successTokens: string[] = [];\n\t\tlet failedTokens: string[] = [];\n\n\t\ttry {\n\t\t\t// Parallel batch sending (safe & fast)\n\t\t\tconst results = await Promise.all(\n\t\t\t\ttokenChunks.map(async chunk => {\n\t\t\t\t\tconst message = this.buildMessage(payload, chunk);\n\t\t\t\t\tconst response = await this.messaging.sendEachForMulticast(message);\n\n\t\t\t\t\tconst batchSuccess: string[] = [];\n\t\t\t\t\tconst batchFailed: string[] = [];\n\n\t\t\t\t\tresponse.responses.forEach((resp, idx) => {\n\t\t\t\t\t\tif (resp.success) {\n\t\t\t\t\t\t\tbatchSuccess.push(chunk[idx]);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst errorCode = resp.error?.code;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\terrorCode === 'messaging/invalid-argument' ||\n\t\t\t\t\t\t\t\terrorCode === 'messaging/registration-token-not-registered'\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tbatchFailed.push(chunk[idx]);\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconsole.warn(`FCM Error for token ${chunk[idx]}:`, resp.error?.message);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\treturn { batchSuccess, batchFailed };\n\t\t\t\t})\n\t\t\t);\n\n\t\t\tfor (const r of results) {\n\t\t\t\tsuccessTokens.push(...r.batchSuccess);\n\t\t\t\tfailedTokens.push(...r.batchFailed);\n\t\t\t}\n\n\t\t\treturn { successTokens, failedTokens };\n\t\t} catch (err) {\n\t\t\tconsole.error('FCM sendNotification error:', err);\n\t\t\tthrow err;\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ref } from '@typegoose/typegoose';
|
|
2
2
|
import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
|
|
3
|
-
import { BannerClickType, BannerLinkType, BannerUserType, Status, UserAppSectionItemType
|
|
3
|
+
import { BannerClickType, BannerLinkType, BannerUserType, Status, UserAppSectionItemType } from '../../../utilities/enum';
|
|
4
4
|
import { Shop } from './shop.model';
|
|
5
5
|
import { Product } from './product.model';
|
|
6
6
|
import { Zone } from './zone.model';
|
|
@@ -19,6 +19,5 @@ export declare class Banner extends TimeStamps {
|
|
|
19
19
|
shop?: Ref<Shop>;
|
|
20
20
|
product?: Ref<Product>;
|
|
21
21
|
listContainer?: Ref<ListContainer>;
|
|
22
|
-
section?: UserAppSectionType;
|
|
23
22
|
sortingOrder?: number;
|
|
24
23
|
}
|
|
@@ -33,7 +33,6 @@ let Banner = class Banner extends defaultClasses_1.TimeStamps {
|
|
|
33
33
|
shop;
|
|
34
34
|
product;
|
|
35
35
|
listContainer;
|
|
36
|
-
section;
|
|
37
36
|
sortingOrder;
|
|
38
37
|
};
|
|
39
38
|
exports.Banner = Banner;
|
|
@@ -89,10 +88,6 @@ __decorate([
|
|
|
89
88
|
(0, typegoose_1.prop)({ ref: () => list_container_model_1.ListContainer }),
|
|
90
89
|
__metadata("design:type", Object)
|
|
91
90
|
], Banner.prototype, "listContainer", void 0);
|
|
92
|
-
__decorate([
|
|
93
|
-
(0, typegoose_1.prop)({ type: String, enum: enum_1.UserAppSectionType }),
|
|
94
|
-
__metadata("design:type", String)
|
|
95
|
-
], Banner.prototype, "section", void 0);
|
|
96
91
|
__decorate([
|
|
97
92
|
(0, typegoose_1.prop)({ type: Number }),
|
|
98
93
|
__metadata("design:type", Number)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"banner.model.js","sourceRoot":"/","sources":["libraries/mongo/models/banner.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,
|
|
1
|
+
{"version":3,"file":"banner.model.js","sourceRoot":"/","sources":["libraries/mongo/models/banner.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2E;AAC3E,4EAAqE;AACrE,kDAOiC;AACjC,6CAAoC;AACpC,mDAA0C;AAC1C,6CAAoC;AACpC,iEAAuD;AACvD,wBAAgC;AAEhC,0EAG0C;AAcnC,IAAM,MAAM,GAAZ,MAAM,MAAO,SAAQ,2BAAU;IAE9B,KAAK,CAAU;IAGf,KAAK,CAAU;IAGf,QAAQ,CAA0B;IAGlC,MAAM,CAAU;IAGhB,UAAU,CAAkB;IAG5B,KAAK,CAAe;IAGpB,WAAW,CAAW;IAGtB,SAAS,CAAmB;IAG5B,QAAQ,CAAkB;IAG1B,IAAI,CAAU;IAGd,IAAI,CAAa;IAGjB,OAAO,CAAgB;IAGvB,aAAa,CAAsB;IAGnC,YAAY,CAAU;CAC7B,CAAA;AA1CY,wBAAM;AAEX;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;;qCAC5C;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;qCACjB;AAGf;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,6BAAsB,EAAE,CAAC;;wCAC5B;AAGlC;IADN,I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AC;IAC1D,IAAA,eAAG,EAAS,MAAM,EAAE,KAAK,WAAW,IAAI;QACxC,MAAM,uDAAiC,CAAC,IAAI,CAAC,IAAI,EAAE,cAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAE7F,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;IACD,IAAA,eAAG,EAAS,kBAAkB,EAAE,KAAK,WAAqC,IAAI;QAC9E,MAAM,yDAAmC,CAAC,IAAI,CAAC,IAAI,EAAE,cAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAEhF,IAAI,EAAE,CAAC;IACR,CAAC,CAAC;IACD,IAAA,iBAAK,EAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAuB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;GACvE,MAAM,CA0ClB","sourcesContent":["import { index, modelOptions, pre, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport {\n\tBannerClickType,\n\tBannerLinkType,\n\tBannerUserType,\n\tItemType,\n\tStatus,\n\tUserAppSectionItemType,\n} from '../../../utilities/enum';\nimport { Shop } from './shop.model';\nimport { Product } from './product.model';\nimport { Zone } from './zone.model';\nimport { ListContainer } from './list-container.model';\nimport { BannerModel } from '.';\nimport { Query } from 'mongoose';\nimport {\n\thandlePreSaveForSortingWithStatus,\n\thandlePreUpdateForSortingWithStatus,\n} from '../utilities/sorting-order.hooks';\n\n@modelOptions({ schemaOptions: { collection: 'banners' } })\n@pre<Banner>('save', async function (next) {\n\tawait handlePreSaveForSortingWithStatus.call(this, BannerModel, { itemType: this.itemType });\n\n\tnext();\n})\n@pre<Banner>('findOneAndUpdate', async function (this: Query<any, Banner>, next) {\n\tawait handlePreUpdateForSortingWithStatus.call(this, BannerModel, ['itemType']);\n\n\tnext();\n})\n@index({ title: 1 }, { unique: true, partialFilterExpression: { deletedAt: null } })\nexport class Banner extends TimeStamps {\n\t@prop({ required: true, type: String, trim: true, maxlength: 50 })\n\tpublic title!: string;\n\n\t@prop({ required: true, type: String })\n\tpublic image!: string;\n\n\t@prop({ required: true, type: String, enum: UserAppSectionItemType })\n\tpublic itemType!: UserAppSectionItemType;\n\n\t@prop({ type: String, enum: Status, default: Status.ACTIVE })\n\tpublic status?: Status;\n\n\t@prop({ type: String, enum: BannerUserType, default: BannerUserType.ALL })\n\tpublic visibility?: BannerUserType;\n\n\t@prop({ ref: () => Zone, default: [] })\n\tpublic zones?: Ref<Zone>[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isClickable?: boolean;\n\n\t@prop({ type: String, enum: BannerClickType })\n\tpublic clickType?: BannerClickType;\n\n\t@prop({ type: String, enum: BannerLinkType })\n\tpublic linkType?: BannerLinkType;\n\n\t@prop({ type: String, trim: true })\n\tpublic link?: string;\n\n\t@prop({ ref: () => Shop })\n\tpublic shop?: Ref<Shop>;\n\n\t@prop({ ref: () => Product })\n\tpublic product?: Ref<Product>;\n\n\t@prop({ ref: () => ListContainer })\n\tpublic listContainer?: Ref<ListContainer>;\n\n\t@prop({ type: Number })\n\tpublic sortingOrder?: number;\n}\n"]}
|
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
req: import("http").IncomingMessage;
|
|
9
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
9
|
tokenType: TokenType | undefined;
|
|
11
10
|
entity: import("../context").EntityContext | undefined;
|
|
11
|
+
req: import("http").IncomingMessage;
|
|
12
12
|
requestId: string | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
|
@@ -4,10 +4,10 @@ interface RoleProtectedOptions {
|
|
|
4
4
|
allowedRoles: string[];
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
|
-
req: import("http").IncomingMessage;
|
|
8
7
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
8
|
tokenType: import("../../auth").TokenType | undefined;
|
|
10
9
|
entity: import("../context").EntityContext | undefined;
|
|
10
|
+
req: import("http").IncomingMessage;
|
|
11
11
|
requestId: string | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
13
13
|
tokenRenewed: boolean | undefined;
|
|
@@ -3,10 +3,10 @@ interface PhoneVerifiedOptions {
|
|
|
3
3
|
entityTypes: AuthEntityType[];
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
|
-
req: import("http").IncomingMessage;
|
|
7
6
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
7
|
tokenType: import("../../auth").TokenType | undefined;
|
|
9
8
|
entity: import("../context").EntityContext | undefined;
|
|
9
|
+
req: import("http").IncomingMessage;
|
|
10
10
|
requestId: string | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
12
12
|
tokenRenewed: boolean | undefined;
|
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
-
req: import("http").IncomingMessage;
|
|
9
8
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
9
|
tokenType: TokenType | undefined;
|
|
11
10
|
entity: import("../context").EntityContext | undefined;
|
|
11
|
+
req: import("http").IncomingMessage;
|
|
12
12
|
requestId: string | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -358,8 +358,7 @@ export declare enum BannerClickType {
|
|
|
358
358
|
LINK = "link",
|
|
359
359
|
SHOP = "shop",
|
|
360
360
|
PRODUCT = "product",
|
|
361
|
-
LIST_CONTAINER = "list_container"
|
|
362
|
-
SECTION = "section"
|
|
361
|
+
LIST_CONTAINER = "list_container"
|
|
363
362
|
}
|
|
364
363
|
export declare enum BannerLinkType {
|
|
365
364
|
URL = "url",
|