@webtypen/webframez-core 0.3.63 → 0.3.64
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.
|
@@ -123,6 +123,8 @@ declare class NotificationServiceFacade {
|
|
|
123
123
|
set registy(registry: {
|
|
124
124
|
[key: string]: NotificationDefinition;
|
|
125
125
|
});
|
|
126
|
+
private getObjectIdString;
|
|
127
|
+
private normalizeObjectId;
|
|
126
128
|
private getNotificationReferenceId;
|
|
127
129
|
init(): void;
|
|
128
130
|
registerType(type: NotificationDefinition): this;
|
|
@@ -56,16 +56,23 @@ class NotificationServiceFacade {
|
|
|
56
56
|
set registy(registry) {
|
|
57
57
|
this.registry = registry;
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
?
|
|
62
|
-
:
|
|
63
|
-
?
|
|
59
|
+
getObjectIdString(value) {
|
|
60
|
+
const objectIdString = typeof value === "string"
|
|
61
|
+
? value
|
|
62
|
+
: value && typeof value.toString === "function"
|
|
63
|
+
? value.toString()
|
|
64
64
|
: null;
|
|
65
|
-
return
|
|
66
|
-
?
|
|
65
|
+
return objectIdString && objectIdString.length === 24 && mongodb_1.ObjectId.isValid(objectIdString)
|
|
66
|
+
? objectIdString
|
|
67
67
|
: null;
|
|
68
68
|
}
|
|
69
|
+
normalizeObjectId(value) {
|
|
70
|
+
const objectIdString = this.getObjectIdString(value);
|
|
71
|
+
return objectIdString ? new mongodb_1.ObjectId(objectIdString) : null;
|
|
72
|
+
}
|
|
73
|
+
getNotificationReferenceId(notificationRef) {
|
|
74
|
+
return this.getObjectIdString(notificationRef);
|
|
75
|
+
}
|
|
69
76
|
init() {
|
|
70
77
|
this.registry = {};
|
|
71
78
|
this.notificationsConfig = Config_1.Config.get("notifications") || {};
|
|
@@ -168,14 +175,11 @@ class NotificationServiceFacade {
|
|
|
168
175
|
return this.targetRegistry[target] || null;
|
|
169
176
|
}
|
|
170
177
|
normalizeTargetId(targetId) {
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
return targetId;
|
|
174
|
-
const value = typeof targetId === "string" ? targetId : (_a = targetId === null || targetId === void 0 ? void 0 : targetId.toString) === null || _a === void 0 ? void 0 : _a.call(targetId);
|
|
175
|
-
if (typeof value !== "string" || value.length !== 24 || !mongodb_1.ObjectId.isValid(value)) {
|
|
178
|
+
const normalized = this.normalizeObjectId(targetId);
|
|
179
|
+
if (!normalized) {
|
|
176
180
|
throw new NotificationTargetValidationError("Invalid notification target_id.");
|
|
177
181
|
}
|
|
178
|
-
return
|
|
182
|
+
return normalized;
|
|
179
183
|
}
|
|
180
184
|
normalizeTargetContext(context) {
|
|
181
185
|
if (!context || typeof context.target !== "string" || context.target.trim() === "") {
|
|
@@ -243,15 +247,8 @@ class NotificationServiceFacade {
|
|
|
243
247
|
return notification;
|
|
244
248
|
}
|
|
245
249
|
getModelId(model) {
|
|
246
|
-
var _a
|
|
247
|
-
|
|
248
|
-
if (value instanceof mongodb_1.ObjectId)
|
|
249
|
-
return value;
|
|
250
|
-
const stringValue = typeof value === "string" ? value : (_b = value === null || value === void 0 ? void 0 : value.toString) === null || _b === void 0 ? void 0 : _b.call(value);
|
|
251
|
-
if (typeof stringValue === "string" && stringValue.length === 24 && mongodb_1.ObjectId.isValid(stringValue)) {
|
|
252
|
-
return new mongodb_1.ObjectId(stringValue);
|
|
253
|
-
}
|
|
254
|
-
return null;
|
|
250
|
+
var _a;
|
|
251
|
+
return this.normalizeObjectId((_a = model === null || model === void 0 ? void 0 : model._id) !== null && _a !== void 0 ? _a : model === null || model === void 0 ? void 0 : model.id);
|
|
255
252
|
}
|
|
256
253
|
getPreferencesField(target) {
|
|
257
254
|
var _a;
|
|
@@ -746,18 +743,9 @@ class NotificationServiceFacade {
|
|
|
746
743
|
getNotificationForTarget(notificationRef, context) {
|
|
747
744
|
return __awaiter(this, void 0, void 0, function* () {
|
|
748
745
|
const notificationId = notificationRef instanceof Notification_1.Notification ? notificationRef._id : notificationRef;
|
|
749
|
-
|
|
746
|
+
const objectId = this.normalizeObjectId(notificationId);
|
|
747
|
+
if (!objectId)
|
|
750
748
|
return null;
|
|
751
|
-
let objectId;
|
|
752
|
-
if (notificationId instanceof mongodb_1.ObjectId) {
|
|
753
|
-
objectId = notificationId;
|
|
754
|
-
}
|
|
755
|
-
else if (typeof notificationId === "string" && mongodb_1.ObjectId.isValid(notificationId)) {
|
|
756
|
-
objectId = new mongodb_1.ObjectId(notificationId);
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
return null;
|
|
760
|
-
}
|
|
761
749
|
const notifications = yield Notification_1.Notification.aggregate([
|
|
762
750
|
{
|
|
763
751
|
$match: Object.assign(Object.assign({}, (yield this.getLoadMatch(context))), { _id: objectId }),
|
package/package.json
CHANGED