@molochko-dev/data 1.4.31 → 1.4.32
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,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IAbstractAnimal } from '../types';
|
|
2
2
|
import { EVENT_TYPES_ENUM } from '../enums';
|
|
3
|
-
export declare function filter(animals:
|
|
3
|
+
export declare function filter<T extends IAbstractAnimal>(animals: T[], eventType: EVENT_TYPES_ENUM): T[];
|
|
@@ -10,9 +10,6 @@ const defaultCowAge = 12;
|
|
|
10
10
|
const filtered = filter(animals, eventType)
|
|
11
11
|
|
|
12
12
|
*/
|
|
13
|
-
function genderFilter(animal, availableGender) {
|
|
14
|
-
return animal.gender === availableGender;
|
|
15
|
-
}
|
|
16
13
|
function ageFilter(animal, availableMinAge /*month*/) {
|
|
17
14
|
const months = (0, date_1.getMonthFromDate)(animal.dob.toISOString());
|
|
18
15
|
return months > availableMinAge;
|
|
@@ -20,6 +17,9 @@ function ageFilter(animal, availableMinAge /*month*/) {
|
|
|
20
17
|
function statusFilter(animal, availableStatuses) {
|
|
21
18
|
return availableStatuses.includes(animal.status);
|
|
22
19
|
}
|
|
20
|
+
function genderFilter(animal, availableGender) {
|
|
21
|
+
return animal.gender === availableGender;
|
|
22
|
+
}
|
|
23
23
|
function abortFilter(animals) {
|
|
24
24
|
const result = animals.filter(animal => genderFilter(animal, enums_1.ANIMAL_GENDER_ENUM.cow));
|
|
25
25
|
return result;
|
|
@@ -61,7 +61,6 @@ function recheckFilter(animals) {
|
|
|
61
61
|
const statusOk = statusFilter(animal, availableStatus);
|
|
62
62
|
return genderOk && statusOk && ageOk && animal;
|
|
63
63
|
});
|
|
64
|
-
console.info('result', result);
|
|
65
64
|
return result;
|
|
66
65
|
}
|
|
67
66
|
function suhostoiFilter(animals) {
|
package/dist/types.d.ts
CHANGED
|
@@ -43,3 +43,10 @@ export interface IAnimalEventRelation {
|
|
|
43
43
|
export interface IEventDetail {
|
|
44
44
|
type: EVENT_TYPES_ENUM;
|
|
45
45
|
}
|
|
46
|
+
export declare type IAbstractAnimal = {
|
|
47
|
+
id: string;
|
|
48
|
+
dob: Date;
|
|
49
|
+
gender: ANIMAL_GENDER_ENUM;
|
|
50
|
+
status: ANIMAL_STATUS_ENUM;
|
|
51
|
+
animalEventRelation?: IAnimalEventRelation[];
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molochko-dev/data",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "typings/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"build": "rm -rf dist/ && tsc",
|
|
12
12
|
"test": "jest --config=jest.config.js",
|
|
13
13
|
"format": "prettier --write \"src/**/*.ts\"",
|
|
14
|
-
"pub": "npm run build && npm publish"
|
|
14
|
+
"pub": "npm tes && npm run build && npm publish"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"molochko-data"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAnimal } from '../types';
|
|
1
|
+
import { IAbstractAnimal, IAnimal } from '../types';
|
|
2
2
|
import { ANIMAL_GENDER_ENUM, ANIMAL_STATUS_ENUM, EVENT_TYPES_ENUM } from '../enums';
|
|
3
3
|
import { getMonthFromDate } from '../helpers/date';
|
|
4
4
|
|
|
@@ -12,30 +12,30 @@ const filtered = filter(animals, eventType)
|
|
|
12
12
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
function
|
|
16
|
-
return animal.gender === availableGender
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function ageFilter (animal: IAnimal, availableMinAge: number /*month*/): Boolean {
|
|
15
|
+
function ageFilter<T extends IAbstractAnimal> (animal: T, availableMinAge: number /*month*/): Boolean {
|
|
20
16
|
const months = getMonthFromDate(animal.dob.toISOString())
|
|
21
17
|
return months > availableMinAge
|
|
22
18
|
}
|
|
23
19
|
|
|
24
|
-
function statusFilter (animal:
|
|
20
|
+
function statusFilter<T extends IAbstractAnimal> (animal: T, availableStatuses: ANIMAL_STATUS_ENUM[]): Boolean {
|
|
25
21
|
return availableStatuses.includes(animal.status)
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
function
|
|
29
|
-
|
|
24
|
+
function genderFilter<T extends IAbstractAnimal> (animal: T, availableGender: ANIMAL_GENDER_ENUM): Boolean {
|
|
25
|
+
return animal.gender === availableGender
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function abortFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
29
|
+
const result: T[] = animals.filter(animal => genderFilter<T>(animal, ANIMAL_GENDER_ENUM.cow))
|
|
30
30
|
return result
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
function neosemFilter (animals:
|
|
33
|
+
function neosemFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
34
34
|
return abortFilter(animals)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function osemenenieFilter(animals:
|
|
38
|
-
const result
|
|
37
|
+
function osemenenieFilter<T extends IAbstractAnimal>(animals: T[]): T[] {
|
|
38
|
+
const result = animals.filter(animal => {
|
|
39
39
|
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
40
40
|
const statusOk = statusFilter(animal, [status.heifer, status.bred, status.open, status.fresh])
|
|
41
41
|
const ageOk = ageFilter(animal, defaultCowAge)
|
|
@@ -46,8 +46,8 @@ function osemenenieFilter(animals: IAnimal[]): IAnimal[] {
|
|
|
46
46
|
return result
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
function otelFilter (animals:
|
|
50
|
-
const result
|
|
49
|
+
function otelFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
50
|
+
const result = animals.filter(animal => {
|
|
51
51
|
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
52
52
|
const statusOk = statusFilter(animal, [status.dry, status.pregnant])
|
|
53
53
|
const ageOk = ageFilter(animal, defaultCowAge)
|
|
@@ -57,8 +57,8 @@ function otelFilter (animals: IAnimal[]): IAnimal[] {
|
|
|
57
57
|
return result
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function recheckFilter (animals:
|
|
61
|
-
const result
|
|
60
|
+
function recheckFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
61
|
+
const result = animals.filter(animal => {
|
|
62
62
|
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
63
63
|
const ageOk = ageFilter(animal, defaultCowAge)
|
|
64
64
|
|
|
@@ -75,16 +75,15 @@ function recheckFilter (animals: IAnimal[]): IAnimal[] {
|
|
|
75
75
|
|
|
76
76
|
return genderOk && statusOk && ageOk && animal
|
|
77
77
|
})
|
|
78
|
-
console.info('result', result)
|
|
79
78
|
return result
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
function suhostoiFilter (animals:
|
|
81
|
+
function suhostoiFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
83
82
|
return abortFilter(animals)
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
function pozSuhostoiFilter (animals:
|
|
87
|
-
const result
|
|
85
|
+
function pozSuhostoiFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
86
|
+
const result = animals.filter(animal => {
|
|
88
87
|
const genderOk = genderFilter(animal, ANIMAL_GENDER_ENUM.cow)
|
|
89
88
|
const statusOk = statusFilter(animal, [status.dry])
|
|
90
89
|
const ageOk = ageFilter(animal, defaultCowAge)
|
|
@@ -94,20 +93,20 @@ function pozSuhostoiFilter (animals: IAnimal[]): IAnimal[] {
|
|
|
94
93
|
return result
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
function transferOutFilter (animals:
|
|
96
|
+
function transferOutFilter<T extends IAbstractAnimal> (animals: T[]): T[] {
|
|
98
97
|
return animals
|
|
99
98
|
}
|
|
100
99
|
|
|
101
|
-
function perevodFilter (animals:
|
|
100
|
+
function perevodFilter<T extends IAbstractAnimal> (animals: T[]) {
|
|
102
101
|
return animals
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
interface IFilters {
|
|
106
|
-
[key: string]: (animals:
|
|
104
|
+
interface IFilters<T extends IAbstractAnimal> {
|
|
105
|
+
[key: string]: (animals: T[]) => T[]
|
|
107
106
|
}
|
|
108
107
|
|
|
109
|
-
export function filter (animals:
|
|
110
|
-
const filters: IFilters = {
|
|
108
|
+
export function filter<T extends IAbstractAnimal>(animals: T[], eventType: EVENT_TYPES_ENUM) {
|
|
109
|
+
const filters: IFilters<T> = {
|
|
111
110
|
[EVENT_TYPES_ENUM.abort]: abortFilter,
|
|
112
111
|
[EVENT_TYPES_ENUM.neosem]: neosemFilter,
|
|
113
112
|
[EVENT_TYPES_ENUM.osemenenie]: osemenenieFilter,
|
package/src/types.ts
CHANGED