@aneuhold/core-ts-db-lib 1.0.13 → 1.0.14
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/README.md +2 -0
- package/lib/documents/dashboard/Task.d.ts +52 -0
- package/lib/documents/dashboard/Task.d.ts.map +1 -0
- package/lib/documents/dashboard/Task.js +71 -0
- package/lib/schemas/validators/ValidateUtil.d.ts +1 -0
- package/lib/schemas/validators/ValidateUtil.d.ts.map +1 -1
- package/lib/schemas/validators/ValidateUtil.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,7 +23,9 @@ following steps
|
|
|
23
23
|
1. Run the migration with `yarn migrate:dry` then `yarn migrate`
|
|
24
24
|
1. Run validation to ensure everything is alright with `yarn validate:dry` then `yarn validate` if needed
|
|
25
25
|
1. Run tests
|
|
26
|
+
1. Update tests if needed then re-validate
|
|
26
27
|
1. Push a new version of the `be-ts-db-lib` to NPM
|
|
27
28
|
1. Pull the new versions into `digital-ocean-functions` and deploy
|
|
28
29
|
1. Pull the new versions into `core-ts-api-lib` and push to NPM
|
|
29
30
|
1. Pull the new versions into any relevant frontends and deploy
|
|
31
|
+
1. Test out the frontends to make sure it works okay and double check MongoDB directly
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ObjectId } from 'bson';
|
|
2
|
+
import BaseDocumentWithType from '../BaseDocumentWithType';
|
|
3
|
+
import RequiredUserId from '../../schemas/required-refs/RequiredUserId';
|
|
4
|
+
import { DocumentValidator } from '../../schemas/validators/DocumentValidator';
|
|
5
|
+
export declare const validateDashboardTask: DocumentValidator<DashboardTask>;
|
|
6
|
+
export default class DashboardTask extends BaseDocumentWithType implements RequiredUserId {
|
|
7
|
+
static docType: string;
|
|
8
|
+
docType: string;
|
|
9
|
+
/**
|
|
10
|
+
* The owner of this task.
|
|
11
|
+
*/
|
|
12
|
+
userId: ObjectId;
|
|
13
|
+
/**
|
|
14
|
+
* The different users this task is shared with. This should be indexed
|
|
15
|
+
* somehow.
|
|
16
|
+
*/
|
|
17
|
+
sharedWith: ObjectId[];
|
|
18
|
+
title: string;
|
|
19
|
+
completed: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* The ID of the parent task if there is one.
|
|
22
|
+
*/
|
|
23
|
+
parentTaskId?: ObjectId;
|
|
24
|
+
/**
|
|
25
|
+
* The description of the task. This is purposefully optional in case the
|
|
26
|
+
* user wants to just use the title. This also helps the frontend
|
|
27
|
+
* differentiate between a task that has no description and a task that has
|
|
28
|
+
* an empty description.
|
|
29
|
+
*/
|
|
30
|
+
description?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The date this task was created.
|
|
33
|
+
*/
|
|
34
|
+
createdDate: Date;
|
|
35
|
+
/**
|
|
36
|
+
* The date this task was last updated.
|
|
37
|
+
*/
|
|
38
|
+
lastUpdatedDate: Date;
|
|
39
|
+
startDate?: Date;
|
|
40
|
+
dueDate?: Date;
|
|
41
|
+
/**
|
|
42
|
+
* User-assigned tags for this task.
|
|
43
|
+
*/
|
|
44
|
+
tags: string[];
|
|
45
|
+
/**
|
|
46
|
+
* System-assigned category for this task. This should be used to determine
|
|
47
|
+
* where this task should be displayed.
|
|
48
|
+
*/
|
|
49
|
+
category: string;
|
|
50
|
+
constructor(ownerId: ObjectId);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=Task.d.ts.map
|
|
@@ -0,0 +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,4CAA4C,CAAC;AAExE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,eAAO,MAAM,qBAAqB,EAAE,iBAAiB,CAAC,aAAa,CAclE,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,aACnB,SAAQ,oBACR,YAAW,cAAc;IAEzB,MAAM,CAAC,OAAO,SAAU;IAExB,OAAO,SAAyB;IAEhC;;OAEG;IACH,MAAM,EAAE,QAAQ,CAAC;IAEjB;;;OAGG;IACH,UAAU,EAAE,QAAQ,EAAE,CAAM;IAE5B,KAAK,SAAM;IAEX,SAAS,UAAS;IAElB;;OAEG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAC;IAExB;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,WAAW,OAAc;IAEzB;;OAEG;IACH,eAAe,OAAc;IAE7B,SAAS,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"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateDashboardTask = void 0;
|
|
7
|
+
const bson_1 = require("bson");
|
|
8
|
+
const BaseDocumentWithType_1 = __importDefault(require("../BaseDocumentWithType"));
|
|
9
|
+
const ValidateUtil_1 = __importDefault(require("../../schemas/validators/ValidateUtil"));
|
|
10
|
+
const validateDashboardTask = (task) => {
|
|
11
|
+
const errors = [];
|
|
12
|
+
const validate = new ValidateUtil_1.default(task, errors);
|
|
13
|
+
const exampleTask = new DashboardTask(new bson_1.ObjectId());
|
|
14
|
+
validate.string('title', exampleTask.title);
|
|
15
|
+
validate.boolean('completed', exampleTask.completed);
|
|
16
|
+
validate.optionalString('description');
|
|
17
|
+
validate.array('tags', exampleTask.tags);
|
|
18
|
+
validate.string('category', exampleTask.category);
|
|
19
|
+
return { updatedDoc: task, errors };
|
|
20
|
+
};
|
|
21
|
+
exports.validateDashboardTask = validateDashboardTask;
|
|
22
|
+
class DashboardTask extends BaseDocumentWithType_1.default {
|
|
23
|
+
static docType = 'task';
|
|
24
|
+
docType = DashboardTask.docType;
|
|
25
|
+
/**
|
|
26
|
+
* The owner of this task.
|
|
27
|
+
*/
|
|
28
|
+
userId;
|
|
29
|
+
/**
|
|
30
|
+
* The different users this task is shared with. This should be indexed
|
|
31
|
+
* somehow.
|
|
32
|
+
*/
|
|
33
|
+
sharedWith = [];
|
|
34
|
+
title = '';
|
|
35
|
+
completed = false;
|
|
36
|
+
/**
|
|
37
|
+
* The ID of the parent task if there is one.
|
|
38
|
+
*/
|
|
39
|
+
parentTaskId;
|
|
40
|
+
/**
|
|
41
|
+
* The description of the task. This is purposefully optional in case the
|
|
42
|
+
* user wants to just use the title. This also helps the frontend
|
|
43
|
+
* differentiate between a task that has no description and a task that has
|
|
44
|
+
* an empty description.
|
|
45
|
+
*/
|
|
46
|
+
description;
|
|
47
|
+
/**
|
|
48
|
+
* The date this task was created.
|
|
49
|
+
*/
|
|
50
|
+
createdDate = new Date();
|
|
51
|
+
/**
|
|
52
|
+
* The date this task was last updated.
|
|
53
|
+
*/
|
|
54
|
+
lastUpdatedDate = new Date();
|
|
55
|
+
startDate;
|
|
56
|
+
dueDate;
|
|
57
|
+
/**
|
|
58
|
+
* User-assigned tags for this task.
|
|
59
|
+
*/
|
|
60
|
+
tags = [];
|
|
61
|
+
/**
|
|
62
|
+
* System-assigned category for this task. This should be used to determine
|
|
63
|
+
* where this task should be displayed.
|
|
64
|
+
*/
|
|
65
|
+
category = 'default';
|
|
66
|
+
constructor(ownerId) {
|
|
67
|
+
super();
|
|
68
|
+
this.userId = ownerId;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.default = DashboardTask;
|
|
@@ -26,6 +26,7 @@ export default class Validate {
|
|
|
26
26
|
object(fieldName: string, defaultValue: object): void;
|
|
27
27
|
number(fieldName: string, defaultValue: number): void;
|
|
28
28
|
boolean(fieldName: string, defaultValue: boolean): void;
|
|
29
|
+
array(fieldName: string, defaultValue: unknown[]): void;
|
|
29
30
|
/**
|
|
30
31
|
* Checks if the provided field path is valid. In other words, if the
|
|
31
32
|
* field path is of length 1, it always returns true. If the field path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValidateUtil.d.ts","sourceRoot":"","sources":["../../../src/schemas/validators/ValidateUtil.ts"],"names":[],"mappings":"AAOA,KAAK,eAAe,GAAG;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAKzB,OAAO,CAAC,WAAW;IAJrB,YAAY,EAAE,eAAe,CAAC;gBAG5B,YAAY,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EAAE;IAK/B,cAAc,CAAC,SAAS,EAAE,MAAM;IAUhC,cAAc,CAAC,SAAS,EAAE,MAAM;IAUhC,eAAe,CAAC,SAAS,EAAE,MAAM;IAUjC,aAAa,CAAC,SAAS,EAAE,MAAM;IAU/B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO;IAUhD;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,WAAW;CAWpB"}
|
|
1
|
+
{"version":3,"file":"ValidateUtil.d.ts","sourceRoot":"","sources":["../../../src/schemas/validators/ValidateUtil.ts"],"names":[],"mappings":"AAOA,KAAK,eAAe,GAAG;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAKzB,OAAO,CAAC,WAAW;IAJrB,YAAY,EAAE,eAAe,CAAC;gBAG5B,YAAY,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EAAE;IAK/B,cAAc,CAAC,SAAS,EAAE,MAAM;IAUhC,cAAc,CAAC,SAAS,EAAE,MAAM;IAUhC,eAAe,CAAC,SAAS,EAAE,MAAM;IAUjC,aAAa,CAAC,SAAS,EAAE,MAAM;IAU/B,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;IAU9C,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO;IAUhD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;IAUhD;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,QAAQ;IAShB,OAAO,CAAC,WAAW;CAWpB"}
|
|
@@ -77,6 +77,13 @@ class Validate {
|
|
|
77
77
|
this.updateField(fieldName, defaultValue);
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
array(fieldName, defaultValue) {
|
|
81
|
+
if (this.fieldPathIsValid(fieldName) &&
|
|
82
|
+
!Array.isArray(this.getField(fieldName))) {
|
|
83
|
+
this.errorsArray.push(`${fieldName} must be an array`);
|
|
84
|
+
this.updateField(fieldName, defaultValue);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
80
87
|
/**
|
|
81
88
|
* Checks if the provided field path is valid. In other words, if the
|
|
82
89
|
* field path is of length 1, it always returns true. If the field path
|