@aneuhold/core-ts-db-lib 1.0.25 → 1.0.26
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.
- package/lib/documents/dashboard/Task.d.ts +10 -6
- package/lib/documents/dashboard/Task.d.ts.map +1 -1
- package/lib/documents/dashboard/Task.js +7 -6
- package/lib/services/dashboard/TaskService.d.ts +1 -0
- package/lib/services/dashboard/TaskService.d.ts.map +1 -1
- package/lib/services/dashboard/TaskService.js +42 -22
- package/lib/services/dashboard/TaskService.spec.js +23 -0
- package/package.json +1 -1
|
@@ -46,16 +46,20 @@ export default class DashboardTask extends BaseDocumentWithType implements Requi
|
|
|
46
46
|
*/
|
|
47
47
|
sharedWith: ObjectId[];
|
|
48
48
|
/**
|
|
49
|
-
* The recurrence info for this task if there is any.
|
|
50
|
-
* if {@link parentRecurringTask} is set.
|
|
49
|
+
* The recurrence info for this task if there is any.
|
|
51
50
|
*/
|
|
52
51
|
recurrenceInfo?: RecurrenceInfo;
|
|
53
52
|
/**
|
|
54
|
-
* The
|
|
55
|
-
*
|
|
56
|
-
*
|
|
53
|
+
* The recurring task info for the parent recurring task if there is one.
|
|
54
|
+
*
|
|
55
|
+
* If this is set, then the current tasks's recurrence info should be the
|
|
56
|
+
* same as the parent recurring task.
|
|
57
57
|
*/
|
|
58
|
-
|
|
58
|
+
parentRecurringTaskInfo?: {
|
|
59
|
+
taskId: ObjectId;
|
|
60
|
+
startDate?: Date;
|
|
61
|
+
dueDate?: Date;
|
|
62
|
+
};
|
|
59
63
|
title: string;
|
|
60
64
|
completed: boolean;
|
|
61
65
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../../src/documents/dashboard/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,oBAAoB,MAAM,yBAAyB,CAAC;AAC3D,OAAO,cAAc,MAAM,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S,CAAC,EAAE,IAAI,CAAC;IAEjB,OAAO,CAAC,EAAE,IAAI,CAAC;IAEf;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAM;IAEpB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAa;gBAEjB,OAAO,EAAE,QAAQ;CAI9B"}
|
|
@@ -23,6 +23,7 @@ const validateDashboardTask = (task) => {
|
|
|
23
23
|
validate.object('lastUpdatedDate', exampleTask.lastUpdatedDate);
|
|
24
24
|
validate.optionalObject('startDate');
|
|
25
25
|
validate.optionalObject('dueDate');
|
|
26
|
+
validate.optionalObject('parentRecurringTaskInfo');
|
|
26
27
|
(0, RecurrenceInfo_1.validateRecurrenceInfo)(task, errors);
|
|
27
28
|
return { updatedDoc: task, errors };
|
|
28
29
|
};
|
|
@@ -69,16 +70,16 @@ class DashboardTask extends BaseDocumentWithType_1.default {
|
|
|
69
70
|
*/
|
|
70
71
|
sharedWith = [];
|
|
71
72
|
/**
|
|
72
|
-
* The recurrence info for this task if there is any.
|
|
73
|
-
* if {@link parentRecurringTask} is set.
|
|
73
|
+
* The recurrence info for this task if there is any.
|
|
74
74
|
*/
|
|
75
75
|
recurrenceInfo;
|
|
76
76
|
/**
|
|
77
|
-
* The
|
|
78
|
-
*
|
|
79
|
-
*
|
|
77
|
+
* The recurring task info for the parent recurring task if there is one.
|
|
78
|
+
*
|
|
79
|
+
* If this is set, then the current tasks's recurrence info should be the
|
|
80
|
+
* same as the parent recurring task.
|
|
80
81
|
*/
|
|
81
|
-
|
|
82
|
+
parentRecurringTaskInfo;
|
|
82
83
|
title = '';
|
|
83
84
|
completed = false;
|
|
84
85
|
/**
|
|
@@ -21,6 +21,7 @@ export default class DashboardTaskService {
|
|
|
21
21
|
* there isn't recurrence info.
|
|
22
22
|
*/
|
|
23
23
|
static updateDatesForRecurrence(task: DashboardTask): void;
|
|
24
|
+
private static getDiffForDateUpdate;
|
|
24
25
|
private static getChildrenTaskIds;
|
|
25
26
|
}
|
|
26
27
|
//# sourceMappingURL=TaskService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskService.d.ts","sourceRoot":"","sources":["../../../src/services/dashboard/TaskService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EACL,mBAAmB,EAEpB,MAAM,oDAAoD,CAAC;AAE5D,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC;;OAEG;IACH,MAAM,CAAC,cAAc,iBACL,aAAa,EAAE,iBACd,QAAQ,EAAE,KACxB,QAAQ,EAAE,CA2BX;IAEF;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB;IAsE3E;;;;;;;;OAQG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"TaskService.d.ts","sourceRoot":"","sources":["../../../src/services/dashboard/TaskService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAEhC,OAAO,aAAa,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EACL,mBAAmB,EAEpB,MAAM,oDAAoD,CAAC;AAE5D,MAAM,CAAC,OAAO,OAAO,oBAAoB;IACvC;;OAEG;IACH,MAAM,CAAC,cAAc,iBACL,aAAa,EAAE,iBACd,QAAQ,EAAE,KACxB,QAAQ,EAAE,CA2BX;IAEF;;;OAGG;IACH,MAAM,CAAC,oBAAoB,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,mBAAmB;IAsE3E;;;;;;;;OAQG;IACH,MAAM,CAAC,wBAAwB,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI;IA+D1D,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAcnC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAsBlC"}
|
|
@@ -103,41 +103,61 @@ class DashboardTaskService {
|
|
|
103
103
|
*/
|
|
104
104
|
static updateDatesForRecurrence(task) {
|
|
105
105
|
// Initial basic validation
|
|
106
|
-
if (!task.recurrenceInfo
|
|
106
|
+
if (!task.recurrenceInfo) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// Validation for dates based on parent
|
|
110
|
+
if (task.parentRecurringTaskInfo) {
|
|
111
|
+
if (
|
|
112
|
+
// No dates to move forward
|
|
113
|
+
(!task.dueDate && !task.startDate) ||
|
|
114
|
+
// Invalid start date recurrence basis
|
|
115
|
+
(task.recurrenceInfo.recurrenceBasis === 'startDate' &&
|
|
116
|
+
!task.parentRecurringTaskInfo.startDate) ||
|
|
117
|
+
// Invalid due date recurrence basis
|
|
118
|
+
(task.recurrenceInfo.recurrenceBasis === 'dueDate' &&
|
|
119
|
+
!task.parentRecurringTaskInfo.dueDate)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
// Validation for moving dates based on their own recurrence
|
|
123
|
+
}
|
|
124
|
+
else if (!task.recurrenceInfo ||
|
|
107
125
|
(task.recurrenceInfo.recurrenceBasis === 'startDate' &&
|
|
108
126
|
!task.startDate) ||
|
|
109
127
|
(task.recurrenceInfo.recurrenceBasis === 'dueDate' && !task.dueDate)) {
|
|
110
128
|
return;
|
|
111
129
|
}
|
|
112
|
-
|
|
113
|
-
if (task.
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
const nextRecurDate = this.getNextFrequencyDate(task.startDate, task.recurrenceInfo.frequency);
|
|
118
|
-
if (!nextRecurDate) {
|
|
119
|
-
return;
|
|
130
|
+
let diff = 0;
|
|
131
|
+
if (task.parentRecurringTaskInfo) {
|
|
132
|
+
if (task.recurrenceInfo.recurrenceBasis === 'startDate') {
|
|
133
|
+
diff = this.getDiffForDateUpdate(task.parentRecurringTaskInfo.startDate, task.recurrenceInfo.frequency);
|
|
120
134
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (task.dueDate) {
|
|
124
|
-
task.dueDate = new Date(task.dueDate.getTime() + diff);
|
|
135
|
+
else {
|
|
136
|
+
diff = this.getDiffForDateUpdate(task.parentRecurringTaskInfo.dueDate, task.recurrenceInfo.frequency);
|
|
125
137
|
}
|
|
126
|
-
return;
|
|
127
138
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return;
|
|
139
|
+
else if (task.recurrenceInfo.recurrenceBasis === 'startDate') {
|
|
140
|
+
diff = this.getDiffForDateUpdate(task.startDate, task.recurrenceInfo.frequency);
|
|
131
141
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return;
|
|
142
|
+
else {
|
|
143
|
+
diff = this.getDiffForDateUpdate(task.dueDate, task.recurrenceInfo.frequency);
|
|
135
144
|
}
|
|
136
|
-
const diff = nextRecurDate.getTime() - task.dueDate.getTime();
|
|
137
|
-
task.dueDate = new Date(task.dueDate.getTime() + diff);
|
|
138
145
|
if (task.startDate) {
|
|
139
146
|
task.startDate = new Date(task.startDate.getTime() + diff);
|
|
140
147
|
}
|
|
148
|
+
if (task.dueDate) {
|
|
149
|
+
task.dueDate = new Date(task.dueDate.getTime() + diff);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
static getDiffForDateUpdate(basisDate, frequency) {
|
|
153
|
+
if (!basisDate) {
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
const nextFrequencyDate = this.getNextFrequencyDate(basisDate, frequency);
|
|
157
|
+
if (!nextFrequencyDate) {
|
|
158
|
+
return 0;
|
|
159
|
+
}
|
|
160
|
+
return nextFrequencyDate.getTime() - basisDate.getTime();
|
|
141
161
|
}
|
|
142
162
|
static getChildrenTaskIds(taskIdToTaskDict, parentToTaskIdsDict, taskId) {
|
|
143
163
|
const childrenIds = parentToTaskIdsDict[taskId];
|
|
@@ -125,6 +125,29 @@ describe('DashboardTaskService', () => {
|
|
|
125
125
|
TaskService_1.default.updateDatesForRecurrence(task);
|
|
126
126
|
expect(task.startDate).toEqual(new Date(2024, 0, 2));
|
|
127
127
|
});
|
|
128
|
+
it('should update the start date correctly for daily recurrence on subtask', () => {
|
|
129
|
+
const task = new Task_1.default(new bson_1.ObjectId());
|
|
130
|
+
task.startDate = new Date(2024, 0, 8);
|
|
131
|
+
task.dueDate = new Date(2024, 0, 13);
|
|
132
|
+
task.recurrenceInfo = {
|
|
133
|
+
frequency: {
|
|
134
|
+
type: RecurrenceInfo_1.RecurrenceFrequencyType.everyXTimeUnit,
|
|
135
|
+
everyXTimeUnit: {
|
|
136
|
+
timeUnit: 'day',
|
|
137
|
+
x: 1
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
recurrenceBasis: RecurrenceInfo_1.RecurrenceBasis.startDate,
|
|
141
|
+
recurrenceEffect: RecurrenceInfo_1.RecurrenceEffect.rollOnBasis
|
|
142
|
+
};
|
|
143
|
+
task.parentRecurringTaskInfo = {
|
|
144
|
+
taskId: new bson_1.ObjectId(),
|
|
145
|
+
startDate: new Date(2024, 0, 1)
|
|
146
|
+
};
|
|
147
|
+
TaskService_1.default.updateDatesForRecurrence(task);
|
|
148
|
+
expect(task.startDate).toEqual(new Date(2024, 0, 9));
|
|
149
|
+
expect(task.dueDate).toEqual(new Date(2024, 0, 14));
|
|
150
|
+
});
|
|
128
151
|
it('should update the start date correctly for a weekly recurrence', () => {
|
|
129
152
|
const task = new Task_1.default(new bson_1.ObjectId());
|
|
130
153
|
task.startDate = new Date(2024, 0, 1);
|