@molochko-dev/data 1.4.29 → 1.4.30
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.
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
import { IAnimal } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
export declare
|
|
4
|
-
animals: IAnimal[];
|
|
5
|
-
eventType: EVENT_TYPES_ENUM;
|
|
6
|
-
constructor(animals: IAnimal[], eventType: EVENT_TYPES_ENUM);
|
|
7
|
-
genderFilter(animal: IAnimal, availableGender: ANIMAL_GENDER_ENUM): Boolean;
|
|
8
|
-
ageFilter(animal: IAnimal, availableMinAge: number): Boolean;
|
|
9
|
-
statusFilter(animal: IAnimal, availableStatuses: ANIMAL_STATUS_ENUM[]): Boolean;
|
|
10
|
-
abortFilter(): IAnimal[];
|
|
11
|
-
neosemFilter(): IAnimal[];
|
|
12
|
-
osemenenieFilter(): IAnimal[];
|
|
13
|
-
otelFilter(): IAnimal[];
|
|
14
|
-
recheckFilter(): IAnimal[];
|
|
15
|
-
suhostoiFilter(): IAnimal[];
|
|
16
|
-
pozSuhostoiFilter(): IAnimal[];
|
|
17
|
-
outputFilter(): IAnimal[];
|
|
18
|
-
filter(): IAnimal[];
|
|
19
|
-
}
|
|
2
|
+
import { EVENT_TYPES_ENUM } from '../enums';
|
|
3
|
+
export declare function filter(animals: IAnimal[], eventType: EVENT_TYPES_ENUM): IAnimal[];
|
|
@@ -1,168 +1,105 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filter = void 0;
|
|
4
4
|
const enums_1 = require("../enums");
|
|
5
5
|
const date_1 = require("../helpers/date");
|
|
6
6
|
const status = enums_1.ANIMAL_STATUS_ENUM;
|
|
7
7
|
const defaultCowAge = 12;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (genderOk && statusOk && ageOk) {
|
|
60
|
-
result.push(animal);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
otelFilter() {
|
|
66
|
-
const result = [];
|
|
67
|
-
this.animals.forEach(animal => {
|
|
68
|
-
let genderOk = false;
|
|
69
|
-
let statusOk = false;
|
|
70
|
-
let ageOk = false;
|
|
71
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
72
|
-
genderOk = true;
|
|
73
|
-
}
|
|
74
|
-
if (this.statusFilter(animal, [status.dry, status.pregnant])) {
|
|
75
|
-
statusOk = true;
|
|
76
|
-
}
|
|
77
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
78
|
-
ageOk = true;
|
|
79
|
-
}
|
|
80
|
-
if (genderOk && statusOk && ageOk) {
|
|
81
|
-
result.push(animal);
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
return result;
|
|
85
|
-
}
|
|
86
|
-
recheckFilter() {
|
|
87
|
-
const result = [];
|
|
88
|
-
this.animals.forEach(animal => {
|
|
89
|
-
let genderOk = false;
|
|
90
|
-
let statusOk = false;
|
|
91
|
-
let ageOk = false;
|
|
92
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
93
|
-
genderOk = true;
|
|
94
|
-
}
|
|
95
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
96
|
-
ageOk = true;
|
|
97
|
-
}
|
|
98
|
-
let availableStatus = [status.bred, status.pregnant, status.dry];
|
|
99
|
-
if (animal.animalEventRelation) {
|
|
100
|
-
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
101
|
-
return row.eventDetail.type === enums_1.EVENT_TYPES_ENUM.recheck;
|
|
102
|
-
});
|
|
103
|
-
if (previousRechecks.length == 0) {
|
|
104
|
-
availableStatus = [status.bred];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (this.statusFilter(animal, availableStatus)) {
|
|
108
|
-
statusOk = true;
|
|
109
|
-
}
|
|
110
|
-
if (genderOk && statusOk && ageOk) {
|
|
111
|
-
result.push(animal);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
return result;
|
|
115
|
-
}
|
|
116
|
-
suhostoiFilter() {
|
|
117
|
-
return this.abortFilter();
|
|
118
|
-
}
|
|
119
|
-
pozSuhostoiFilter() {
|
|
120
|
-
const result = [];
|
|
121
|
-
this.animals.forEach(animal => {
|
|
122
|
-
let genderOk = false;
|
|
123
|
-
let statusOk = false;
|
|
124
|
-
let ageOk = false;
|
|
125
|
-
if (this.genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow)) {
|
|
126
|
-
genderOk = true;
|
|
127
|
-
}
|
|
128
|
-
if (this.statusFilter(animal, [status.dry])) {
|
|
129
|
-
statusOk = true;
|
|
130
|
-
}
|
|
131
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
132
|
-
ageOk = true;
|
|
133
|
-
}
|
|
134
|
-
if (genderOk && statusOk && ageOk) {
|
|
135
|
-
result.push(animal);
|
|
8
|
+
/*
|
|
9
|
+
|
|
10
|
+
const filtered = filter(animals, eventType)
|
|
11
|
+
|
|
12
|
+
*/
|
|
13
|
+
function genderFilter(animal, availableGender) {
|
|
14
|
+
return animal.gender === availableGender;
|
|
15
|
+
}
|
|
16
|
+
function ageFilter(animal, availableMinAge /*month*/) {
|
|
17
|
+
const months = (0, date_1.getMonthFromDate)(animal.dob.toISOString());
|
|
18
|
+
return months > availableMinAge;
|
|
19
|
+
}
|
|
20
|
+
function statusFilter(animal, availableStatuses) {
|
|
21
|
+
return availableStatuses.includes(animal.status);
|
|
22
|
+
}
|
|
23
|
+
function abortFilter(animals) {
|
|
24
|
+
const result = animals.filter(animal => genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow));
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
function neosemFilter(animals) {
|
|
28
|
+
return abortFilter(animals);
|
|
29
|
+
}
|
|
30
|
+
function osemenenieFilter(animals) {
|
|
31
|
+
const result = animals.filter(animal => {
|
|
32
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
33
|
+
const statusOk = statusFilter(animal, [status.heifer, status.bred, status.open, status.fresh]);
|
|
34
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
35
|
+
return genderOk && statusOk && ageOk && animal;
|
|
36
|
+
});
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
function otelFilter(animals) {
|
|
40
|
+
const result = animals.filter(animal => {
|
|
41
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
42
|
+
const statusOk = statusFilter(animal, [status.dry, status.pregnant]);
|
|
43
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
44
|
+
return genderOk && statusOk && ageOk && animal;
|
|
45
|
+
});
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function recheckFilter(animals) {
|
|
49
|
+
const result = animals.filter(animal => {
|
|
50
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
51
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
52
|
+
let availableStatus = [status.bred, status.pregnant, status.dry];
|
|
53
|
+
if (animal.animalEventRelation) {
|
|
54
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
55
|
+
return row.eventDetail.type === enums_1.EVENT_TYPES_ENUM.recheck;
|
|
56
|
+
});
|
|
57
|
+
if (previousRechecks.length == 0) {
|
|
58
|
+
availableStatus = [status.bred];
|
|
136
59
|
}
|
|
137
|
-
}
|
|
60
|
+
}
|
|
61
|
+
const statusOk = statusFilter(animal, availableStatus);
|
|
62
|
+
return genderOk && statusOk && ageOk && animal;
|
|
63
|
+
});
|
|
64
|
+
console.info('result', result);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
function suhostoiFilter(animals) {
|
|
68
|
+
return abortFilter(animals);
|
|
69
|
+
}
|
|
70
|
+
function pozSuhostoiFilter(animals) {
|
|
71
|
+
const result = animals.filter(animal => {
|
|
72
|
+
const genderOk = genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow);
|
|
73
|
+
const statusOk = statusFilter(animal, [status.dry]);
|
|
74
|
+
const ageOk = ageFilter(animal, defaultCowAge);
|
|
75
|
+
return genderOk && statusOk && ageOk && animal;
|
|
76
|
+
});
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
function transferOutFilter(animals) {
|
|
80
|
+
return animals;
|
|
81
|
+
}
|
|
82
|
+
function perevodFilter(animals) {
|
|
83
|
+
return animals;
|
|
84
|
+
}
|
|
85
|
+
function filter(animals, eventType) {
|
|
86
|
+
const filters = {
|
|
87
|
+
[enums_1.EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
88
|
+
[enums_1.EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
89
|
+
[enums_1.EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
90
|
+
[enums_1.EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
91
|
+
[enums_1.EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
92
|
+
[enums_1.EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
93
|
+
[enums_1.EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
94
|
+
[enums_1.EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
95
|
+
[enums_1.EVENT_TYPES_ENUM.transferOut]: transferOutFilter
|
|
96
|
+
};
|
|
97
|
+
try {
|
|
98
|
+
const result = filters[eventType](animals);
|
|
138
99
|
return result;
|
|
139
100
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
filter() {
|
|
144
|
-
switch (this.eventType) {
|
|
145
|
-
case enums_1.EVENT_TYPES_ENUM.abort:
|
|
146
|
-
return this.abortFilter();
|
|
147
|
-
case enums_1.EVENT_TYPES_ENUM.neosem:
|
|
148
|
-
return this.neosemFilter();
|
|
149
|
-
case enums_1.EVENT_TYPES_ENUM.osemenenie:
|
|
150
|
-
return this.osemenenieFilter();
|
|
151
|
-
case enums_1.EVENT_TYPES_ENUM.otel:
|
|
152
|
-
return this.otelFilter();
|
|
153
|
-
case enums_1.EVENT_TYPES_ENUM.recheck:
|
|
154
|
-
return this.recheckFilter();
|
|
155
|
-
case enums_1.EVENT_TYPES_ENUM.suhostoi:
|
|
156
|
-
return this.suhostoiFilter();
|
|
157
|
-
case enums_1.EVENT_TYPES_ENUM.pozSuhostoi:
|
|
158
|
-
return this.pozSuhostoiFilter();
|
|
159
|
-
case enums_1.EVENT_TYPES_ENUM.perevod:
|
|
160
|
-
return this.animals;
|
|
161
|
-
case enums_1.EVENT_TYPES_ENUM.transferOut:
|
|
162
|
-
return this.outputFilter();
|
|
163
|
-
default:
|
|
164
|
-
throw new Error(`AnimalForEventFilter.filter.${this.eventType} not implemented`);
|
|
165
|
-
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`);
|
|
166
103
|
}
|
|
167
104
|
}
|
|
168
|
-
exports.
|
|
105
|
+
exports.filter = filter;
|
package/dist/event/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { filter as _filter } from './animal-event-filter';
|
|
2
|
+
export { _filter as filter };
|
package/dist/event/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.filter = void 0;
|
|
4
4
|
const animal_event_filter_1 = require("./animal-event-filter");
|
|
5
|
-
Object.defineProperty(exports, "
|
|
5
|
+
Object.defineProperty(exports, "filter", { enumerable: true, get: function () { return animal_event_filter_1.filter; } });
|
package/package.json
CHANGED
|
@@ -6,184 +6,122 @@ const status = ANIMAL_STATUS_ENUM
|
|
|
6
6
|
|
|
7
7
|
const defaultCowAge = 12
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
animals: IAnimal[]
|
|
11
|
-
eventType: EVENT_TYPES_ENUM
|
|
9
|
+
/*
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
this.animals = animals
|
|
15
|
-
this.eventType = eventType
|
|
16
|
-
}
|
|
11
|
+
const filtered = filter(animals, eventType)
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
if (animal.gender === availableGender) {
|
|
20
|
-
return true
|
|
21
|
-
}
|
|
22
|
-
return false
|
|
23
|
-
}
|
|
13
|
+
*/
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return true
|
|
29
|
-
}
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
15
|
+
function genderFilter (animal: IAnimal, availableGender: ANIMAL_GENDER_ENUM): Boolean {
|
|
16
|
+
return animal.gender === availableGender
|
|
17
|
+
}
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return false
|
|
38
|
-
}
|
|
19
|
+
function ageFilter (animal: IAnimal, availableMinAge: number /*month*/): Boolean {
|
|
20
|
+
const months = getMonthFromDate(animal.dob.toISOString())
|
|
21
|
+
return months > availableMinAge
|
|
22
|
+
}
|
|
39
23
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (this.genderFilter(animal, ANIMAL_GENDER_ENUM.cow)) {
|
|
44
|
-
result.push(animal)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
return result
|
|
48
|
-
}
|
|
24
|
+
function statusFilter (animal: IAnimal, availableStatuses: ANIMAL_STATUS_ENUM[]): Boolean {
|
|
25
|
+
return availableStatuses.includes(animal.status)
|
|
26
|
+
}
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
function abortFilter (animals: IAnimal[]): IAnimal[] {
|
|
29
|
+
const result: IAnimal[] = animals.filter(animal => genderFilter(animal, ANIMAL_GENDER_ENUM.cow))
|
|
30
|
+
return result
|
|
31
|
+
}
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
let genderOk = false
|
|
58
|
-
let statusOk = false
|
|
59
|
-
let ageOk = false
|
|
33
|
+
function neosemFilter (animals: IAnimal[]): IAnimal[] {
|
|
34
|
+
return abortFilter(animals)
|
|
35
|
+
}
|
|
60
36
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
68
|
-
ageOk = true
|
|
69
|
-
}
|
|
70
|
-
if (genderOk && statusOk && ageOk) {
|
|
71
|
-
result.push(animal)
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
return result
|
|
75
|
-
}
|
|
37
|
+
function osemenenieFilter(animals: IAnimal[]): IAnimal[] {
|
|
38
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
39
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
40
|
+
const statusOk = statusFilter(animal, [status.heifer, status.bred, status.open, status.fresh])
|
|
41
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
76
42
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.animals.forEach(animal => {
|
|
80
|
-
let genderOk = false
|
|
81
|
-
let statusOk = false
|
|
82
|
-
let ageOk = false
|
|
43
|
+
return genderOk && statusOk && ageOk && animal
|
|
44
|
+
})
|
|
83
45
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
if (this.statusFilter(animal, [status.dry, status.pregnant])) {
|
|
88
|
-
statusOk = true
|
|
89
|
-
}
|
|
90
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
91
|
-
ageOk = true
|
|
92
|
-
}
|
|
93
|
-
if (genderOk && statusOk && ageOk) {
|
|
94
|
-
result.push(animal)
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
return result
|
|
98
|
-
}
|
|
46
|
+
return result
|
|
47
|
+
}
|
|
99
48
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
let ageOk = false
|
|
49
|
+
function otelFilter (animals: IAnimal[]): IAnimal[] {
|
|
50
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
51
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
52
|
+
const statusOk = statusFilter(animal, [status.dry, status.pregnant])
|
|
53
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
106
54
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
ageOk = true
|
|
112
|
-
}
|
|
55
|
+
return genderOk && statusOk && ageOk && animal
|
|
56
|
+
})
|
|
57
|
+
return result
|
|
58
|
+
}
|
|
113
59
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
60
|
+
function recheckFilter (animals: IAnimal[]): IAnimal[] {
|
|
61
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
62
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
63
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
64
|
+
|
|
65
|
+
let availableStatus = [status.bred, status.pregnant, status.dry]
|
|
66
|
+
if (animal.animalEventRelation) {
|
|
67
|
+
const previousRechecks = animal.animalEventRelation.filter((row) => {
|
|
68
|
+
return row.eventDetail.type === EVENT_TYPES_ENUM.recheck
|
|
69
|
+
})
|
|
70
|
+
if (previousRechecks.length == 0) {
|
|
71
|
+
availableStatus = [status.bred]
|
|
122
72
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
73
|
+
}
|
|
74
|
+
const statusOk = statusFilter(animal, availableStatus)
|
|
75
|
+
|
|
76
|
+
return genderOk && statusOk && ageOk && animal
|
|
77
|
+
})
|
|
78
|
+
console.info('result', result)
|
|
79
|
+
return result
|
|
80
|
+
}
|
|
132
81
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
82
|
+
function suhostoiFilter (animals: IAnimal[]): IAnimal[] {
|
|
83
|
+
return abortFilter(animals)
|
|
84
|
+
}
|
|
136
85
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let ageOk = false
|
|
86
|
+
function pozSuhostoiFilter (animals: IAnimal[]): IAnimal[] {
|
|
87
|
+
const result: IAnimal[] = animals.filter(animal => {
|
|
88
|
+
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
89
|
+
const statusOk = statusFilter(animal, [status.dry])
|
|
90
|
+
const ageOk = ageFilter(animal, defaultCowAge)
|
|
143
91
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
statusOk = true
|
|
149
|
-
}
|
|
150
|
-
if (this.ageFilter(animal, defaultCowAge)) {
|
|
151
|
-
ageOk = true
|
|
152
|
-
}
|
|
153
|
-
if (genderOk && statusOk && ageOk) {
|
|
154
|
-
result.push(animal)
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
return result
|
|
158
|
-
}
|
|
92
|
+
return genderOk && statusOk && ageOk && animal
|
|
93
|
+
})
|
|
94
|
+
return result
|
|
95
|
+
}
|
|
159
96
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
97
|
+
function transferOutFilter (animals: IAnimal[]): IAnimal[] {
|
|
98
|
+
return animals
|
|
99
|
+
}
|
|
163
100
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
case EVENT_TYPES_ENUM.osemenenie:
|
|
171
|
-
return this.osemenenieFilter()
|
|
172
|
-
case EVENT_TYPES_ENUM.otel:
|
|
173
|
-
return this.otelFilter()
|
|
174
|
-
case EVENT_TYPES_ENUM.recheck:
|
|
175
|
-
return this.recheckFilter()
|
|
176
|
-
case EVENT_TYPES_ENUM.suhostoi:
|
|
177
|
-
return this.suhostoiFilter()
|
|
178
|
-
case EVENT_TYPES_ENUM.pozSuhostoi:
|
|
179
|
-
return this.pozSuhostoiFilter()
|
|
180
|
-
case EVENT_TYPES_ENUM.perevod:
|
|
181
|
-
return this.animals
|
|
182
|
-
case EVENT_TYPES_ENUM.transferOut:
|
|
183
|
-
return this.outputFilter()
|
|
184
|
-
default:
|
|
185
|
-
throw new Error(`AnimalForEventFilter.filter.${this.eventType} not implemented`)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
101
|
+
function perevodFilter (animals: IAnimal[]) {
|
|
102
|
+
return animals
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
interface IFilters {
|
|
106
|
+
[key: string]: (animals: IAnimal[]) => IAnimal[]
|
|
188
107
|
}
|
|
189
108
|
|
|
109
|
+
export function filter (animals: IAnimal[], eventType: EVENT_TYPES_ENUM) {
|
|
110
|
+
const filters: IFilters = {
|
|
111
|
+
[EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
112
|
+
[EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
113
|
+
[EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
|
114
|
+
[EVENT_TYPES_ENUM.otel]: otelFilter,
|
|
115
|
+
[EVENT_TYPES_ENUM.recheck]: recheckFilter,
|
|
116
|
+
[EVENT_TYPES_ENUM.suhostoi]: suhostoiFilter,
|
|
117
|
+
[EVENT_TYPES_ENUM.pozSuhostoi]: pozSuhostoiFilter,
|
|
118
|
+
[EVENT_TYPES_ENUM.perevod]: perevodFilter,
|
|
119
|
+
[EVENT_TYPES_ENUM.transferOut]: transferOutFilter
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const result = filters[eventType](animals)
|
|
123
|
+
return result
|
|
124
|
+
} catch (err) {
|
|
125
|
+
throw new Error(`AnimalForEventFilter.filter.${eventType} not implemented`)
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/event/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { filter as _filter } from './animal-event-filter'
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { _filter as filter }
|