@justair/justair-library 7.15.0 → 7.16.0-alpha.c51e44a
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/dist/models/users.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/models/users.js +25 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../../src/models/users.js"],"names":[],"mappings":"AA8GA,8BA2IE;AAiCF,wBAAmD;AAhRnD,iDAA4D;AAC5D,6CAAmD;AAUnD,4DA0BC"}
|
package/package.json
CHANGED
package/src/models/users.js
CHANGED
|
@@ -63,16 +63,31 @@ const validateCookieConsent = (consent) => {
|
|
|
63
63
|
// projectSubscribedMonitors would read the `monitor` row as a monitor id and
|
|
64
64
|
// write a Site id into subscribedMonitors, which is precisely the polymorphic
|
|
65
65
|
// id the subscribedMonitors/subscribedDevices split exists to keep out, and it
|
|
66
|
-
// fails silently (the notification service just filters it away).
|
|
67
|
-
// the subscribe path
|
|
68
|
-
//
|
|
66
|
+
// fails silently (the notification service just filters it away). Since
|
|
67
|
+
// JA-3765 the subscribe path guards on deviceId alone (below), so a second
|
|
68
|
+
// type for the same id is refused rather than added; rows written earlier
|
|
69
|
+
// under `$addToSet` can still hold both and are removed by an exact `$pull`.
|
|
69
70
|
//
|
|
70
|
-
//
|
|
71
|
-
//
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
71
|
+
// `subscribedAt` (JA-3765) is when the user followed the device, read per org
|
|
72
|
+
// by the admin Community > Communication page. It lives INSIDE the element,
|
|
73
|
+
// which ends the `$addToSet` dedupe described above: a fresh timestamp makes
|
|
74
|
+
// every pushed element distinct, so `$addToSet` would add a row per click.
|
|
75
|
+
// Writers that stamp it must guard in the filter instead and `$push`:
|
|
76
|
+
//
|
|
77
|
+
// updateOne(
|
|
78
|
+
// { _id, "subscribedDevices.deviceId": { $ne: deviceId } },
|
|
79
|
+
// { $push: { subscribedDevices: { deviceId, deviceType, subscribedAt: now } } },
|
|
80
|
+
// )
|
|
81
|
+
//
|
|
82
|
+
// A repeat subscribe then matches nothing, writes nothing and keeps the first
|
|
83
|
+
// date; the filter and the push are one atomic single-document update, so two
|
|
84
|
+
// concurrent clicks still leave one row. Guarding on deviceId alone (not the
|
|
85
|
+
// pair) also enforces "a deviceId never carries two types".
|
|
86
|
+
//
|
|
87
|
+
// Optional with NO default, on purpose: every element written before JA-3765
|
|
88
|
+
// has no date, and a default would be invented at hydrate time and read as
|
|
89
|
+
// real. Readers treat absent as "unknown"; the JA-3985 backfill dates the old
|
|
90
|
+
// rows from MonitorEpisode history.
|
|
76
91
|
const subscribedDeviceSchema = mongoose.Schema(
|
|
77
92
|
{
|
|
78
93
|
deviceId: { type: mongoose.Types.ObjectId, required: true },
|
|
@@ -88,6 +103,7 @@ const subscribedDeviceSchema = mongoose.Schema(
|
|
|
88
103
|
// path MUST check the request body against DEVICE_TYPE_VALUES before
|
|
89
104
|
// writing (and/or pass `{ runValidators: true }` to the update).
|
|
90
105
|
deviceType: { type: String, enum: DEVICE_TYPE_VALUES, required: true },
|
|
106
|
+
subscribedAt: { type: Date },
|
|
91
107
|
},
|
|
92
108
|
{ _id: false },
|
|
93
109
|
);
|