gemcap-be-common 1.4.230 → 1.4.232

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.
@@ -0,0 +1 @@
1
+ export declare const convertBankReferenceToTransactionReference: (rawReference: string) => string;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertBankReferenceToTransactionReference = void 0;
4
+ const extractReferenceValue = (reference, key) => {
5
+ if (!reference) {
6
+ return '';
7
+ }
8
+ // Capture everything after KEY= until the next XXX= block or end of string
9
+ const regex = new RegExp(`${key}=([\\s\\S]*?)(?=\\s+[A-Z]{2,}=|$)`);
10
+ const match = reference.match(regex);
11
+ if (!match) {
12
+ return '';
13
+ }
14
+ let value = match[1].trim();
15
+ // Remove trailing account markers like /AC- or /BC-
16
+ value = value.split('/')[0].trim();
17
+ // Remove NOTPROVIDED if present
18
+ value = value.replace(/NOTPROVIDED/gi, '').trim();
19
+ // Collapse multiple spaces (incl. tabs) into a single space
20
+ value = value.replace(/\s{2,}/g, ' ');
21
+ return value;
22
+ };
23
+ const convertBankReferenceToTransactionReference = (rawReference) => {
24
+ if (!rawReference) {
25
+ return ' : : ';
26
+ }
27
+ const org = extractReferenceValue(rawReference, 'ORG');
28
+ const bnf = extractReferenceValue(rawReference, 'BNF');
29
+ const obi = extractReferenceValue(rawReference, 'OBI');
30
+ return `${org || ''} : ${bnf || ''} : ${obi || ''}`;
31
+ };
32
+ exports.convertBankReferenceToTransactionReference = convertBankReferenceToTransactionReference;
@@ -17,6 +17,12 @@ const extractReferenceValue = (reference: string, key: string): string => {
17
17
  // Remove trailing account markers like /AC- or /BC-
18
18
  value = value.split('/')[0].trim();
19
19
 
20
+ // Remove NOTPROVIDED if present
21
+ value = value.replace(/NOTPROVIDED/gi, '').trim();
22
+
23
+ // Collapse multiple spaces (incl. tabs) into a single space
24
+ value = value.replace(/\s{2,}/g, ' ');
25
+
20
26
  return value;
21
27
  };
22
28
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.230",
3
+ "version": "1.4.232",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -17,6 +17,7 @@ const CashAllocationProduct_model_1 = require("../models/CashAllocationProduct.m
17
17
  const AllocatedBankTransaction_model_1 = require("../models/AllocatedBankTransaction.model");
18
18
  const AllocatedData_model_1 = require("../models/AllocatedData.model");
19
19
  const date_formats_constants_1 = require("../constants/date-formats.constants");
20
+ const bank_reference_helper_1 = require("../helpers/bank-reference.helper");
20
21
  const useExternalUploader = false; // TODO keep only external upload
21
22
  const createCashAllocationReferencesOnUpload = false;
22
23
  class BankUploadedTransactionsService {
@@ -314,13 +315,14 @@ class BankUploadedTransactionsService {
314
315
  description: '',
315
316
  effectiveDate: null,
316
317
  productId: foundCashAllocationProduct.productId,
317
- reference: splitTransaction ? splitTransaction.memo : transactionToConvert.reference,
318
+ reference: splitTransaction ? splitTransaction.memo : (0, bank_reference_helper_1.convertBankReferenceToTransactionReference)(transactionToConvert.reference),
318
319
  transactionType: transaction.amount > 0 ? LoanTransaction_model_1.ELoanTransactionTypes.COLLECTION : LoanTransaction_model_1.ELoanTransactionTypes.DISBURSEMENT,
319
320
  balance: 0,
320
321
  floatedBalance: 0,
321
322
  });
322
323
  const loanTransactionsService = this.getLoanTransactionsService();
323
324
  const normalizedTransaction = await loanTransactionsService.normalizeLoanTransaction(getLoanTransaction(), userId);
325
+ console.log({ normalizedTransaction });
324
326
  const createdLoanTransaction = await loanTransactionsService.createLoanTransaction(normalizedTransaction);
325
327
  loanTransactionsMap[String(transaction._id)] = [...loanTransactionsMap[String(transaction._id)], new mongoose_1.default.Types.ObjectId(String(createdLoanTransaction._id))];
326
328
  productIds.add(String(foundCashAllocationProduct.productId));
@@ -360,6 +360,7 @@ export class BankUploadedTransactionsService {
360
360
  });
361
361
  const loanTransactionsService = this.getLoanTransactionsService();
362
362
  const normalizedTransaction = await loanTransactionsService.normalizeLoanTransaction(getLoanTransaction() as ILoanTransactionDoc, userId);
363
+ console.log({ normalizedTransaction });
363
364
  const createdLoanTransaction = await loanTransactionsService.createLoanTransaction(normalizedTransaction as Partial<ILoanTransactionWithId>);
364
365
  loanTransactionsMap[String(transaction._id)] = [...loanTransactionsMap[String(transaction._id)], new mongoose.Types.ObjectId(String(createdLoanTransaction._id))];
365
366
  productIds.add(String(foundCashAllocationProduct.productId));