UNPKG

phx-node

Version:

PHX NODE

102 lines 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PHXConvertHeadersRequest = exports.generateValue = exports.sumTotalFee = exports.getTotalDetailPromoByCode = exports.findAdjustmentForOtherService = exports.findAdjustmentForTuition = exports.parseToObject = exports.prevYearDate = exports.nextYearDate = exports.timeYearActive = void 0; const constant_1 = require("./constant"); const tuition_1 = require("./types/tuition"); exports.timeYearActive = new Date().toISOString().slice(0, 10); const nextYear = new Date(); nextYear.setFullYear(nextYear.getFullYear() + 1); exports.nextYearDate = nextYear.toISOString().slice(0, 10); const prevYear = new Date(); prevYear.setFullYear(prevYear.getFullYear() - 1); exports.prevYearDate = prevYear.toISOString().slice(0, 10); const parseToObject = (value) => { return value .split("\n") .filter((line) => line.trim() && !line.startsWith("#")) .reduce((acc, line) => { const [key, value] = line.split("="); if (key && value) { acc[key.trim()] = value.trim(); } return acc; }, {}); }; exports.parseToObject = parseToObject; const findAdjustmentForTuition = (list_detail_fee_adjustment) => { const listAdjustmentFeeForTuition = list_detail_fee_adjustment.filter(({ tuition_fee_adjustment: { fee_type_code, tuition_fee_project_code: { tuition_fee_type_of_service: { type_code }, }, }, }) => { const isDescFee = fee_type_code === tuition_1.FEE_TYPE.DESC; return isDescFee && type_code === constant_1.CODE_TUITION; }); return listAdjustmentFeeForTuition; }; exports.findAdjustmentForTuition = findAdjustmentForTuition; const findAdjustmentForOtherService = (list_detail_fee_adjustment) => { const listAdjustmentFeeForOtherService = list_detail_fee_adjustment.filter(({ tuition_fee_adjustment: { fee_type_code, tuition_fee_project_code: { tuition_fee_type_of_service: { type_code }, }, }, }) => { const isDescFee = fee_type_code === tuition_1.FEE_TYPE.DESC; return isDescFee && type_code !== constant_1.CODE_TUITION; }); return listAdjustmentFeeForOtherService; }; exports.findAdjustmentForOtherService = findAdjustmentForOtherService; const getTotalDetailPromoByCode = (list_detail_promo, code) => { const admissionPromoForTuition = list_detail_promo.filter((item) => (item === null || item === void 0 ? void 0 : item.code) === code); return (0, exports.sumTotalFee)(admissionPromoForTuition); }; exports.getTotalDetailPromoByCode = getTotalDetailPromoByCode; const sumTotalFee = (listFee, isFeeAdjustment = false) => { var _a; const listFeeLength = listFee.length; if (listFeeLength === 0) return 0; let sumTotalFee = 0; for (const feeItem of listFee) { let totalPromo = 0; if (isFeeAdjustment) { totalPromo = ((_a = feeItem === null || feeItem === void 0 ? void 0 : feeItem.tuition_fee_adjustment) === null || _a === void 0 ? void 0 : _a.total_fee) || 0; } else { totalPromo = (feeItem === null || feeItem === void 0 ? void 0 : feeItem.total_promo) || (feeItem === null || feeItem === void 0 ? void 0 : feeItem.value) || 0; } sumTotalFee += totalPromo; } return sumTotalFee; }; exports.sumTotalFee = sumTotalFee; const generateValue = (value) => { if (!value) return 0; return Math.abs(value); }; exports.generateValue = generateValue; const PHXConvertHeadersRequest = (headers) => { const parseSchoolsHeader = (data) => { if (!data || data === "{null: null}") return; const schoolsHeaderToJsonString = data .replace(/(\d+):/g, '"$1":') .replace(/:\s*(https?:\/\/[^,}]+)/g, ':"$1"'); const result = JSON.parse(schoolsHeaderToJsonString); return Object.entries(result).map(([userId, hostname]) => ({ user_id: Number(userId), hostname: String(hostname), })); }; return { authorizationId: Number(headers["authorization-id"]), appId: headers["app-id"], app: headers["app"], hostname: headers["hostname"], phoneNumber: headers["phone-number"], parentId: Number(headers["parent-id"]), studentId: Number(headers["student-id"]), language: headers["language"], os: headers["os"], osVersion: headers["os-version"], deviceModel: headers["device-model"], deviceId: headers["device-id"], listUserSchool: parseSchoolsHeader(headers["hostnames-and-parents-ids"]), }; }; exports.PHXConvertHeadersRequest = PHXConvertHeadersRequest; //# sourceMappingURL=helper.js.map