@konplit-services/common 1.0.124 → 1.0.126
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,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* this algorithm is called the luhn algorigth for validating the validity of a card
|
|
4
|
+
* @param cardNumber the card number as string
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.cardValidate = void 0;
|
|
9
|
+
const cardValidate = (cardNumber) => {
|
|
10
|
+
let sum = 0;
|
|
11
|
+
let shouldDouble = false;
|
|
12
|
+
for (let i = cardNumber.length - 1; i >= 0; i--) {
|
|
13
|
+
let digit = parseInt(cardNumber[i], 10);
|
|
14
|
+
if (isNaN(digit)) {
|
|
15
|
+
throw new Error(`Invalid character '${cardNumber[i]}' in card number.`);
|
|
16
|
+
}
|
|
17
|
+
if (shouldDouble) {
|
|
18
|
+
digit *= 2;
|
|
19
|
+
if (digit > 9)
|
|
20
|
+
digit -= 9;
|
|
21
|
+
}
|
|
22
|
+
sum += digit;
|
|
23
|
+
shouldDouble = !shouldDouble;
|
|
24
|
+
}
|
|
25
|
+
return sum % 10 === 0;
|
|
26
|
+
};
|
|
27
|
+
exports.cardValidate = cardValidate;
|
package/build/helper/index.d.ts
CHANGED
package/build/helper/index.js
CHANGED
|
@@ -54,3 +54,4 @@ __exportStar(require("./worker-task-types"), exports);
|
|
|
54
54
|
__exportStar(require("./api-config-types"), exports);
|
|
55
55
|
__exportStar(require("./settings-types"), exports);
|
|
56
56
|
__exportStar(require("./business-types"), exports);
|
|
57
|
+
__exportStar(require("./card-validate"), exports);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import { JWT_Data } from "../services/Jwt";
|
|
3
|
+
import { USER_TYPES } from "../helper";
|
|
3
4
|
declare global {
|
|
4
5
|
namespace Express {
|
|
5
6
|
interface Request {
|
|
@@ -7,4 +8,4 @@ declare global {
|
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
10
|
}
|
|
10
|
-
export declare const hasPermission: (permissionCode: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
11
|
+
export declare const hasPermission: (userType: USER_TYPES, permissionCode: string) => (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
@@ -16,13 +16,16 @@ const error_codes_1 = require("../helper/errorCodes/error-codes");
|
|
|
16
16
|
const language_1 = require("../helper/lang/language");
|
|
17
17
|
const base_1 = require("../redis/base");
|
|
18
18
|
const constants_1 = require("../redis/constants");
|
|
19
|
-
const hasPermission = (permissionCode) => {
|
|
19
|
+
const hasPermission = (userType, permissionCode) => {
|
|
20
20
|
return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
21
|
//comment
|
|
22
22
|
if (!req.currentUser) {
|
|
23
23
|
throw new notAuthorized_1.NotAuthorizedError(language_1.lang.not_authorized, error_codes_1.error_codes.INVALID_AUTHORIZATION);
|
|
24
24
|
}
|
|
25
25
|
const user = req.currentUser;
|
|
26
|
+
if (userType !== user.userType) {
|
|
27
|
+
throw new forbidden_error_1.ForbiddenError(language_1.lang.forbidden, error_codes_1.error_codes.INVALID_FORBIDDEN);
|
|
28
|
+
}
|
|
26
29
|
try {
|
|
27
30
|
let permissions = [];
|
|
28
31
|
const perm = yield base_1.redisWrapper.get((0, constants_1.getPermissions)(user.id));
|