@lyxa.ai/core 1.3.221 → 1.3.222

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.
@@ -7,7 +7,7 @@ export declare class CashSettlementService {
7
7
  checkSettlementStatus(settlementId: string): Promise<any>;
8
8
  getSettlements(filter?: any): Promise<any>;
9
9
  revokeSettlement(reference: string): Promise<any>;
10
- markSettlementAsPaid(reference: string): Promise<boolean>;
10
+ markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
11
11
  hasPendingSettlements(reference: string): Promise<boolean>;
12
12
  getLastSettlement(reference: string): Promise<ISettlementInfo | null>;
13
13
  }
@@ -26,8 +26,8 @@ let CashSettlementService = class CashSettlementService {
26
26
  async revokeSettlement(reference) {
27
27
  return await this.service.revokeSettlement(reference);
28
28
  }
29
- async markSettlementAsPaid(reference) {
30
- return await this.service.markSettlementAsPaid(reference);
29
+ async markSettlementAsPaid(settlementId) {
30
+ return await this.service.markSettlementAsPaid(settlementId);
31
31
  }
32
32
  async hasPendingSettlements(reference) {
33
33
  return await this.service.hasPendingSettlements(reference);
@@ -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;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"]}
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;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 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"]}
@@ -15,7 +15,7 @@ export type ISettlementInfo = {
15
15
  export interface ICashSettlementService {
16
16
  initiateSettlement(amount: number, currency: string, reference: string, firstName: string, lastName: string, riderId: mongoose.Types.ObjectId, location?: string): Promise<boolean>;
17
17
  revokeSettlement(reference: string): Promise<boolean>;
18
- markSettlementAsPaid(reference: string): Promise<boolean>;
18
+ markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
19
19
  hasPendingSettlements(reference: string): Promise<boolean>;
20
20
  getLastSettlement(reference: string): Promise<ISettlementInfo | null>;
21
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}\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"]}
@@ -19,7 +19,7 @@ export declare class BOBService implements ICashSettlementService {
19
19
  constructor(secrets: BOBSecrets);
20
20
  initiateSettlement(amount: number, currency: string, reference: string, firstName: string, lastName: string, riderId: mongoose.Types.ObjectId, location?: string): Promise<boolean>;
21
21
  private createBullMQJobForStatusCheck;
22
- markSettlementAsPaid(reference: string): Promise<boolean>;
22
+ markSettlementAsPaid(settlementId: mongoose.Types.ObjectId): Promise<boolean>;
23
23
  private settlePayment;
24
24
  revokeSettlement(reference: string): Promise<boolean>;
25
25
  private removeTransfer;
@@ -139,7 +139,7 @@ let BOBService = class BOBService {
139
139
  }
140
140
  const hasUnpaidTransfer = responseObject.some((item) => item.CRMNumber == crmNumber && item.Status == BOBTransferStatus.NOT_PAID);
141
141
  if (!hasUnpaidTransfer) {
142
- this.settlePayment(job.data.crmNumber, settlement);
142
+ this.settlePayment(settlement);
143
143
  }
144
144
  console.log(`🔥 [${new Date().toISOString()}] Settlement status for ${job.data.crmNumber}:`, responseObject);
145
145
  });
@@ -150,24 +150,21 @@ let BOBService = class BOBService {
150
150
  console.error(`❌ Job failed: ${job?.id} -`, err);
151
151
  });
152
152
  }
153
- async markSettlementAsPaid(reference) {
154
- const settlement = await this.model.findOne({
155
- crmNumber: reference,
156
- status: enum_1.BobSettlementStatus.NOT_PAID,
157
- });
153
+ async markSettlementAsPaid(settlementId) {
154
+ const settlement = await this.model.findById(settlementId);
158
155
  if (!settlement) {
159
- console.error(`Settlement with reference ${reference} not found.`);
156
+ console.error(`Settlement with not found.`);
160
157
  throw new server_1.TRPCError({
161
158
  code: 'NOT_FOUND',
162
159
  message: 'Settlement not found.',
163
160
  });
164
161
  }
165
- await this.settlePayment(reference, settlement);
166
- await this.removeTransfer(reference);
162
+ await this.settlePayment(settlement);
163
+ await this.removeTransfer(settlement.crmNumber);
167
164
  return true;
168
165
  }
169
- async settlePayment(reference, settlement) {
170
- await this.model.findOneAndUpdate({ crmNumber: reference, status: enum_1.BobSettlementStatus.NOT_PAID }, { status: enum_1.BobSettlementStatus.PAID }, { new: true, runValidators: true });
166
+ async settlePayment(settlement) {
167
+ await this.model.findByIdAndUpdate(settlement._id, { status: enum_1.BobSettlementStatus.PAID }, { new: true, runValidators: true });
171
168
  await this.financeSettlementModel.create({
172
169
  amount: settlement.amount,
173
170
  secondaryAmount: settlement.secondaryAmount,
@@ -1 +1 @@
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;AAEj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YACF,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;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"]}
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,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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kB,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;AA9XY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA8XtB","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(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\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\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\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"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.3.221
25
+ Version: 1.3.222
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.3.221",
3
+ "version": "1.3.222",
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.221",
3
+ "version": "1.3.222",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",