@vidal-community/vidal-web-components
Version:
Vidal Web Components
43 lines • 1.55 kB
JavaScript
export class DrugResultFilter {
constructor(id, sortASC, sortDSC) {
this.id = id;
this.sortASC = sortASC;
this.sortDSC = sortDSC;
}
static from(filter) {
switch (filter) {
case 'NAME': {
return DrugResultFilter.NAME;
}
case 'PRICE': {
return DrugResultFilter.PRICE;
}
}
return DrugResultFilter.NAME;
}
getCorrespondingSort(order) {
if (order === 'ASC') {
return this.sortASC;
}
return this.sortDSC;
}
}
DrugResultFilter.NAME = new DrugResultFilter('NAME', (drug1, drug2) => drug1.label.localeCompare(drug2.label), (drug1, drug2) => drug2.label.localeCompare(drug1.label));
DrugResultFilter.PRICE = new DrugResultFilter('PRICE', (drug1, drug2) => {
var _a, _b;
const price1 = Number((_a = drug1.price) === null || _a === void 0 ? void 0 : _a.min);
const price2 = Number((_b = drug2.price) === null || _b === void 0 ? void 0 : _b.min);
return price1 > price2 ? 1 : price1 == price2 ? 0 : -1;
}, (drug1, drug2) => {
var _a, _b;
const price1 = Number((_a = drug1.price) === null || _a === void 0 ? void 0 : _a.min);
const price2 = Number((_b = drug2.price) === null || _b === void 0 ? void 0 : _b.min);
return price2 > price1 ? 1 : price2 == price1 ? 0 : -1;
});
export class SortState {
constructor(column, order) {
this.column = column;
this.order = order;
}
}
//# sourceMappingURL=drug-result-filters.js.map