purespectrum-lib
Version:
shared code between front and backend projects
62 lines • 2.97 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChildrenLabelMapper = void 0;
var qualification_codes_1 = require("../../shared/qualification-codes");
var quota_mapper_constants_1 = require("./quota-mapper.constants");
var child_1 = require("../child/child");
var children_1 = require("../children/children");
var ChildrenLabelMapper = /** @class */ (function () {
function ChildrenLabelMapper(conditionCodes, unit) {
if (unit === void 0) { unit = quota_mapper_constants_1.YEARS_CHILD_AGE_UNIT_CODE; }
this._conditionCodes = conditionCodes;
this._ageUnit = unit;
this._childs = this._conditionCodes.map(function (code) { return new child_1.Child(Number(code)); });
this._childrens = new children_1.Children(this._childs, this._ageUnit);
}
ChildrenLabelMapper.prototype.label = function () {
var noChildrenExist = this._conditionCodes.includes(qualification_codes_1.CHILD_AGE_GENDER.NO_CHILDREN_CHILD_AGE_QUOTA);
if (noChildrenExist && this._conditionCodes.length === 1) {
return 'No Children';
}
return "".concat(this._audiance(), ", Have Children, ").concat(this.from(), " - ").concat(this.to(), ", ").concat(this._timeUnit()).concat(noChildrenExist ? ', No Children' : '');
};
ChildrenLabelMapper.prototype._audiance = function () {
if (this._haveBoy() && this._haveGirl()) {
return 'Either';
}
if (this._haveBoy()) {
return 'Boy';
}
return 'Girl';
};
ChildrenLabelMapper.prototype._timeUnit = function () {
return this._ageUnit === quota_mapper_constants_1.YEARS_CHILD_AGE_UNIT_CODE ? 'Years' : 'Months';
};
ChildrenLabelMapper.prototype.min = function () {
return this._childrens.age.from;
};
ChildrenLabelMapper.prototype.max = function () {
return this._childrens.age.to;
};
ChildrenLabelMapper.prototype.to = function () {
return this.max();
};
ChildrenLabelMapper.prototype.from = function () {
return this.min();
};
ChildrenLabelMapper.prototype._haveGirl = function () {
return this._conditionCodes.some(this._isGirlConditionCode);
};
ChildrenLabelMapper.prototype._haveBoy = function () {
return this._conditionCodes.some(this._isBoyConditionCode);
};
ChildrenLabelMapper.prototype._isBoyConditionCode = function (conditionCode) {
return qualification_codes_1.CHILD_AGE_GENDER.BOYS_CONDITIONS_CODES.some(function (code) { return code === conditionCode; });
};
ChildrenLabelMapper.prototype._isGirlConditionCode = function (conditionCode) {
return qualification_codes_1.CHILD_AGE_GENDER.GIRLS_CONDITIONS_CODES.some(function (code) { return code === conditionCode; });
};
return ChildrenLabelMapper;
}());
exports.ChildrenLabelMapper = ChildrenLabelMapper;
//# sourceMappingURL=children-label-mapper.js.map