@6thbridge/utils 0.3.8 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/charge.action.d.ts +0 -18
- package/lib/actions/charge.action.js +3 -34
- package/lib/actions/charge.action.js.map +1 -1
- package/lib/actions/charge.action.test.js +0 -42
- package/lib/actions/charge.action.test.js.map +1 -1
- package/lib/actions/index.d.ts +5 -11
- package/lib/actions/index.js +7 -34
- package/lib/actions/index.js.map +1 -1
- package/lib/actions/permission.action.js +2 -2
- package/lib/actions/permission.action.js.map +1 -1
- package/lib/actions/route.action.js +4 -3
- package/lib/actions/route.action.js.map +1 -1
- package/lib/{translations/index.d.ts → actions/translation.action.d.ts} +3 -1
- package/lib/{translations/index.js → actions/translation.action.js} +15 -12
- package/lib/actions/translation.action.js.map +1 -0
- package/lib/brokers/index.d.ts +1 -2
- package/lib/brokers/index.js +1 -3
- package/lib/brokers/index.js.map +1 -1
- package/lib/brokers/rabbitmq.d.ts +102 -5
- package/lib/brokers/rabbitmq.js +111 -6
- package/lib/brokers/rabbitmq.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +19 -0
- package/lib/data/index.js.map +1 -0
- package/lib/data/rabbitmq/index.d.ts +57 -0
- package/lib/data/rabbitmq/index.js +231 -0
- package/lib/data/rabbitmq/index.js.map +1 -0
- package/lib/data/rabbitmq/rabbitmq.test.js +71 -0
- package/lib/data/rabbitmq/rabbitmq.test.js.map +1 -0
- package/lib/data/redis/index.d.ts +32 -0
- package/lib/data/redis/index.js +70 -0
- package/lib/data/redis/index.js.map +1 -0
- package/lib/{actions/queue.action.js → data/redis/redis-example.js} +14 -6
- package/lib/data/redis/redis-example.js.map +1 -0
- package/lib/database/MongoDBRepository.d.ts +5 -3
- package/lib/database/MongoDBRepository.js +2 -2
- package/lib/database/MongoDBRepository.js.map +1 -1
- package/lib/database/index.d.ts +2 -3
- package/lib/database/index.js +4 -16
- package/lib/database/index.js.map +1 -1
- package/lib/index.d.ts +13 -17
- package/lib/index.js +18 -40
- package/lib/index.js.map +1 -1
- package/lib/logger/index.d.ts +2 -0
- package/lib/logger/index.js +16 -0
- package/lib/logger/index.js.map +1 -1
- package/lib/logger/logger-test.js +2 -2
- package/lib/logger/logger-test.js.map +1 -1
- package/lib/logger/logger.d.ts +3 -3
- package/lib/logger/logger.js +2 -2
- package/lib/logger/logger.js.map +1 -1
- package/lib/{test/logger → logger}/test.spec.js +1 -1
- package/lib/logger/test.spec.js.map +1 -0
- package/lib/middlewares/common.js +3 -4
- package/lib/middlewares/common.js.map +1 -1
- package/lib/middlewares/index.d.ts +1 -2
- package/lib/middlewares/index.js +1 -3
- package/lib/middlewares/index.js.map +1 -1
- package/lib/monitoring/index.js +3 -2
- package/lib/monitoring/index.js.map +1 -1
- package/lib/responses/express.d.ts +2 -0
- package/lib/responses/express.js +7 -31
- package/lib/responses/express.js.map +1 -1
- package/lib/responses/index.d.ts +1 -2
- package/lib/responses/index.js +1 -3
- package/lib/responses/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/broker.entity.d.ts +1 -0
- package/lib/types/index.d.ts +13 -13
- package/lib/types/index.js +13 -17
- package/lib/types/index.js.map +1 -1
- package/lib/types/wallet.entity.d.ts +9 -0
- package/lib/{actions/currency.action.d.ts → utils/amount.d.ts} +12 -10
- package/lib/{actions/currency.action.js → utils/amount.js} +42 -38
- package/lib/utils/amount.js.map +1 -0
- package/lib/{test/actions/amount.action.test.js → utils/amount.test.js} +17 -17
- package/lib/utils/amount.test.js.map +1 -0
- package/lib/{actions/database.action.d.ts → utils/database.d.ts} +1 -1
- package/lib/{actions/database.action.js → utils/database.js} +10 -7
- package/lib/utils/database.js.map +1 -0
- package/lib/{actions/database.action.spec.js → utils/database.spec.js} +35 -39
- package/lib/utils/database.spec.js.map +1 -0
- package/lib/{actions/file.action.d.ts → utils/file.d.ts} +1 -1
- package/lib/{actions/file.action.js → utils/file.js} +4 -4
- package/lib/utils/file.js.map +1 -0
- package/lib/utils/helper.d.ts +10 -0
- package/lib/utils/helper.js +86 -0
- package/lib/utils/helper.js.map +1 -0
- package/lib/utils/helper.spec.js +203 -0
- package/lib/utils/helper.spec.js.map +1 -0
- package/lib/{http/axios.d.ts → utils/http.d.ts} +4 -0
- package/lib/{http/axios.js → utils/http.js} +12 -3
- package/lib/utils/http.js.map +1 -0
- package/lib/utils/index.d.ts +8 -0
- package/lib/utils/index.js +25 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/{actions/phone-number.action.d.ts → utils/phoneNumber.d.ts} +22 -19
- package/lib/{actions/phone-number.action.js → utils/phoneNumber.js} +41 -41
- package/lib/utils/phoneNumber.js.map +1 -0
- package/lib/utils/phoneNumber.spec.js +60 -0
- package/lib/utils/phoneNumber.spec.js.map +1 -0
- package/lib/utils/reference.d.ts +7 -0
- package/lib/utils/reference.js +44 -0
- package/lib/utils/reference.js.map +1 -0
- package/lib/utils/reference.spec.d.ts +1 -0
- package/lib/utils/reference.spec.js +34 -0
- package/lib/utils/reference.spec.js.map +1 -0
- package/lib/utils/validator.d.ts +20 -0
- package/lib/utils/validator.js +56 -0
- package/lib/utils/validator.js.map +1 -0
- package/package.json +4 -3
- package/readme.md +347 -47
- package/lib/actions/amount.action.d.ts +0 -10
- package/lib/actions/amount.action.js +0 -40
- package/lib/actions/amount.action.js.map +0 -1
- package/lib/actions/currency.action.js.map +0 -1
- package/lib/actions/database.action.js.map +0 -1
- package/lib/actions/database.action.spec.js.map +0 -1
- package/lib/actions/file.action.js.map +0 -1
- package/lib/actions/phone-number.action.js.map +0 -1
- package/lib/actions/queue.action.d.ts +0 -3
- package/lib/actions/queue.action.js.map +0 -1
- package/lib/brokers/kafka.d.ts +0 -84
- package/lib/brokers/kafka.js +0 -275
- package/lib/brokers/kafka.js.map +0 -1
- package/lib/brokers/kafka.test.js +0 -117
- package/lib/brokers/kafka.test.js.map +0 -1
- package/lib/database/MongoDBTypeRepository.d.ts +0 -77
- package/lib/database/MongoDBTypeRepository.js +0 -85
- package/lib/database/MongoDBTypeRepository.js.map +0 -1
- package/lib/database/query.d.ts +0 -18
- package/lib/database/query.js +0 -30
- package/lib/database/query.js.map +0 -1
- package/lib/helpers/errors.d.ts +0 -15
- package/lib/helpers/errors.js +0 -29
- package/lib/helpers/errors.js.map +0 -1
- package/lib/helpers/index.d.ts +0 -58
- package/lib/helpers/index.js +0 -226
- package/lib/helpers/index.js.map +0 -1
- package/lib/helpers/utils.d.ts +0 -9
- package/lib/helpers/utils.js +0 -17
- package/lib/helpers/utils.js.map +0 -1
- package/lib/http/axios.js.map +0 -1
- package/lib/middlewares/fastify.d.ts +0 -4
- package/lib/middlewares/fastify.js +0 -73
- package/lib/middlewares/fastify.js.map +0 -1
- package/lib/responses/fastify.d.ts +0 -4
- package/lib/responses/fastify.js +0 -25
- package/lib/responses/fastify.js.map +0 -1
- package/lib/secrets/aws-secret.d.ts +0 -4
- package/lib/secrets/aws-secret.js +0 -55
- package/lib/secrets/aws-secret.js.map +0 -1
- package/lib/secrets/index.d.ts +0 -8
- package/lib/secrets/index.js +0 -18
- package/lib/secrets/index.js.map +0 -1
- package/lib/test/actions/amount.action.test.js.map +0 -1
- package/lib/test/database/test.spec.js +0 -91
- package/lib/test/database/test.spec.js.map +0 -1
- package/lib/test/helpers/PhoneNumber.spec.js +0 -82
- package/lib/test/helpers/PhoneNumber.spec.js.map +0 -1
- package/lib/test/logger/test.spec.js.map +0 -1
- package/lib/test/types/context.entity.test.js +0 -29
- package/lib/test/types/context.entity.test.js.map +0 -1
- package/lib/translations/index.js.map +0 -1
- /package/lib/{actions/database.action.spec.d.ts → data/rabbitmq/rabbitmq.test.d.ts} +0 -0
- /package/lib/{brokers/kafka.test.d.ts → data/redis/redis-example.d.ts} +0 -0
- /package/lib/{test/database → logger}/test.spec.d.ts +0 -0
- /package/lib/{test/actions/amount.action.test.d.ts → utils/amount.test.d.ts} +0 -0
- /package/lib/{test/helpers/PhoneNumber.spec.d.ts → utils/database.spec.d.ts} +0 -0
- /package/lib/{test/logger/test.spec.d.ts → utils/helper.spec.d.ts} +0 -0
- /package/lib/{test/types/context.entity.test.d.ts → utils/phoneNumber.spec.d.ts} +0 -0
package/lib/types/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export * from './context.entity';
|
|
2
|
+
export * from './user.entity';
|
|
3
|
+
export * from './client.entity';
|
|
4
|
+
export * from './broker.entity';
|
|
5
|
+
export * from './custom.exception';
|
|
6
|
+
export * from './integration.entity';
|
|
7
|
+
export * from './permission';
|
|
8
|
+
export * from './route.entity';
|
|
9
|
+
export * from './user.entity';
|
|
10
|
+
export * from './wallet.entity';
|
|
11
|
+
export * from '../logger';
|
|
12
|
+
export * from '../responses/express';
|
|
7
13
|
declare module 'axios' {
|
|
8
14
|
interface InternalAxiosRequestConfig {
|
|
9
15
|
meta?: any;
|
|
@@ -61,11 +67,5 @@ interface TransactionFee {
|
|
|
61
67
|
roundUpFinalValue?: boolean;
|
|
62
68
|
[x: string]: any;
|
|
63
69
|
}
|
|
64
|
-
export {
|
|
65
|
-
export * from "./integration.entity";
|
|
66
|
-
export * from "./wallet.entity";
|
|
67
|
-
export * from "./broker.entity";
|
|
68
|
-
export * from "./custom.exception";
|
|
70
|
+
export { SaveActivityLogDTO, FunctionResponseDTO, FunctionResult, PFunctionResult, TransactionFee, ErrorTypeEnum, };
|
|
69
71
|
export { CountryCode } from 'libphonenumber-js';
|
|
70
|
-
export { RouteHandler, RouteConfig, RouteHTTPMethod, RouteGroupConfig, RouteMiddleware, } from "./route.entity";
|
|
71
|
-
export * from "../actions";
|
package/lib/types/index.js
CHANGED
|
@@ -14,27 +14,23 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ErrorTypeEnum =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
exports.ErrorTypeEnum = void 0;
|
|
18
|
+
__exportStar(require("./context.entity"), exports);
|
|
19
|
+
__exportStar(require("./user.entity"), exports);
|
|
20
|
+
__exportStar(require("./client.entity"), exports);
|
|
21
|
+
__exportStar(require("./broker.entity"), exports);
|
|
22
|
+
__exportStar(require("./custom.exception"), exports);
|
|
23
|
+
__exportStar(require("./integration.entity"), exports);
|
|
24
|
+
__exportStar(require("./permission"), exports);
|
|
25
|
+
__exportStar(require("./route.entity"), exports);
|
|
26
|
+
__exportStar(require("./user.entity"), exports);
|
|
27
|
+
__exportStar(require("./wallet.entity"), exports);
|
|
28
|
+
__exportStar(require("../logger"), exports);
|
|
29
|
+
__exportStar(require("../responses/express"), exports);
|
|
29
30
|
var ErrorTypeEnum;
|
|
30
31
|
(function (ErrorTypeEnum) {
|
|
31
32
|
ErrorTypeEnum["ProviderError"] = "ProviderError";
|
|
32
33
|
ErrorTypeEnum["PlatformError"] = "PlatformError";
|
|
33
34
|
ErrorTypeEnum["CustomerError"] = "CustomerError";
|
|
34
35
|
})(ErrorTypeEnum || (exports.ErrorTypeEnum = ErrorTypeEnum = {}));
|
|
35
|
-
__exportStar(require("./integration.entity"), exports);
|
|
36
|
-
__exportStar(require("./wallet.entity"), exports);
|
|
37
|
-
__exportStar(require("./broker.entity"), exports);
|
|
38
|
-
__exportStar(require("./custom.exception"), exports);
|
|
39
|
-
__exportStar(require("../actions"), exports);
|
|
40
36
|
//# sourceMappingURL=index.js.map
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,gDAA+B;AAC/B,kDAAiC;AACjC,kDAAiC;AACjC,qDAAoC;AACpC,uDAAsC;AACtC,+CAA8B;AAC9B,iDAAgC;AAChC,gDAA+B;AAC/B,kDAAiC;AACjC,4CAA0B;AAC1B,uDAAqC;AAkBrC,IAAK,aAIJ;AAJD,WAAK,aAAa;IAChB,gDAA+B,CAAA;IAC/B,gDAA+B,CAAA;IAC/B,gDAA+B,CAAA;AACjC,CAAC,EAJI,aAAa,6BAAb,aAAa,QAIjB"}
|
|
@@ -32,3 +32,12 @@ export type WalletEntity = {
|
|
|
32
32
|
notificationLimitEmailNextSentAt?: number;
|
|
33
33
|
[x: string]: any;
|
|
34
34
|
};
|
|
35
|
+
export type TransactionBalanceResult = {
|
|
36
|
+
clientId: string;
|
|
37
|
+
walletType: WalletType;
|
|
38
|
+
country: string;
|
|
39
|
+
currency: string;
|
|
40
|
+
ownerType: WalletOwnerType;
|
|
41
|
+
ownerId: string;
|
|
42
|
+
balance: number;
|
|
43
|
+
};
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
export declare const NON_DECIMAL_ACCEPTING_COUNTRIES: string[];
|
|
1
2
|
export declare const FRANCOPHONE_CURRENCY_CODES: string[];
|
|
3
|
+
export declare const symbols: {
|
|
4
|
+
[x: string]: string;
|
|
5
|
+
};
|
|
2
6
|
interface AmountLabelPayload {
|
|
3
7
|
currency: string;
|
|
4
8
|
amount: number;
|
|
5
9
|
currencyLabel?: string;
|
|
6
10
|
currencyExchangeValue?: number;
|
|
7
11
|
}
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
export declare class CurrencyAction {
|
|
12
|
+
export declare class AmountUtil {
|
|
13
|
+
static validateNonDecimalAmount(amount: number, country: string, NonDecimalCountries?: string[]): {
|
|
14
|
+
error: string;
|
|
15
|
+
data?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
data: boolean;
|
|
18
|
+
error?: undefined;
|
|
19
|
+
};
|
|
18
20
|
static createAmountLabel(payload: AmountLabelPayload): string;
|
|
19
21
|
static formatAmountAndCurrency(currency: string, value: any): string;
|
|
20
22
|
static formatAmountAndCurrencyUsingInBuildIntlNumberFormat(currency: string, value: any): string;
|
|
@@ -1,40 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.AmountUtil = exports.symbols = exports.FRANCOPHONE_CURRENCY_CODES = exports.NON_DECIMAL_ACCEPTING_COUNTRIES = void 0;
|
|
7
7
|
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
|
|
8
|
+
exports.NON_DECIMAL_ACCEPTING_COUNTRIES = ["XOF", "XAF", "UGX", "RWF"];
|
|
9
9
|
exports.FRANCOPHONE_CURRENCY_CODES = ['xaf', 'xof'];
|
|
10
|
-
const localeMap = {
|
|
11
|
-
XOF: 'fr',
|
|
12
|
-
XAF: 'fr',
|
|
13
|
-
};
|
|
14
|
-
const createAmountLabel = (payload) => {
|
|
15
|
-
return CurrencyAction.createAmountLabel(payload);
|
|
16
|
-
};
|
|
17
|
-
exports.createAmountLabel = createAmountLabel;
|
|
18
|
-
const formatAmountAndCurrency = (currency, value) => {
|
|
19
|
-
return CurrencyAction.formatAmountAndCurrency(currency, value);
|
|
20
|
-
};
|
|
21
|
-
exports.formatAmountAndCurrency = formatAmountAndCurrency;
|
|
22
|
-
const formatAmountAndCurrencyUsingInBuildIntlNumberFormat = (currency, value) => {
|
|
23
|
-
return CurrencyAction.formatAmountAndCurrencyUsingInBuildIntlNumberFormat(currency, value);
|
|
24
|
-
};
|
|
25
|
-
exports.formatAmountAndCurrencyUsingInBuildIntlNumberFormat = formatAmountAndCurrencyUsingInBuildIntlNumberFormat;
|
|
26
|
-
function validateAmount(currency, amount) {
|
|
27
|
-
return CurrencyAction.validateAmount(currency, amount);
|
|
28
|
-
}
|
|
29
|
-
exports.validateAmount = validateAmount;
|
|
30
|
-
const getCurrencySymbol = (currency) => {
|
|
31
|
-
return CurrencyAction.getCurrencySymbol(currency);
|
|
32
|
-
};
|
|
33
|
-
exports.getCurrencySymbol = getCurrencySymbol;
|
|
34
|
-
function processAmount(currency, amount) {
|
|
35
|
-
return CurrencyAction.processAmount(currency, amount);
|
|
36
|
-
}
|
|
37
|
-
exports.processAmount = processAmount;
|
|
38
10
|
exports.symbols = {
|
|
39
11
|
USD: '$', // US Dollar
|
|
40
12
|
EUR: '€', // Euro
|
|
@@ -56,18 +28,50 @@ exports.symbols = {
|
|
|
56
28
|
XAF: 'FCFA',
|
|
57
29
|
GHS: 'GH₵', //ghana cedis
|
|
58
30
|
};
|
|
59
|
-
|
|
31
|
+
const localeMap = {
|
|
32
|
+
XOF: 'fr',
|
|
33
|
+
XAF: 'fr',
|
|
34
|
+
};
|
|
35
|
+
class AmountUtil {
|
|
36
|
+
static validateNonDecimalAmount(amount, country, NonDecimalCountries) {
|
|
37
|
+
NonDecimalCountries = NonDecimalCountries || exports.NON_DECIMAL_ACCEPTING_COUNTRIES;
|
|
38
|
+
if (!amount)
|
|
39
|
+
return {
|
|
40
|
+
error: "Amount is required"
|
|
41
|
+
};
|
|
42
|
+
if (!country)
|
|
43
|
+
return {
|
|
44
|
+
error: "Country is required"
|
|
45
|
+
};
|
|
46
|
+
if (!Array.isArray(NonDecimalCountries))
|
|
47
|
+
return {
|
|
48
|
+
error: "NonDecimalCountries is required as an array"
|
|
49
|
+
};
|
|
50
|
+
//check if amount has decimal
|
|
51
|
+
const amountDividedBy100 = new bignumber_js_1.default(amount).dividedBy(100).toNumber();
|
|
52
|
+
if (amountDividedBy100 % 1 === 0)
|
|
53
|
+
return {
|
|
54
|
+
data: true //amount has no decimal place
|
|
55
|
+
};
|
|
56
|
+
if (!NonDecimalCountries.includes(country))
|
|
57
|
+
return {
|
|
58
|
+
data: true
|
|
59
|
+
};
|
|
60
|
+
return {
|
|
61
|
+
error: `${country}: Country Selected is not accepting decimal amount. Countries Not Supporting Decimals are ${NonDecimalCountries.join(", ")}`
|
|
62
|
+
};
|
|
63
|
+
}
|
|
60
64
|
static createAmountLabel(payload) {
|
|
61
65
|
payload.currencyLabel = payload.currencyLabel || payload.currency;
|
|
62
66
|
if (payload.currencyLabel != payload.currency && payload.currencyExchangeValue != 1) {
|
|
63
67
|
const amount = Number(new bignumber_js_1.default(payload.currencyExchangeValue || 1).multipliedBy(payload.amount).toFixed(2));
|
|
64
|
-
return
|
|
68
|
+
return AmountUtil.formatAmountAndCurrency(payload.currencyLabel, Number(amount / 100).toFixed(2));
|
|
65
69
|
}
|
|
66
|
-
return
|
|
70
|
+
return AmountUtil.formatAmountAndCurrency(payload.currency, Number(payload.amount / 100).toFixed(2));
|
|
67
71
|
}
|
|
68
72
|
static formatAmountAndCurrency(currency, value) {
|
|
69
73
|
//get currency symbol
|
|
70
|
-
const currencySymbol =
|
|
74
|
+
const currencySymbol = AmountUtil.getCurrencySymbol(currency);
|
|
71
75
|
if (currency && exports.FRANCOPHONE_CURRENCY_CODES.includes(currency.toLowerCase()))
|
|
72
76
|
return `${parseFloat(value || 0)
|
|
73
77
|
.toFixed(0)
|
|
@@ -86,7 +90,7 @@ class CurrencyAction {
|
|
|
86
90
|
}
|
|
87
91
|
;
|
|
88
92
|
static validateAmount(currency, amount) {
|
|
89
|
-
// return
|
|
93
|
+
// return AmountUtil.validateNonDecimalAmount(amount, currency)
|
|
90
94
|
if (!['XOF', 'XAF'].includes(currency.toUpperCase()))
|
|
91
95
|
return null;
|
|
92
96
|
if (!Number.isInteger(amount / 100)) {
|
|
@@ -106,5 +110,5 @@ class CurrencyAction {
|
|
|
106
110
|
return Math.ceil(amountInLargestCurrency) * 100;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
|
-
exports.
|
|
110
|
-
//# sourceMappingURL=
|
|
113
|
+
exports.AmountUtil = AmountUtil;
|
|
114
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/utils/amount.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAqC;AAExB,QAAA,+BAA+B,GAAG,CAAC,KAAK,EAAE,KAAK,EAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC7D,QAAA,0BAA0B,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC5C,QAAA,OAAO,GAA4B;IAC5C,GAAG,EAAE,GAAG,EAAE,YAAY;IACtB,GAAG,EAAE,GAAG,EAAE,OAAO;IACjB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,GAAG,EAAE,oBAAoB;IAC9B,GAAG,EAAE,GAAG,EAAE,yBAAyB;IACnC,GAAG,EAAE,GAAG,EAAE,qBAAqB;IAC/B,GAAG,EAAE,GAAG,EAAE,eAAe;IACzB,GAAG,EAAE,GAAG,EAAE,eAAe;IACzB,GAAG,EAAE,GAAG,EAAE,mBAAmB;IAC7B,GAAG,EAAE,GAAG,EAAE,iBAAiB;IAC3B,GAAG,EAAE,GAAG,EAAE,kBAAkB;IAC5B,GAAG,EAAE,IAAI,EAAE,eAAe;IAC1B,GAAG,EAAE,GAAG,EAAE,qBAAqB;IAC/B,GAAG,EAAE,GAAG,EAAE,YAAY;IACtB,GAAG,EAAE,GAAG,EAAE,oBAAoB;IAC9B,GAAG,EAAE,GAAG,EAAE,mBAAmB;IAC7B,GAAG,EAAE,OAAO,EAAE,iBAAi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CAAC;aACb,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC;aACxB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACzB,yGAAyG;IAC7G,CAAC;IAAA,CAAC;IAEF,MAAM,CAAC,cAAc,CAAC,QAAgB,EAAE,MAAc;QAClD,+DAA+D;QAC/D,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC;YAAE,OAAO,IAAI,CAAC;QAElE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,yGAAyG,CAAC;QACrH,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,iBAAiB,CAAC,QAAgB;QACrC,OAAO,eAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC;IACzC,CAAC;IAAA,CAAC;IAEF,MAAM,CAAE,aAAa,CAAC,QAAgB,EAAE,MAAc;QAClD,IAAI,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,MAAM,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,gDAAgD,EAAE,MAAM,CAAC,CAAC;QACtE,IAAI,uBAAuB,GAAG,MAAM,GAAG,GAAG,CAAC;QAC3C,OAAO,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,GAAG,GAAG,CAAC;IACpD,CAAC;CACJ;AApFD,gCAoFC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const amount_1 = require("./amount");
|
|
4
4
|
// Mock BigNumber
|
|
5
|
-
describe('
|
|
5
|
+
describe('AmountUtil', () => {
|
|
6
6
|
beforeEach(() => {
|
|
7
7
|
// Clear all mocks before each test
|
|
8
8
|
jest.clearAllMocks();
|
|
@@ -10,72 +10,72 @@ describe('AmountAction', () => {
|
|
|
10
10
|
describe('validateNonDecimalAmount', () => {
|
|
11
11
|
describe('Input Validation', () => {
|
|
12
12
|
it('should return error when amount is not provided', () => {
|
|
13
|
-
const result =
|
|
13
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(0, 'USD');
|
|
14
14
|
expect(result).toEqual({ error: 'Amount is required' });
|
|
15
15
|
});
|
|
16
16
|
it('should return error when country is not provided', () => {
|
|
17
|
-
const result =
|
|
17
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(1000, '');
|
|
18
18
|
expect(result).toEqual({ error: 'Country is required' });
|
|
19
19
|
});
|
|
20
20
|
it('should return error when NonDecimalCountries is provided but not as an array', () => {
|
|
21
|
-
const result =
|
|
21
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(1000, 'USD', 'NOT_AN_ARRAY');
|
|
22
22
|
expect(result).toEqual({ error: 'NonDecimalCountries is required as an array' });
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
describe('Default NON_DECIMAL_ACCEPTING_COUNTRIES', () => {
|
|
26
26
|
it('should use default NON_DECIMAL_ACCEPTING_COUNTRIES when not provided', () => {
|
|
27
|
-
const result =
|
|
27
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(1000, 'XOF');
|
|
28
28
|
expect(result.data).toEqual(true);
|
|
29
29
|
});
|
|
30
30
|
it('should use custom NonDecimalCountries when provided', () => {
|
|
31
31
|
const customCountries = ['ABC', 'DEF'];
|
|
32
|
-
const result =
|
|
32
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(1000, 'ABC', customCountries);
|
|
33
33
|
expect(result.data).toEqual(true);
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
describe('Amount Validation', () => {
|
|
37
37
|
it('should accept non-decimal amounts for non-decimal accepting countries', () => {
|
|
38
38
|
// Amount 10000 cents = 100.00 (no decimal after division by 100)
|
|
39
|
-
const result =
|
|
39
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(10000, 'KES');
|
|
40
40
|
expect(result).toEqual({ data: true });
|
|
41
41
|
});
|
|
42
42
|
it('should reject decimal amounts for non-decimal accepting countries', () => {
|
|
43
|
-
const result =
|
|
43
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(10050, 'XOF');
|
|
44
44
|
expect(result).toEqual({
|
|
45
|
-
error: '
|
|
45
|
+
error: 'XOF: Country Selected is not accepting decimal amount. Countries Not Supporting Decimals are XOF, XAF, UGX, RWF'
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
it('should accept decimal amounts for decimal-accepting countries', () => {
|
|
49
|
-
const result =
|
|
49
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(10050, 'USD');
|
|
50
50
|
expect(result).toEqual({ data: true });
|
|
51
51
|
});
|
|
52
52
|
it('should accept non-decimal amounts for decimal-accepting countries', () => {
|
|
53
53
|
// Amount 10000 cents = 100.00 (no decimal after division by 100)
|
|
54
|
-
const result =
|
|
54
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(10000, 'USD');
|
|
55
55
|
expect(result).toEqual({ data: true });
|
|
56
56
|
});
|
|
57
57
|
});
|
|
58
58
|
describe('Edge Cases', () => {
|
|
59
59
|
it('should handle very large numbers correctly', () => {
|
|
60
60
|
const largeAmount = Number.MAX_SAFE_INTEGER;
|
|
61
|
-
const result =
|
|
61
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(largeAmount, 'USD');
|
|
62
62
|
expect(result).toEqual({ data: true });
|
|
63
63
|
});
|
|
64
64
|
it('should handle very small numbers correctly', () => {
|
|
65
65
|
const smallAmount = 1;
|
|
66
|
-
const result =
|
|
66
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(smallAmount, 'USD');
|
|
67
67
|
expect(result).toEqual({ data: true });
|
|
68
68
|
});
|
|
69
69
|
it('should handle negative numbers', () => {
|
|
70
70
|
const negativeAmount = -1000;
|
|
71
|
-
const result =
|
|
71
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(negativeAmount, 'USD');
|
|
72
72
|
expect(result).toEqual({ data: true });
|
|
73
73
|
});
|
|
74
74
|
it('should handle empty custom NonDecimalCountries array', () => {
|
|
75
|
-
const result =
|
|
75
|
+
const result = amount_1.AmountUtil.validateNonDecimalAmount(1000, 'KES', []);
|
|
76
76
|
expect(result).toEqual({ data: true });
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
-
//# sourceMappingURL=amount.
|
|
81
|
+
//# sourceMappingURL=amount.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.test.js","sourceRoot":"","sources":["../../src/utils/amount.test.ts"],"names":[],"mappings":";;AAAA,qCAAsC;AAEtC,iBAAiB;AACjB,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,UAAU,CAAC,GAAG,EAAE;QACd,mCAAmC;QACnC,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;QACxC,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;YAChC,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;gBACzD,MAAM,MAAM,GAAG,mBAAU,CAAC,wBAAwB,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;gBAC7D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;gBAC1D,MAAM,MAAM,GAAG,mBAAU,CAAC,wBAAwB,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC7D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC,CAAC;YAC3D,CAAC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AE,KAAK,CAAC,CAAC;gBACvE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE;gBACxC,MAAM,cAAc,GAAG,CAAC,IAAI,CAAC;gBAC7B,MAAM,MAAM,GAAG,mBAAU,CAAC,wBAAwB,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;gBAC1E,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;YAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;gBAC9D,MAAM,MAAM,GAAG,mBAAU,CAAC,wBAAwB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;gBACpE,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -15,6 +15,6 @@ export declare class ObjectToMongoDBQueryResult {
|
|
|
15
15
|
filter: any;
|
|
16
16
|
sort: any;
|
|
17
17
|
}
|
|
18
|
-
export declare class
|
|
18
|
+
export declare class DatabaseUtil {
|
|
19
19
|
static resolveObjectToMongoDBQuery(requestQuery: Record<string, any>, options?: ObjectToMongoDBQueryOption): ObjectToMongoDBQueryResult;
|
|
20
20
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
6
|
+
exports.DatabaseUtil = exports.ObjectToMongoDBQueryResult = exports.ObjectToMongoDBQueryOption = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
5
8
|
const lodash_1 = require("lodash");
|
|
6
9
|
/**
|
|
7
10
|
* @description resolveRequestQueryToMongoDBQuery
|
|
@@ -24,7 +27,7 @@ class ObjectToMongoDBQueryResult {
|
|
|
24
27
|
}
|
|
25
28
|
}
|
|
26
29
|
exports.ObjectToMongoDBQueryResult = ObjectToMongoDBQueryResult;
|
|
27
|
-
class
|
|
30
|
+
class DatabaseUtil {
|
|
28
31
|
static resolveObjectToMongoDBQuery(requestQuery, options) {
|
|
29
32
|
var _a, _b, _c, _d;
|
|
30
33
|
if (!options) {
|
|
@@ -58,11 +61,11 @@ class DatabaseAction {
|
|
|
58
61
|
continue;
|
|
59
62
|
}
|
|
60
63
|
if (key === 'dateFrom' && !(0, lodash_1.isEmpty)(requestQuery[key])) {
|
|
61
|
-
response.filter[options.dateField || 'createdAt'] = Object.assign(Object.assign({}, response.filter[options.dateField || 'createdAt']), { $gte: (0,
|
|
64
|
+
response.filter[options.dateField || 'createdAt'] = Object.assign(Object.assign({}, response.filter[options.dateField || 'createdAt']), { $gte: (0, dayjs_1.default)(requestQuery[key] || new Date(), (_b = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _b !== void 0 ? _b : 'DD-MM-YYYY').startOf('day').toDate() });
|
|
62
65
|
continue;
|
|
63
66
|
}
|
|
64
67
|
if (key === 'dateTo' && !(0, lodash_1.isEmpty)(requestQuery[key])) {
|
|
65
|
-
response.filter[options.dateField || 'createdAt'] = Object.assign(Object.assign({}, response.filter[options.dateField || 'createdAt']), { $lte: (0,
|
|
68
|
+
response.filter[options.dateField || 'createdAt'] = Object.assign(Object.assign({}, response.filter[options.dateField || 'createdAt']), { $lte: (0, dayjs_1.default)(requestQuery[key] || new Date(), (_c = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _c !== void 0 ? _c : 'DD-MM-YYYY').endOf('day').toDate() });
|
|
66
69
|
continue;
|
|
67
70
|
}
|
|
68
71
|
//query
|
|
@@ -86,5 +89,5 @@ class DatabaseAction {
|
|
|
86
89
|
return response;
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
|
-
exports.
|
|
90
|
-
//# sourceMappingURL=database.
|
|
92
|
+
exports.DatabaseUtil = DatabaseUtil;
|
|
93
|
+
//# sourceMappingURL=database.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/utils/database.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,mCAAiC;AAEjC;;;;GAIG;AAEH,MAAa,0BAA0B;IAAvC;QACI,cAAS,GAAY,WAAW,CAAC;QACjC,eAAU,GAAY,GAAG,CAAA;IAE7B,CAAC;CAAA;AAJD,gEAIC;AAED,MAAa,0BAA0B;IAAvC;QACI,SAAI,GAAY,CAAC,CAAC;QAClB,UAAK,GAAY,EAAE,CAAC;QAEpB,WAAM,GAAQ,EAAE,CAAC;QACjB,SAAI,GAAQ,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;IAC5B,CAAC;CAAA;AAND,gEAMC;AAGD,MAAa,YAAY;IACrB,MAAM,CAAC,2BAA2B,CAAC,YAAiC,EAAE,OAAoC;;QACtG,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,GAAG;gBACN,SAAS,EAAE,WAAW;aACzB,CAAC;QACN,CAAC;QAED,MAAM,QAAQ,GAA+B;YACzC,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,EAAE;YACT,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;SACpB,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;YAC1C,IAAI,GAAG,KAAK,MAAM,EAAE,CA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