nodebb-plugin-onekite-calendar 1.0.22 → 1.0.24
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/api.js +29 -43
- package/package.json +1 -1
- package/plugin.json +1 -1
package/lib/api.js
CHANGED
|
@@ -328,8 +328,8 @@ function eventsFor(resv) {
|
|
|
328
328
|
const startIsoDate = new Date(parseInt(resv.start, 10)).toISOString().slice(0, 10);
|
|
329
329
|
const endIsoDate = new Date(parseInt(resv.end, 10)).toISOString().slice(0, 10);
|
|
330
330
|
|
|
331
|
-
const itemIds = Array.isArray(
|
|
332
|
-
const itemNames = Array.isArray(
|
|
331
|
+
const itemIds = Array.isArray(resv.itemIds) ? resv.itemIds.filter(Boolean) : [];
|
|
332
|
+
const itemNames = Array.isArray(resv.itemNames) ? resv.itemNames.filter(Boolean) : [];
|
|
333
333
|
|
|
334
334
|
// One line = one material: return one calendar event per item
|
|
335
335
|
if (!itemIds.length && !itemNames.length) {
|
|
@@ -754,51 +754,35 @@ api.createReservation = async function (req, res) {
|
|
|
754
754
|
// Save
|
|
755
755
|
await dbLayer.saveReservation(resv);
|
|
756
756
|
|
|
757
|
-
// Notify groups by email (NodeBB
|
|
757
|
+
// Notify groups by email (NodeBB 4.x, UID-only)
|
|
758
758
|
try {
|
|
759
|
-
const notifyGroups = (settings.notifyGroups || '')
|
|
759
|
+
const notifyGroups = String(settings.notifyGroups || '')
|
|
760
|
+
.split(/[\n,;]+/)
|
|
761
|
+
.map(s => s.trim())
|
|
762
|
+
.filter(Boolean);
|
|
763
|
+
|
|
760
764
|
if (notifyGroups.length) {
|
|
761
|
-
const requester = await user.getUserFields(uid, ['username'
|
|
762
|
-
const itemsLabel = (
|
|
765
|
+
const requester = await user.getUserFields(uid, ['username']);
|
|
766
|
+
const itemsLabel = (itemNames && itemNames.length ? itemNames : itemIds).join(', ');
|
|
767
|
+
|
|
763
768
|
for (const g of notifyGroups) {
|
|
764
769
|
const members = await getMembersByGroupIdentifier(g);
|
|
765
770
|
const uids = normalizeUids(members);
|
|
766
771
|
|
|
767
|
-
|
|
768
|
-
let usersData = [];
|
|
769
|
-
try {
|
|
770
|
-
if (typeof user.getUsersFields === 'function') {
|
|
771
|
-
usersData = await user.getUsersFields(uids, ['username', 'email']);
|
|
772
|
-
// Some NodeBB versions omit uid in returned rows; re-attach it from input order.
|
|
773
|
-
if (Array.isArray(usersData)) {
|
|
774
|
-
usersData = usersData.map((row, idx) => (row ? Object.assign({ uid: uids[idx] }, row) : null));
|
|
775
|
-
}
|
|
776
|
-
} else {
|
|
777
|
-
usersData = await Promise.all(uids.map(async (memberUid) => {
|
|
778
|
-
try { return await user.getUserFields(memberUid, ['username', 'email']); }
|
|
779
|
-
catch (e) { return null; }
|
|
780
|
-
}));
|
|
781
|
-
}
|
|
782
|
-
} catch (e) {
|
|
783
|
-
usersData = [];
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
for (const md of (usersData || [])) {
|
|
787
|
-
const memberUid = md && (md.uid || md.userId || md.userid || md.user_id);
|
|
772
|
+
for (const memberUid of uids) {
|
|
788
773
|
const u = parseInt(memberUid, 10);
|
|
789
|
-
if (Number.isInteger(u)
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
774
|
+
if (!Number.isInteger(u) || u <= 0) continue;
|
|
775
|
+
|
|
776
|
+
await sendEmail('calendar-onekite_pending', u, 'Location matériel - Demande de réservation', {
|
|
777
|
+
uid: u,
|
|
778
|
+
requester: requester && requester.username ? requester.username : '',
|
|
779
|
+
itemName: itemsLabel,
|
|
780
|
+
itemNames: (itemNames && itemNames.length ? itemNames : itemIds),
|
|
781
|
+
dateRange: `Du ${formatFR(start)} au ${formatFR(end)}`,
|
|
782
|
+
start: formatFR(start),
|
|
783
|
+
end: formatFR(end),
|
|
784
|
+
total: resv.total || 0,
|
|
785
|
+
});
|
|
802
786
|
}
|
|
803
787
|
}
|
|
804
788
|
}
|
|
@@ -812,8 +796,8 @@ api.createReservation = async function (req, res) {
|
|
|
812
796
|
rid: resv.rid,
|
|
813
797
|
uid: resv.uid,
|
|
814
798
|
username: resv.username || '',
|
|
815
|
-
itemIds:
|
|
816
|
-
itemNames:
|
|
799
|
+
itemIds: itemIds || [],
|
|
800
|
+
itemNames: itemNames || [],
|
|
817
801
|
start: resv.start,
|
|
818
802
|
end: resv.end,
|
|
819
803
|
status: resv.status,
|
|
@@ -1016,4 +1000,6 @@ api.cancelReservation = async function (req, res) {
|
|
|
1016
1000
|
return res.json({ ok: true, status: 'cancelled' });
|
|
1017
1001
|
};
|
|
1018
1002
|
|
|
1019
|
-
module.exports = api;
|
|
1003
|
+
module.exports = api;
|
|
1004
|
+
|
|
1005
|
+
}
|
package/package.json
CHANGED
package/plugin.json
CHANGED