nodebb-plugin-equipment-calendar 8.0.2 → 8.1.2
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/library.js +34 -7
- package/package.json +1 -1
- package/plugin.json +1 -1
package/library.js
CHANGED
|
@@ -45,6 +45,33 @@ function normalizeItemIds(itemIdsRaw) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
|
|
49
|
+
function parseDateInput(v) {
|
|
50
|
+
if (v === null || v === undefined) return null;
|
|
51
|
+
if (typeof v === 'number' || (typeof v === 'string' && v.trim() && /^\d+$/.test(v.trim()))) {
|
|
52
|
+
const ms = typeof v === 'number' ? v : parseInt(v.trim(), 10);
|
|
53
|
+
const d = new Date(ms);
|
|
54
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
55
|
+
}
|
|
56
|
+
if (typeof v === 'string') {
|
|
57
|
+
const s = v.trim();
|
|
58
|
+
if (!s) return null;
|
|
59
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) {
|
|
60
|
+
const d = new Date(s + 'T00:00:00Z');
|
|
61
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
62
|
+
}
|
|
63
|
+
const d = new Date(s);
|
|
64
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
65
|
+
}
|
|
66
|
+
try {
|
|
67
|
+
const d = new Date(String(v));
|
|
68
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
48
75
|
const axios = require('axios');
|
|
49
76
|
const { DateTime } = require('luxon');
|
|
50
77
|
const { v4: uuidv4 } = require('uuid');
|
|
@@ -1199,12 +1226,12 @@ async function handleCreateReservation(req, res) {
|
|
|
1199
1226
|
if (!itemIds.length) return res.status(400).send('itemIds required');
|
|
1200
1227
|
|
|
1201
1228
|
// Dates come from modal as YYYY-MM-DD
|
|
1202
|
-
const
|
|
1203
|
-
const
|
|
1204
|
-
|
|
1229
|
+
const startVal = req.body.start || req.body.startDate || req.body.startIso || req.body.startMs || req.body.startTime || '';
|
|
1230
|
+
const endVal = req.body.end || req.body.endDate || req.body.endIso || req.body.endMs || req.body.endTime || '';
|
|
1231
|
+
const start = parseDateInput(startVal);
|
|
1232
|
+
const end = parseDateInput(endVal);
|
|
1233
|
+
if (!start || !end) return res.status(400).send('dates required');
|
|
1205
1234
|
|
|
1206
|
-
const start = new Date(startStr + 'T00:00:00Z');
|
|
1207
|
-
const end = new Date(endStr + 'T00:00:00Z');
|
|
1208
1235
|
const startMs = Date.UTC(start.getUTCFullYear(), start.getUTCMonth(), start.getUTCDate());
|
|
1209
1236
|
let endMs = Date.UTC(end.getUTCFullYear(), end.getUTCMonth(), end.getUTCDate());
|
|
1210
1237
|
if (endMs <= startMs) endMs = startMs + 24 * 60 * 60 * 1000;
|
|
@@ -1247,8 +1274,8 @@ async function handleCreateReservation(req, res) {
|
|
|
1247
1274
|
|
|
1248
1275
|
return res.redirect(nconf.get('relative_path') + '/calendar?created=1');
|
|
1249
1276
|
} catch (err) {
|
|
1250
|
-
winston.error('[equipment-calendar] create error', err);
|
|
1251
|
-
return res.status(500).send('error');
|
|
1277
|
+
winston.error('[equipment-calendar] create error: ' + (err && err.message ? err.message : ''), err);
|
|
1278
|
+
return res.status(500).send(err && err.message ? err.message : 'error');
|
|
1252
1279
|
}
|
|
1253
1280
|
}
|
|
1254
1281
|
|
package/package.json
CHANGED