@aneuhold/core-ts-db-lib 1.0.43 → 1.0.45

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.
@@ -30,6 +30,17 @@ export default class DashboardUserConfig extends BaseDocumentWithType implements
30
30
  automationPage: boolean;
31
31
  homePageLinks: boolean;
32
32
  };
33
+ /**
34
+ * The number of days after which a task is automatically deleted. The
35
+ * requirement is that this number is at least 5 days, and at most 90 days.
36
+ *
37
+ * Tasks are only deleted if:
38
+ *
39
+ * - They are not recurring
40
+ * - They are not completed
41
+ * - They have not been updated in the number listed by this setting
42
+ */
43
+ autoTaskDeletionDays: number;
33
44
  /**
34
45
  * The user's tag settings for the dashboard.
35
46
  */
@@ -1 +1 @@
1
- {"version":3,"file":"UserConfig.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/UserConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,cAAc,MAAM,4CAA4C,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,gDAAgD,CAAC;AACtF,OAAO,EACL,mCAAmC,EAEpC,MAAM,kDAAkD,CAAC;AAC1D,OAAO,EACL,qCAAqC,EAEtC,MAAM,oDAAoD,CAAC;AAE5D,eAAO,MAAM,2BAA2B,EAAE,iBAAiB,CACzD,mBAAmB,CAcpB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,mBACnB,SAAQ,oBACR,YAAW,cAAc;IAEzB,MAAM,CAAC,OAAO,SAAgB;IAE9B,OAAO,SAA+B;IAEtC;;OAEG;IACH,MAAM,EAAE,QAAQ,CAAC;IAEjB;;;OAGG;IACH,aAAa,EAAE,QAAQ,EAAE,CAAM;IAE/B;;OAEG;IACH,aAAa,UAAS;IAEtB;;OAEG;IACH,e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AAM;IAEvC,oBAAoB,EAAE,mCAAmC,CAAM;IAE/D,sBAAsB,EAAE,qCAAqC,CAAM;gBAEvD,OAAO,EAAE,QAAQ;CAI9B"}
@@ -17,6 +17,7 @@ const validateDashboardUserConfig = (config) => {
17
17
  validate.array('collaborators', exampleConfig.collaborators);
18
18
  validate.object('tagSettings', {});
19
19
  validate.object('enabledFeatures', exampleConfig.enabledFeatures);
20
+ validate.number('autoTaskDeletionDays', exampleConfig.autoTaskDeletionDays);
20
21
  (0, SortSettings_1.validateSortSettings)(validate, config);
21
22
  (0, FilterSettings_1.validateFilterSettings)(validate, config);
22
23
  return { updatedDoc: config, errors };
@@ -46,6 +47,17 @@ class DashboardUserConfig extends BaseDocumentWithType_1.default {
46
47
  automationPage: false,
47
48
  homePageLinks: false
48
49
  };
50
+ /**
51
+ * The number of days after which a task is automatically deleted. The
52
+ * requirement is that this number is at least 5 days, and at most 90 days.
53
+ *
54
+ * Tasks are only deleted if:
55
+ *
56
+ * - They are not recurring
57
+ * - They are not completed
58
+ * - They have not been updated in the number listed by this setting
59
+ */
60
+ autoTaskDeletionDays = 30;
49
61
  /**
50
62
  * The user's tag settings for the dashboard.
51
63
  */
@@ -356,7 +356,7 @@ describe('DashboardTaskService', () => {
356
356
  const task4 = tasksList[2];
357
357
  const task5 = tasksList[3];
358
358
  task1.tags = {
359
- [sortSettings.userId]: ['tagWithoutPriority']
359
+ [sortSettings.userId]: ['tagWithoutPriority', 'tag3']
360
360
  };
361
361
  task2.tags = {
362
362
  [sortSettings.userId]: ['tag3', 'tag4', 'tag1']
@@ -1,4 +1,4 @@
1
- import DashboardTask, { DashboardTaskMap } from '../../../documents/dashboard/Task';
1
+ import { DashboardTaskMap } from '../../../documents/dashboard/Task';
2
2
  import { DashboardTaskListSortSettings, DashboardTaskSortDirection } from '../../../embedded-types/dashboard/task/SortSettings';
3
3
  import { DashboardTagSettings } from '../../../embedded-types/dashboard/userConfig/Tags';
4
4
  /**
@@ -24,6 +24,7 @@ export default class DashboardTaskSortService {
24
24
  /**
25
25
  * Gets the highest priority tag value for the provided task.
26
26
  */
27
- static getHighestPriorityTagValue(task: DashboardTask, userId: string, tagSettings: DashboardTagSettings, sortDirection: DashboardTaskSortDirection): number;
27
+ private static getHighestPriorityTagValue;
28
+ private static getPriorityTagForTask;
28
29
  }
29
30
  //# sourceMappingURL=TaskSortService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TaskSortService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskSortService.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,EAAE,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAE7B,0BAA0B,EAC3B,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAC3C;;OAEG;IACH,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,oBAAoB;IA0BnC;;;;OAIG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,EACjC,uBAAuB,EAAE,MAAM,EAC/B,aAAa,EAAE,0BAA0B,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAkCzB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkElC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAgCpC;;OAEG;IACH,MAAM,CAAC,0BAA0B,CAC/B,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,0BAA0B;CAoB5C"}
1
+ {"version":3,"file":"TaskSortService.d.ts","sourceRoot":"","sources":["../../../../src/services/dashboard/Task/TaskSortService.ts"],"names":[],"mappings":"AAAA,OAAsB,EACpB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,6BAA6B,EAE7B,0BAA0B,EAC3B,MAAM,qDAAqD,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mDAAmD,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAC3C;;OAEG;IACH,MAAM,CAAC,IAAI,CACT,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,YAAY,EAAE,6BAA6B,EAC3C,WAAW,EAAE,oBAAoB;IA0BnC;;;;OAIG;IACH,MAAM,CAAC,eAAe,CACpB,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,MAAM,EAAE,EACjB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,oBAAoB,EACjC,uBAAuB,EAAE,MAAM,EAC/B,aAAa,EAAE,0BAA0B,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAkCzB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAkElC;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAepC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,0BAA0B;IAezC,OAAO,CAAC,MAAM,CAAC,qBAAqB;CAgCrC"}
@@ -114,44 +114,40 @@ class DashboardTaskSortService {
114
114
  * or if there are no tags with a priority, then this will return null.
115
115
  */
116
116
  static getHighestPriorityTag(task, userId, tagSettings, sortDirection) {
117
- const tags = task.tags[userId];
118
- if (!tags || tags.length === 0)
119
- return null;
120
- let highestPriorityTag = null;
121
- let highestPriority = 0;
122
- const sortDirectionIsAscending = sortDirection === SortSettings_1.DashboardTaskSortDirection.ascending;
123
- // If the sort direction is descending, then we want to start with the
124
- // lowest priority number.
125
- if (sortDirectionIsAscending) {
126
- highestPriority = Number.MAX_SAFE_INTEGER;
127
- }
128
- tags.forEach((tag) => {
129
- const priority = tagSettings[tag]?.priority;
130
- if (priority &&
131
- ((sortDirectionIsAscending && priority < highestPriority) ||
132
- (!sortDirectionIsAscending && priority > highestPriority))) {
133
- highestPriorityTag = tag;
134
- highestPriority = priority;
135
- }
136
- });
137
- return highestPriorityTag;
117
+ const priorityTag = this.getPriorityTagForTask(task, userId, tagSettings, sortDirection);
118
+ return priorityTag ? priorityTag.tag : null;
138
119
  }
139
120
  /**
140
121
  * Gets the highest priority tag value for the provided task.
141
122
  */
142
123
  static getHighestPriorityTagValue(task, userId, tagSettings, sortDirection) {
124
+ const priorityTag = this.getPriorityTagForTask(task, userId, tagSettings, sortDirection);
125
+ return priorityTag ? priorityTag.priority : 0;
126
+ }
127
+ static getPriorityTagForTask(task, userId, tagSettings, sortDirection) {
128
+ let priorityTag = null;
143
129
  const tags = task.tags[userId];
144
130
  if (!tags || tags.length === 0)
145
- return 0;
131
+ return priorityTag;
132
+ let highestPriority = 0;
146
133
  const isAscending = sortDirection === SortSettings_1.DashboardTaskSortDirection.ascending;
147
- return tags.reduce((highestPriority, tag) => {
134
+ // If the sort direction is descending, then we want to start with the
135
+ // lowest priority number.
136
+ if (isAscending) {
137
+ highestPriority = Number.MAX_SAFE_INTEGER;
138
+ }
139
+ tags.forEach((tag) => {
148
140
  const priority = tagSettings[tag]?.priority ?? 0;
149
141
  if ((isAscending && priority < highestPriority) ||
150
142
  (!isAscending && priority > highestPriority)) {
151
- return priority;
143
+ highestPriority = priority;
144
+ priorityTag = { tag, priority };
152
145
  }
153
- return highestPriority;
154
- }, isAscending ? Number.MAX_SAFE_INTEGER : 0);
146
+ });
147
+ if (highestPriority === 0) {
148
+ return null;
149
+ }
150
+ return priorityTag;
155
151
  }
156
152
  }
157
153
  exports.default = DashboardTaskSortService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-db-lib",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "A core database library used for personal projects",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",