@lyxa.ai/core 1.3.225 → 1.3.227

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.
@@ -13,5 +13,4 @@ export declare class CashSettlementService {
13
13
  revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
14
14
  hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;
15
15
  getLastRiderSettlement(riderId: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;
16
- markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
17
16
  }
@@ -44,9 +44,6 @@ let CashSettlementService = class CashSettlementService {
44
44
  async getLastRiderSettlement(riderId) {
45
45
  return await this.service.getLastRiderSettlement(riderId);
46
46
  }
47
- async markRiderSettlementsAsPaid(riderId) {
48
- return await this.service.markRiderSettlementsAsPaid(riderId);
49
- }
50
47
  };
51
48
  exports.CashSettlementService = CashSettlementService;
52
49
  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,YAAqC;QACtE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAC9D,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;IAQM,KAAK,CAAC,sBAAsB,CAAC,KAA8B;QACjE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;IACzD,CAAC;IAQM,KAAK,CAAC,0BAA0B,CAAC,OAAgC;QACvE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;IAQM,KAAK,CAAC,sBAAsB,CAAC,OAAgC;QACnE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAQM,KAAK,CAAC,0BAA0B,CAAC,OAAgC;QACvE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;IAC/D,CAAC;CACD,CAAA;AAnIY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,gBAAO,GAAE;;GACG,qBAAqB,CAmIjC","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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\treturn await this.service.markSettlementAsPaid(settlementId);\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\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param riderId - The ID of the rider whose settlements are to be revoked\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean> {\n\t\treturn await this.service.revokeRiderSettlements(rider);\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\treturn await this.service.hasPendingRiderSettlements(riderId);\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(riderId: mongoose.Types.ObjectId): Promise<ISettlementInfo | null> {\n\t\treturn await this.service.getLastRiderSettlement(riderId);\n\t}\n\n\t/**\n\t * Mark all settlements for a rider as paid\n\t *\n\t * @param riderId - The ID of the rider whose settlements are to be marked as paid\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\treturn await this.service.markRiderSettlementsAsPaid(riderId);\n\t}\n}\n"]}
1
+ {"version":3,"file":"cashSettlementService.js","sourceRoot":"/","sources":["libraries/cash-settlement/cashSettlementService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAK1B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IACb;IA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sBAAsB,CAAC,OAAgC;QACnE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;CACD,CAAA;AAzHY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,gBAAO,GAAE;;GACG,qBAAqB,CAyHjC","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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\treturn await this.service.markSettlementAsPaid(settlementId);\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\t/**\n\t * Revokes a cash settlement\n\t *\n\t * @param riderId - The ID of the rider whose settlements are to be revoked\n\t * @returns Confirmation of the revocation\n\t */\n\tpublic async revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean> {\n\t\treturn await this.service.revokeRiderSettlements(rider);\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\treturn await this.service.hasPendingRiderSettlements(riderId);\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(riderId: mongoose.Types.ObjectId): Promise<ISettlementInfo | null> {\n\t\treturn await this.service.getLastRiderSettlement(riderId);\n\t}\n}\n"]}
@@ -21,5 +21,4 @@ export interface ICashSettlementService {
21
21
  revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
22
22
  hasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;
23
23
  getLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;
24
- markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
25
24
  }
@@ -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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tmarkSettlementAsPaid(settlementId: mongoose.Types.ObjectId): 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\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\trevokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;\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\thasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;\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\tgetLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;\n\n\t/**\n\t * Mark all settlements for a rider as paid\n\t *\n\t * @param riderId - The ID of the rider whose settlements are to be marked as paid\n\t * @returns Confirmation of the update\n\t */\n\tmarkRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;\n}\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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tmarkSettlementAsPaid(settlementId: mongoose.Types.ObjectId): 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\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\trevokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;\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\thasPendingRiderSettlements(riderId: mongoose.Types.ObjectId): Promise<boolean>;\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\tgetLastRiderSettlement(rider: mongoose.Types.ObjectId): Promise<ISettlementInfo | null>;\n}\n"]}
@@ -22,8 +22,6 @@ export declare class BOBService implements ICashSettlementService {
22
22
  initiateSettlement(amount: number, currency: string, reference: string, firstName: string, lastName: string, riderId: mongoose.Types.ObjectId, location?: string): Promise<boolean>;
23
23
  private createBullMQJobForStatusCheck;
24
24
  markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
25
- markSettlementAsPaidBySettlementId(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
26
- markRiderSettlementsAsPaid(riderId: mongoose.Types.ObjectId): Promise<boolean>;
27
25
  private settlePayment;
28
26
  revokeSettlement(reference: string): Promise<boolean>;
29
27
  revokeRiderSettlements(rider: mongoose.Types.ObjectId): Promise<boolean>;
@@ -191,33 +191,6 @@ let BOBService = class BOBService {
191
191
  }
192
192
  return true;
193
193
  }
194
- async markSettlementAsPaidBySettlementId(settlementId) {
195
- const settlement = await this.model.findOne({
196
- _id: settlementId,
197
- status: enum_1.BobSettlementStatus.NOT_PAID,
198
- });
199
- if (!settlement) {
200
- console.error(`Settlement with ID ${settlementId} not found.`);
201
- throw new server_1.TRPCError({
202
- code: 'NOT_FOUND',
203
- message: 'Settlement not found.',
204
- });
205
- }
206
- await this.settlePayment(settlement);
207
- await this.removeTransfer(settlement.crmNumber);
208
- return true;
209
- }
210
- async markRiderSettlementsAsPaid(riderId) {
211
- const settlements = await this.model.find({
212
- rider: riderId,
213
- status: enum_1.BobSettlementStatus.NOT_PAID,
214
- });
215
- for (const settlement of settlements) {
216
- await this.settlePayment(settlement);
217
- await this.removeTransfer(settlement.crmNumber);
218
- }
219
- return true;
220
- }
221
194
  async settlePayment(settlement) {
222
195
  await this.model.findByIdAndUpdate(settlement._id, { status: enum_1.BobSettlementStatus.PAID }, { new: true, runValidators: true });
223
196
  await this.financeSettlementModel.create({
@@ -270,6 +243,9 @@ let BOBService = class BOBService {
270
243
  rider: rider,
271
244
  status: enum_1.BobSettlementStatus.NOT_PAID,
272
245
  });
246
+ if (!settlements.length) {
247
+ (0, error_common_1.notFoundError)('No unpaid settlements found.');
248
+ }
273
249
  for (const settlement of settlements) {
274
250
  await this.removeTransfer(settlement.crmNumber);
275
251
  await this.model.findByIdAndUpdate(settlement._id, {
@@ -1 +1 @@
1
- {"version":3,"file":"bob.js","sourceRoot":"/","sources":["libraries/cash-settlement/providers/bob.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAG1B,+CAS4B;AAC5B,mCAAiC;AACjC,kDAA0B;AAC1B,gDAAwB;AACxB,yCAAyC;AACzC,kDASiC;AAEjC,gCAAwC;AACxC,kEAAkE;AAQlE,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC5B,0CAAqB,CAAA;IACrB,kCAAa,CAAA;AACd,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAU;IACd,KAAK,CAAuD;IAC5D,UAAU,CAA6C;IACvD,sBAAsB,CAAqE;IAE3F,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,OAAO,CAAS;IAExB,YAAY,OAAmB;QAC9B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAE/B,IAAI,CAAC,KAAK,GAAG,wBAAuE,CAAC;QACrF,IAAI,CAAC,UAAU,GAAG,mBAAwD,CAAC;QAC3E,IAAI,CAAC,sBAAsB,GAAG,+BACK,CAAC;IACrC,CAA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,kBAAkB,EAAE,EAAE;gBACtD,IAAI,GAAG,EAAE,CAAC;oBACT,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;oBAChD,MAAM,IAAI,kBAAS,CAAC;wBACnB,IAAI,EAAE,uBAAuB;wBAC7B,OAAO,EAAE,yCAAyC;qBAClD,CAAC,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBAEP,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAG3D,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAEjD,OAAO,CAAC,cAAc,CAAC,CAAC;gBACzB,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA5gBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA4gBtB","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(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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst settlement = await this.model.findById(settlementId);\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with 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\tif (settlement.status === BobSettlementStatus.PAID) {\n\t\t\tconsole.error(`Settlement with ID ${settlementId} is already marked as paid.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\tmessage: 'Settlement is already marked as paid.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.settlePayment(settlement);\n\n\t\tif (settlement.status === BobSettlementStatus.NOT_PAID) {\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\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);\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);\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(settlement: DocumentType<BOBFinance>) {\n\t\tawait this.model.findByIdAndUpdate(\n\t\t\tsettlement._id,\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,+CAS4B;AAC5B,mCAAiC;AACjC,kDAA0B;AAC1B,gDAAwB;AACxB,yCAAyC;AACzC,kDASiC;AAEjC,gCAAwC;AACxC,kEAAiF;AAQjF,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC5B,0CAAqB,CAAA;IACrB,kCAAa,CAAA;AACd,CAAC,EAHW,iBAAiB,iCAAjB,iBAAiB,QAG5B;AAGM,IAAM,UAAU,GAAhB,MAAM,UAAU;IACd,KAAK,CAAuD;IAC5D,UAAU,CAA6C;IACvD,sBAAsB,CAAqE;IAE3F,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,OAAO,CAAS;IAExB,YAAY,OAAmB;QAC9B,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAE/B,IAAI,CAAC,KAAK,GAAG,wBAAuE,CAAC;QACrF,IAAI,CAAC,UAAU,GAAG,mBAAwD,CAAC;QAC3E,IAAI,CAAC,sBAAsB,GAAG,+BACK,CAAC;IACrC,CAAC;IAEO,KAAK,CAAC,uBAAuB;QACpC,OAAO,M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EAAE;YACjD,SAAS,EAAE,cAAc,CAAC,SAAS,IAAI,IAAI,IAAI,EAAE;SACjD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAAC,QAAgB;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAEtC,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAGtD,cAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,GAAG,EAAE,kBAAkB,EAAE,EAAE;gBACtD,IAAI,GAAG,EAAE,CAAC;oBACT,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAC;oBAChD,MAAM,IAAI,kBAAS,CAAC;wBACnB,IAAI,EAAE,uBAAuB;wBAC7B,OAAO,EAAE,yCAAyC;qBAClD,CAAC,CAAC;gBACJ,CAAC;qBAAM,CAAC;oBAEP,MAAM,aAAa,GAAG,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;oBAG3D,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;oBAEjD,OAAO,CAAC,cAAc,CAAC,CAAC;gBACzB,CAAC;YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AAteY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CAsetB","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, notFoundError } 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(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 settlementId - The ID of the settlement to update\n\t * @returns Confirmation of the update\n\t */\n\tpublic async markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean> {\n\t\tconst settlement = await this.model.findById(settlementId);\n\n\t\tif (!settlement) {\n\t\t\tconsole.error(`Settlement with 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\tif (settlement.status === BobSettlementStatus.PAID) {\n\t\t\tconsole.error(`Settlement with ID ${settlementId} is already marked as paid.`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'BAD_REQUEST',\n\t\t\t\tmessage: 'Settlement is already marked as paid.',\n\t\t\t});\n\t\t}\n\n\t\tawait this.settlePayment(settlement);\n\n\t\tif (settlement.status === BobSettlementStatus.NOT_PAID) {\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(settlement: DocumentType<BOBFinance>) {\n\t\tawait this.model.findByIdAndUpdate(\n\t\t\tsettlement._id,\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\tif (!settlements.length) {\n\t\t\tnotFoundError('No unpaid settlements found.')\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,6 +1,15 @@
1
1
  import { Ref } from '@typegoose/typegoose';
2
2
  import { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
3
3
  import { Product } from './product.model';
4
+ import { Attribute } from './attribute.model';
5
+ import { Types } from 'mongoose';
6
+ declare class AttributeMap {
7
+ attribute: Ref<Attribute>;
8
+ hiddenItems?: Types.ObjectId[];
9
+ }
4
10
  export declare class ProductStockTracker extends TimeStamps {
5
- productIds: Ref<Product>[];
11
+ isStockOut: boolean;
12
+ productId: Ref<Product>;
13
+ attributeMaps?: AttributeMap[];
6
14
  }
15
+ export {};
@@ -13,21 +13,45 @@ exports.ProductStockTracker = void 0;
13
13
  const typegoose_1 = require("@typegoose/typegoose");
14
14
  const defaultClasses_1 = require("@typegoose/typegoose/lib/defaultClasses");
15
15
  const product_model_1 = require("./product.model");
16
- let ProductStockTracker = class ProductStockTracker extends defaultClasses_1.TimeStamps {
17
- productIds;
16
+ const attribute_model_1 = require("./attribute.model");
17
+ const mongoose_1 = require("mongoose");
18
+ let AttributeMap = class AttributeMap {
19
+ attribute;
20
+ hiddenItems;
18
21
  };
19
- exports.ProductStockTracker = ProductStockTracker;
20
22
  __decorate([
21
- (0, typegoose_1.prop)({ ref: () => product_model_1.Product, default: [] }),
23
+ (0, typegoose_1.prop)({ required: true, ref: () => attribute_model_1.Attribute }),
24
+ __metadata("design:type", Object)
25
+ ], AttributeMap.prototype, "attribute", void 0);
26
+ __decorate([
27
+ (0, typegoose_1.prop)({ type: () => [mongoose_1.Types.ObjectId], default: [] }),
22
28
  __metadata("design:type", Array)
23
- ], ProductStockTracker.prototype, "productIds", void 0);
24
- exports.ProductStockTracker = ProductStockTracker = __decorate([
29
+ ], AttributeMap.prototype, "hiddenItems", void 0);
30
+ AttributeMap = __decorate([
25
31
  (0, typegoose_1.modelOptions)({
26
32
  schemaOptions: {
27
- collection: 'productStockTracks',
33
+ collection: 'productStockTrackers',
28
34
  toJSON: { virtuals: true },
29
35
  toObject: { virtuals: true },
30
36
  },
31
37
  })
32
- ], ProductStockTracker);
38
+ ], AttributeMap);
39
+ class ProductStockTracker extends defaultClasses_1.TimeStamps {
40
+ isStockOut;
41
+ productId;
42
+ attributeMaps;
43
+ }
44
+ exports.ProductStockTracker = ProductStockTracker;
45
+ __decorate([
46
+ (0, typegoose_1.prop)({ required: true, type: Boolean }),
47
+ __metadata("design:type", Boolean)
48
+ ], ProductStockTracker.prototype, "isStockOut", void 0);
49
+ __decorate([
50
+ (0, typegoose_1.prop)({ required: true, ref: () => product_model_1.Product }),
51
+ __metadata("design:type", Object)
52
+ ], ProductStockTracker.prototype, "productId", void 0);
53
+ __decorate([
54
+ (0, typegoose_1.prop)({ type: [AttributeMap], default: [] }),
55
+ __metadata("design:type", Array)
56
+ ], ProductStockTracker.prototype, "attributeMaps", void 0);
33
57
  //# sourceMappingURL=product-stock-tracker.model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"product-stock-tracker.model.js","sourceRoot":"/","sources":["libraries/mongo/models/product-stock-tracker.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,mDAA0C;AASnC,IAAM,mBAAmB,GAAzB,MAAM,mBAAoB,SAAQ,2BAAU;IAE3C,UAAU,CAAiB;CAClC,CAAA;AAHY,kDAAmB;AAExB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,uBAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;uDACR;8BAFtB,mBAAmB;IAP/B,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,oBAAoB;YAChC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5B;KACD,CAAC;GACW,mBAAmB,CAG/B","sourcesContent":["import { modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { Product } from './product.model';\n\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'productStockTracks',\n\t\ttoJSON: { virtuals: true },\n\t\ttoObject: { virtuals: true },\n\t},\n})\nexport class ProductStockTracker extends TimeStamps {\n\t@prop({ ref: () => Product, default: [] })\n\tpublic productIds: Ref<Product>[];\n}\n"]}
1
+ {"version":3,"file":"product-stock-tracker.model.js","sourceRoot":"/","sources":["libraries/mongo/models/product-stock-tracker.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA+D;AAC/D,4EAAqE;AACrE,mDAA0C;AAC1C,uDAA8C;AAC9C,uCAAiC;AASjC,IAAM,YAAY,GAAlB,MAAM,YAAY;IAEV,SAAS,CAAkB;IAG3B,WAAW,CAAoB;CACtC,CAAA;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,2BAAS,EAAE,CAAC;;+CACb;AAG3B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAK,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;iDACd;AALjC,YAAY;IAPjB,IAAA,wBAAY,EAAC;QACb,aAAa,EAAE;YACd,UAAU,EAAE,sBAAsB;YAClC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;YAC1B,QAAQ,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE;SAC5B;KACD,CAAC;GACI,YAAY,CAMjB;AAED,MAAa,mBAAoB,SAAQ,2BAAU;IAE3C,UAAU,CAAU;IAGpB,SAAS,CAAe;IAGxB,aAAa,CAAkB;CACtC;AATD,kDASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;uDACb;AAGpB;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,uBAAO,EAAE,CAAC;;sDACd;AAGxB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;0DACN","sourcesContent":["import { modelOptions, prop, Ref } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { Product } from './product.model';\nimport { Attribute } from './attribute.model';\nimport { Types } from 'mongoose';\n\n@modelOptions({\n\tschemaOptions: {\n\t\tcollection: 'productStockTrackers',\n\t\ttoJSON: { virtuals: true },\n\t\ttoObject: { virtuals: true },\n\t},\n})\nclass AttributeMap {\n\t@prop({ required: true, ref: () => Attribute })\n\tpublic attribute!: Ref<Attribute>;\n\n\t@prop({ type: () => [Types.ObjectId], default: [] })\n\tpublic hiddenItems?: Types.ObjectId[];\n}\n\nexport class ProductStockTracker extends TimeStamps {\n\t@prop({ required: true, type: Boolean })\n\tpublic isStockOut: boolean;\n\n\t@prop({ required: true, ref: () => Product })\n\tpublic productId: Ref<Product>;\n\n\t@prop({ type: [AttributeMap], default: [] })\n\tpublic attributeMaps?: AttributeMap[];\n}\n"]}
@@ -14,4 +14,7 @@ export declare class RedisService {
14
14
  removeFromSet(group: string, member: string): Promise<boolean>;
15
15
  isMemberOfSet(group: string, member: string): Promise<boolean>;
16
16
  getSetMembers(group: string): Promise<string[]>;
17
+ acquireLock(key: string, ttl?: number): Promise<string | null>;
18
+ releaseLock(key: string, lockValue: string): Promise<boolean>;
19
+ executeWithLock<T>(key: string, ttl: number, callback: () => Promise<T>): Promise<T>;
17
20
  }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.RedisService = void 0;
16
16
  const ioredis_1 = __importDefault(require("ioredis"));
17
17
  const typedi_1 = require("typedi");
18
+ const crypto_1 = require("crypto");
18
19
  let RedisService = class RedisService {
19
20
  _redisClient;
20
21
  constructor(redisURL) {
@@ -82,6 +83,39 @@ let RedisService = class RedisService {
82
83
  async getSetMembers(group) {
83
84
  return await this._redisClient.smembers(group);
84
85
  }
86
+ async acquireLock(key, ttl = 10000) {
87
+ const lockKey = `lock:${key}`;
88
+ const lockValue = (0, crypto_1.randomUUID)();
89
+ const result = await this._redisClient.set(lockKey, lockValue, 'PX', ttl, 'NX');
90
+ if (result === 'OK') {
91
+ return lockValue;
92
+ }
93
+ return null;
94
+ }
95
+ async releaseLock(key, lockValue) {
96
+ const lockKey = `lock:${key}`;
97
+ const luaScript = `
98
+ if redis.call("get", KEYS[1]) == ARGV[1] then
99
+ return redis.call("del", KEYS[1])
100
+ else
101
+ return 0
102
+ end
103
+ `;
104
+ const result = await this._redisClient.eval(luaScript, 1, lockKey, lockValue);
105
+ return result === 1;
106
+ }
107
+ async executeWithLock(key, ttl, callback) {
108
+ const lockValue = await this.acquireLock(key, ttl);
109
+ if (!lockValue) {
110
+ throw new Error('Resource is locked');
111
+ }
112
+ try {
113
+ return await callback();
114
+ }
115
+ finally {
116
+ await this.releaseLock(key, lockValue);
117
+ }
118
+ }
85
119
  };
86
120
  exports.RedisService = RedisService;
87
121
  exports.RedisService = RedisService = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA4B;AAC5B,mCAAiC;AAG1B,IAAM,YAAY,GAAlB,MAAM,YAAY;IAChB,YAAY,CAAS;IAE7B,YAAY,QAAgB;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;YACvC,oBAAoB,EAAE,IAAI;SAC1B,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,eAAe,CAAI,GAAW;QAC1C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEvD,IAAI,aAAa,IAAI,SAAS,EAAE,CAAC;YAChC,OAAO,IA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;QACnE,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,WAAW,CAAC,GAAW;QAC7B,OAAO,GAAG;aACR,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;aACxB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,WAAW,EAAE,CAAC;IACjB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,KAAa,EAAE,MAAc;QAClD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa,EAAE,MAAc;QACvD,MAAM,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa,EAAE,MAAc;QACvD,OAAO,CAAC,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC;IACjE,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,KAAa;QACvC,OAAO,MAAM,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,CAAC;CACD,CAAA;AAtFY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CAsFxB","sourcesContent":["import Redis from 'ioredis';\nimport { Service } from 'typedi';\n\n@Service()\nexport class RedisService {\n\tprivate _redisClient!: Redis;\n\n\tconstructor(redisURL: string) {\n\t\tthis._redisClient = new Redis(redisURL, {\n\t\t\tmaxRetriesPerRequest: null,\n\t\t});\n\t}\n\n\tget redisClient(): Redis {\n\t\treturn this._redisClient;\n\t}\n\n\tpublic async getCachedObject<T>(key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.get(key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async cacheObject<T>(key: string, object: T, expiry?: number): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\n\t\tif (expiry) {\n\t\t\tawait this._redisClient.setex(key, expiry, stringifiedObject);\n\t\t} else {\n\t\t\tawait this._redisClient.set(key, stringifiedObject);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObject(key: string): Promise<boolean> {\n\t\tawait this._redisClient.del(key);\n\t\treturn true;\n\t}\n\n\tpublic async getCachedObjectByGroup<T>(group: string, key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.hget(group, key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\t\tawait this._redisClient.hset(group, key, stringifiedObject);\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean> {\n\t\tawait this._redisClient.hdel(group, key);\n\t\treturn true;\n\t}\n\n\tpublic sanitizeKey(key: string) {\n\t\treturn key\n\t\t\t.replace(/[^\\w\\s]/gi, '')\n\t\t\t.replace(/\\s+/g, '-')\n\t\t\t.toLowerCase();\n\t}\n\n\tpublic async addToSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.sadd(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async removeFromSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.srem(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async isMemberOfSet(group: string, member: string): Promise<boolean> {\n\t\treturn (await this._redisClient.sismember(group, member)) === 1;\n\t}\n\n\tpublic async getSetMembers(group: string): Promise<string[]> {\n\t\treturn await this._redisClient.smembers(group);\n\t}\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/redis/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA4B;AAC5B,mCAAiC;AACjC,mCAAoC;AAG7B,IAAM,YAAY,GAAlB,MAAM,YAAY;IAChB,YAAY,CAAS;IAE7B,YAAY,QAAgB;QAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,iBAAK,CAAC,QAAQ,EAAE;YACvC,oBAAoB,EAAE,IAAI;SAC1B,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,WAAW;QACd,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,eAAe,CAAI,GAAW;QAC1C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEvD,IAAI,aAAa,IAAI,SAAS,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAM,CAAC;QACvC,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,WAAW,CAAI,GAAW,EAAE,MAAS,EAAE,MAAe;QAClE,MAAM,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEjD,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC;QAC/D,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC;QACrD,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,GAAW;QAC1C,MAAM,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC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AAoB,CAAC,CAAC;QACvC,CAAC;QAED,IAAI,CAAC;YACJ,OAAO,MAAM,QAAQ,EAAE,CAAC;QACzB,CAAC;gBAAS,CAAC;YACV,MAAM,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;QACxC,CAAC;IACF,CAAC;CACD,CAAA;AArIY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,gBAAO,GAAE;;GACG,YAAY,CAqIxB","sourcesContent":["import Redis from 'ioredis';\nimport { Service } from 'typedi';\nimport { randomUUID } from 'crypto';\n\n@Service()\nexport class RedisService {\n\tprivate _redisClient!: Redis;\n\n\tconstructor(redisURL: string) {\n\t\tthis._redisClient = new Redis(redisURL, {\n\t\t\tmaxRetriesPerRequest: null,\n\t\t});\n\t}\n\n\tget redisClient(): Redis {\n\t\treturn this._redisClient;\n\t}\n\n\tpublic async getCachedObject<T>(key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.get(key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async cacheObject<T>(key: string, object: T, expiry?: number): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\n\t\tif (expiry) {\n\t\t\tawait this._redisClient.setex(key, expiry, stringifiedObject);\n\t\t} else {\n\t\t\tawait this._redisClient.set(key, stringifiedObject);\n\t\t}\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObject(key: string): Promise<boolean> {\n\t\tawait this._redisClient.del(key);\n\t\treturn true;\n\t}\n\n\tpublic async getCachedObjectByGroup<T>(group: string, key: string): Promise<T | undefined> {\n\t\tconst usageResponse = await this._redisClient.hget(group, key);\n\n\t\tif (usageResponse != undefined) {\n\t\t\treturn JSON.parse(usageResponse) as T;\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\tpublic async setCachedObjectByGroup<T>(group: string, key: string, object: T): Promise<boolean> {\n\t\tconst stringifiedObject = JSON.stringify(object);\n\t\tawait this._redisClient.hset(group, key, stringifiedObject);\n\n\t\treturn true;\n\t}\n\n\tpublic async deleteCachedObjectByGroup<T>(group: string, key: string): Promise<boolean> {\n\t\tawait this._redisClient.hdel(group, key);\n\t\treturn true;\n\t}\n\n\tpublic sanitizeKey(key: string) {\n\t\treturn key\n\t\t\t.replace(/[^\\w\\s]/gi, '')\n\t\t\t.replace(/\\s+/g, '-')\n\t\t\t.toLowerCase();\n\t}\n\n\tpublic async addToSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.sadd(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async removeFromSet(group: string, member: string): Promise<boolean> {\n\t\tawait this._redisClient.srem(group, member);\n\t\treturn true;\n\t}\n\n\tpublic async isMemberOfSet(group: string, member: string): Promise<boolean> {\n\t\treturn (await this._redisClient.sismember(group, member)) === 1;\n\t}\n\n\tpublic async getSetMembers(group: string): Promise<string[]> {\n\t\treturn await this._redisClient.smembers(group);\n\t}\n\n\tpublic async acquireLock(\n\t\tkey: string,\n\t\tttl: number = 10000 // default 10s\n\t): Promise<string | null> {\n\t\tconst lockKey = `lock:${key}`;\n\t\tconst lockValue = randomUUID(); // unique value per process\n\n\t\tconst result = await this._redisClient.set(lockKey, lockValue, 'PX', ttl, 'NX');\n\n\t\t// If result === 'OK' → lock acquired\n\t\tif (result === 'OK') {\n\t\t\treturn lockValue;\n\t\t}\n\n\t\treturn null; // lock not acquired\n\t}\n\n\tpublic async releaseLock(key: string, lockValue: string): Promise<boolean> {\n\t\tconst lockKey = `lock:${key}`;\n\n\t\tconst luaScript = `\n\t\tif redis.call(\"get\", KEYS[1]) == ARGV[1] then\n\t\t\treturn redis.call(\"del\", KEYS[1])\n\t\telse\n\t\t\treturn 0\n\t\tend\n\t`;\n\n\t\tconst result = await this._redisClient.eval(luaScript, 1, lockKey, lockValue);\n\n\t\treturn result === 1;\n\t}\n\n\tpublic async executeWithLock<T>(key: string, ttl: number, callback: () => Promise<T>): Promise<T> {\n\t\tconst lockValue = await this.acquireLock(key, ttl);\n\n\t\tif (!lockValue) {\n\t\t\tthrow new Error('Resource is locked');\n\t\t}\n\n\t\ttry {\n\t\t\treturn await callback();\n\t\t} finally {\n\t\t\tawait this.releaseLock(key, lockValue);\n\t\t}\n\t}\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.3.225
25
+ Version: 1.3.227
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.225",
3
+ "version": "1.3.227",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -26,8 +26,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
26
26
  searchFields?: string[] | undefined;
27
27
  } | undefined;
28
28
  sort?: Record<string, 1 | -1> | undefined;
29
- select?: Record<string, 0 | 1> | undefined;
30
29
  populate?: any;
30
+ select?: Record<string, 0 | 1> | undefined;
31
31
  query?: Record<string, any> | undefined;
32
32
  }, {
33
33
  search?: {
@@ -36,8 +36,8 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
36
36
  } | undefined;
37
37
  sort?: Record<string, 1 | -1> | undefined;
38
38
  size?: number | undefined;
39
- select?: Record<string, 0 | 1> | undefined;
40
39
  populate?: any;
40
+ select?: Record<string, 0 | 1> | undefined;
41
41
  query?: Record<string, any> | undefined;
42
42
  page?: number | undefined;
43
43
  }>>;
@@ -733,12 +733,12 @@ export declare const GetByIdInputSchema: z.ZodObject<{
733
733
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
734
734
  }, "strip", z.ZodTypeAny, {
735
735
  _id: import("mongoose").Types.ObjectId;
736
- select?: Record<string, 0 | 1> | undefined;
737
736
  populate?: any;
737
+ select?: Record<string, 0 | 1> | undefined;
738
738
  }, {
739
739
  _id: string | import("mongoose").Types.ObjectId;
740
- select?: Record<string, 0 | 1> | undefined;
741
740
  populate?: any;
741
+ select?: Record<string, 0 | 1> | undefined;
742
742
  }>;
743
743
  export type GetByIdInputDTO = DTO<typeof GetByIdInputSchema>;
744
744
  export declare const GetProductByIdInputSchema: z.ZodObject<{
@@ -751,12 +751,12 @@ export declare const GetProductByIdInputSchema: z.ZodObject<{
751
751
  _id: import("mongoose").Types.ObjectId;
752
752
  withAttributeHiddenItems: boolean;
753
753
  withAddonsHiddenItems: boolean;
754
- select?: Record<string, 0 | 1> | undefined;
755
754
  populate?: any;
755
+ select?: Record<string, 0 | 1> | undefined;
756
756
  }, {
757
757
  _id: string | import("mongoose").Types.ObjectId;
758
- select?: Record<string, 0 | 1> | undefined;
759
758
  populate?: any;
759
+ select?: Record<string, 0 | 1> | undefined;
760
760
  withAttributeHiddenItems?: boolean | undefined;
761
761
  withAddonsHiddenItems?: boolean | undefined;
762
762
  }>;
@@ -768,13 +768,13 @@ export declare const GetOrderByIdInputSchema: z.ZodObject<{
768
768
  userOrderCompletionScope: z.ZodOptional<z.ZodNativeEnum<typeof UserOrderCompletionScope>>;
769
769
  }, "strip", z.ZodTypeAny, {
770
770
  _id: import("mongoose").Types.ObjectId;
771
- select?: Record<string, 0 | 1> | undefined;
772
771
  populate?: any;
772
+ select?: Record<string, 0 | 1> | undefined;
773
773
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
774
774
  }, {
775
775
  _id: string | import("mongoose").Types.ObjectId;
776
- select?: Record<string, 0 | 1> | undefined;
777
776
  populate?: any;
777
+ select?: Record<string, 0 | 1> | undefined;
778
778
  userOrderCompletionScope?: UserOrderCompletionScope | undefined;
779
779
  }>;
780
780
  export type GetOrderByIdInputDTO = DTO<typeof GetOrderByIdInputSchema>;
@@ -782,11 +782,11 @@ export declare const GetByTokenInputSchema: z.ZodOptional<z.ZodObject<{
782
782
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
783
783
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
784
784
  }, "strip", z.ZodTypeAny, {
785
- select?: Record<string, 0 | 1> | undefined;
786
785
  populate?: any;
787
- }, {
788
786
  select?: Record<string, 0 | 1> | undefined;
787
+ }, {
789
788
  populate?: any;
789
+ select?: Record<string, 0 | 1> | undefined;
790
790
  }>>;
791
791
  export type GetByTokenInputDTO = DTO<typeof GetByTokenInputSchema>;
792
792
  export declare const GetOneQuerySchema: z.ZodObject<{
@@ -794,12 +794,12 @@ export declare const GetOneQuerySchema: z.ZodObject<{
794
794
  select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
795
795
  populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
796
796
  }, "strip", z.ZodTypeAny, {
797
- select?: Record<string, 0 | 1> | undefined;
798
797
  populate?: any;
798
+ select?: Record<string, 0 | 1> | undefined;
799
799
  query?: Record<string, any> | undefined;
800
800
  }, {
801
- select?: Record<string, 0 | 1> | undefined;
802
801
  populate?: any;
802
+ select?: Record<string, 0 | 1> | undefined;
803
803
  query?: Record<string, any> | undefined;
804
804
  }>;
805
805
  export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.3.225",
3
+ "version": "1.3.227",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",