@outliant/sunrise-utils 1.0.0

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.
Files changed (40) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc +53 -0
  3. package/.github/workflows/pr-dev-workflow.yml +16 -0
  4. package/.nvmrc +1 -0
  5. package/.release-it.js +26 -0
  6. package/.vscode/launch.json +24 -0
  7. package/.vscode/settings.json +7 -0
  8. package/CHANGELOG.md +12 -0
  9. package/README.md +19 -0
  10. package/changelog.hbs +13 -0
  11. package/helpers/es.js +6 -0
  12. package/helpers/projectFilter/projectFieldFilter.js +587 -0
  13. package/helpers/searchFilter.js +86 -0
  14. package/helpers/taskFilter/criticalPathFilter.js +144 -0
  15. package/helpers/taskFilter/index.js +228 -0
  16. package/helpers/taskFilter/onHoldFilter.js +101 -0
  17. package/helpers/taskFilter/ownerFilter.js +148 -0
  18. package/helpers/taskFilter/pathAgeFilter.js +18 -0
  19. package/helpers/taskFilter/regionFilter.js +82 -0
  20. package/helpers/taskFilter/statusFilter.js +177 -0
  21. package/helpers/taskFilter/taskFieldFilter.js +309 -0
  22. package/helpers/taskSortScript.js +356 -0
  23. package/index.d.ts +11 -0
  24. package/index.js +9 -0
  25. package/lib/fieldConditions.js +166 -0
  26. package/lib/logger.js +48 -0
  27. package/lib/taskPipeline.js +137 -0
  28. package/package.json +73 -0
  29. package/test/helpers/projectFilter/projectFieldFilter.spec.js +881 -0
  30. package/test/helpers/taskFilter/criticalPathFilter.spec.js +174 -0
  31. package/test/helpers/taskFilter/index.spec.js +339 -0
  32. package/test/helpers/taskFilter/onHoldFilter.spec.js +112 -0
  33. package/test/helpers/taskFilter/ownerFilter.spec.js +226 -0
  34. package/test/helpers/taskFilter/pathAgeFilter.spec.js +47 -0
  35. package/test/helpers/taskFilter/regionFilter.spec.js +131 -0
  36. package/test/helpers/taskFilter/statusFilter.spec.js +197 -0
  37. package/test/helpers/taskFilter/taskFieldFilter.spec.js +355 -0
  38. package/test/lib/fieldConditions.spec.js +17 -0
  39. package/test/lib/logger.spec.js +117 -0
  40. package/test/lib/taskPipeline.spec.js +162 -0
@@ -0,0 +1,137 @@
1
+ const { validate: isUuid } = require('uuid');
2
+ const {
3
+ taskStatusOptions,
4
+ defaultCustomColumns,
5
+ defaultTaskFilter,
6
+ buildTaskPipelineFilter
7
+ } = require('../helpers/taskFilter');
8
+ const searchFilter = require('../helpers/searchFilter');
9
+ const taskSortScript = require('../helpers/taskSortScript');
10
+
11
+ class TaskPipeline {
12
+ taskStatusOptions = taskStatusOptions;
13
+ defaultCustomColumns = defaultCustomColumns;
14
+ buildFilter = buildTaskPipelineFilter;
15
+
16
+ buildFiltersQuery(
17
+ orgId,
18
+ departmentId,
19
+ filters = [],
20
+ query = {},
21
+ searchFields = []
22
+ ) {
23
+ const mustQuery = [
24
+ {
25
+ term: {
26
+ organization_id: {
27
+ value: orgId
28
+ }
29
+ }
30
+ },
31
+ {
32
+ term: {
33
+ department_id: {
34
+ value: departmentId
35
+ }
36
+ }
37
+ }
38
+ ];
39
+
40
+ if (query.projectId) {
41
+ // Project tasks
42
+ mustQuery.push({
43
+ term: {
44
+ project_id: {
45
+ value: query.projectId
46
+ }
47
+ }
48
+ });
49
+ }
50
+
51
+ if (query.search && query.search.length > 0) {
52
+ const should = searchFilter(query, searchFields);
53
+
54
+ if (should.length > 0) {
55
+ mustQuery.push({
56
+ bool: {
57
+ should
58
+ }
59
+ });
60
+ }
61
+ }
62
+
63
+ if (!filters.length) {
64
+ return {
65
+ bool: {
66
+ must: mustQuery
67
+ }
68
+ };
69
+ }
70
+
71
+ for (const filter of filters) {
72
+ const queryFilter = buildTaskPipelineFilter(filter);
73
+
74
+ if (queryFilter) {
75
+ mustQuery.push(queryFilter);
76
+ }
77
+ }
78
+
79
+ if (!filters.find((f) => f.value === 'on_hold' && f.type === 'status')) {
80
+ mustQuery.push(defaultTaskFilter);
81
+ }
82
+
83
+ return { bool: { must: mustQuery } };
84
+ }
85
+
86
+ buildSortScript(query = {}, customSort = []) {
87
+ const sort = query.sort || 'desc';
88
+ const sortBy = query.sortBy || 'created_at';
89
+ const sortByMultiple = sortBy.split(',');
90
+ let taskPipelinesSort = [];
91
+
92
+ if (sortByMultiple.length > 0) {
93
+ if (sortByMultiple[0] === 'default') {
94
+ taskPipelinesSort = taskSortScript.default;
95
+ } else {
96
+ sortByMultiple.forEach((s) => {
97
+ if (s === 'region') {
98
+ taskPipelinesSort.push(taskSortScript.region(sort));
99
+ } else if (s === 'owner' || s === 'completed_by') {
100
+ taskPipelinesSort.push(taskSortScript.owner(sort));
101
+ } else if (s === 'status') {
102
+ taskPipelinesSort.push(taskSortScript.status(sort));
103
+ } else if (s === 'critical_path_stage') {
104
+ taskPipelinesSort.push(taskSortScript.criticalPathStage(sort));
105
+ } else if (s === 'project_id') {
106
+ // Sort numeric part of the Project ID
107
+ taskPipelinesSort.push(taskSortScript.projectId(sort));
108
+ } else if (s === 'ready_at') {
109
+ taskPipelinesSort.push(taskSortScript.readyAt(sort));
110
+ } else if (s === 'was_marked_incomplete') {
111
+ taskPipelinesSort.push(taskSortScript.wasMarkedIncomplete(sort));
112
+ } else if (s === 'last_comment_date') {
113
+ taskPipelinesSort.push(taskSortScript.lastCommentDate(sort));
114
+ } else if (isUuid(s)) {
115
+ taskPipelinesSort.push(taskSortScript.projectFieldNumeric(sort, s));
116
+ taskPipelinesSort.push(taskSortScript.projectFieldText(sort, s));
117
+ } else {
118
+ taskPipelinesSort.push({
119
+ [s]: { order: sort, missing: '_last' }
120
+ });
121
+ }
122
+ });
123
+ }
124
+ } else {
125
+ // Default sorting
126
+ taskPipelinesSort = taskSortScript.default;
127
+ }
128
+
129
+ if (customSort.length > 0) {
130
+ customSort.forEach((cSort) => taskPipelinesSort.push(cSort));
131
+ }
132
+
133
+ return taskPipelinesSort;
134
+ }
135
+ }
136
+
137
+ module.exports = new TaskPipeline();
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@outliant/sunrise-utils",
3
+ "description": "Helper functions for project Sunrise",
4
+ "version": "1.0.0",
5
+ "license": "ISC",
6
+ "author": "Outliant",
7
+ "main": "index.js",
8
+ "scripts": {
9
+ "lint": "./node_modules/.bin/eslint .",
10
+ "test": "./node_modules/.bin/nyc --reporter=lcov --reporter=text ./node_modules/.bin/mocha --recursive './test/**/*.spec.js'",
11
+ "release": "release-it"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/outliant/sunrise-utils.git"
16
+ },
17
+ "devDependencies": {
18
+ "@babel/eslint-parser": "^7.19.1",
19
+ "auto-changelog": "^2.4.0",
20
+ "chai": "^4.3.7",
21
+ "chai-as-promised": "^7.1.1",
22
+ "eslint": "^8.34.0",
23
+ "eslint-config-prettier": "^8.6.0",
24
+ "eslint-plugin-promise": "^6.1.1",
25
+ "husky": "^8.0.3",
26
+ "mocha": "^10.2.0",
27
+ "nyc": "^15.1.0",
28
+ "release-it": "^15.6.0",
29
+ "sinon": "^15.0.1",
30
+ "test-console": "^2.0.0"
31
+ },
32
+ "keywords": [
33
+ "sunrise",
34
+ "utils",
35
+ "node"
36
+ ],
37
+ "husky": {
38
+ "hooks": {
39
+ "pre-commit": "npm run lint",
40
+ "pre-push": "npm run test"
41
+ }
42
+ },
43
+ "prettier": {
44
+ "tabWidth": 2,
45
+ "singleQuote": true,
46
+ "trailingComma": "none"
47
+ },
48
+ "nyc": {
49
+ "extension": [],
50
+ "require": [],
51
+ "include": [
52
+ "lib/**/*",
53
+ "helpers/**/*"
54
+ ],
55
+ "exclude": [],
56
+ "reporter": [
57
+ "text"
58
+ ],
59
+ "all": true,
60
+ "check-coverage": true,
61
+ "branches": 50,
62
+ "lines": 50,
63
+ "functions": 50,
64
+ "statements": 50
65
+ },
66
+ "dependencies": {
67
+ "moment": "^2.29.4",
68
+ "uuid": "^9.0.0"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public"
72
+ }
73
+ }