UNPKG

purespectrum-lib

Version:

shared code between front and backend projects

111 lines 4.36 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Child = void 0; var qualification_codes_1 = require("../../shared/qualification-codes"); var child_age_gender_mapper_constants_1 = require("../child-age-gender-mapper.constants"); /** * Core mapper class for new child age gender qualification. * A instance of this class represent one child, its age, gender and * the new condition code that represents it. * This class use new child age gender condition code to determine child age and gender. */ var Child = /** @class */ (function () { /** * Create a new Child from a new child gender age condition code. */ function Child(code) { if (code < child_age_gender_mapper_constants_1.START_CHILD_AGE_CODE || code > child_age_gender_mapper_constants_1.END_CHILD_AGE_CODE) { throw new Error('Child, gender and age criterias code is out of the range of mapped codes'); } this.code = code; } /** * Create a new Child from criterias * @param {boolean} isBaby - true for baby ages, meaning months from 1 to 11. * false for child ages, meaning years from 1 to 17. * @param {boolean} isBoy - child gender: true for boy or false for girl. * @param {number} age - child age. * @returns a new Child instance */ Child.create = function (isBaby, isBoy, age) { var condition_code = qualification_codes_1.CHILD_AGE_GENDER.ALL_CONDITIONS_CODES.find(function (condition_code) { return condition_code.age === age && condition_code.isBaby === isBaby && condition_code.isBoy === isBoy; }); if (!condition_code) { throw new Error("Invalid baby age informed: ".concat(age)); } return new Child(condition_code.code); }; Child.createNoChildren = function () { return new Child(child_age_gender_mapper_constants_1.NO_CHILDREN_CODE); }; Object.defineProperty(Child.prototype, "noChildren", { get: function () { return this.code === child_age_gender_mapper_constants_1.NO_CHILDREN_CODE; }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "isBaby", { get: function () { var _this = this; var _a; return (((_a = qualification_codes_1.CHILD_AGE_GENDER.ALL_CONDITIONS_CODES.find(function (_a) { var code = _a.code; return _this.code === code; })) === null || _a === void 0 ? void 0 : _a.isBaby) || false); }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "isBoy", { get: function () { var _this = this; var _a; return (((_a = qualification_codes_1.CHILD_AGE_GENDER.ALL_CONDITIONS_CODES.find(function (_a) { var code = _a.code; return _this.code === code; })) === null || _a === void 0 ? void 0 : _a.isBoy) || false); }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "age", { get: function () { var _this = this; var _a, _b; return ((_b = (_a = qualification_codes_1.CHILD_AGE_GENDER.ALL_CONDITIONS_CODES.find(function (_a) { var code = _a.code; return _this.code === code; })) === null || _a === void 0 ? void 0 : _a.age) !== null && _b !== void 0 ? _b : 0); }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "ageUnit", { get: function () { return this.isBaby ? 'Months' : 'Year'; }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "gender", { get: function () { return this.isBoy ? 'Boy' : 'Girl'; }, enumerable: false, configurable: true }); Object.defineProperty(Child.prototype, "ageWithUnit", { get: function () { return "".concat(this.age, " ").concat(this.ageUnit); }, enumerable: false, configurable: true }); return Child; }()); exports.Child = Child; //# sourceMappingURL=child.js.map