nodebb-plugin-niki-loyalty 1.0.18 → 1.0.20
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 +54 -35
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -160,45 +160,64 @@ Plugin.init = async function (params) {
|
|
|
160
160
|
});
|
|
161
161
|
|
|
162
162
|
// 3) KASA HISTORY (admin/mod)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
163
|
+
router.get('/api/niki-loyalty/kasa-history', middleware.ensureLoggedIn, async (req, res) => {
|
|
164
|
+
try {
|
|
165
|
+
const isAdmin = await user.isAdministrator(req.uid);
|
|
166
|
+
const isMod = await user.isGlobalModerator(req.uid);
|
|
167
|
+
if (!isAdmin && !isMod) return res.status(403).json([]);
|
|
168
168
|
|
|
169
|
-
|
|
169
|
+
const raw = await db.getListRange('niki:kasa:history', 0, -1);
|
|
170
170
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
// ✅ userslug + username + picture al
|
|
181
|
-
const uData = await user.getUserFields(item.cuid, ['username', 'userslug', 'picture']);
|
|
182
|
-
const userslug = uData?.userslug;
|
|
183
|
-
|
|
184
|
-
return {
|
|
185
|
-
...item,
|
|
186
|
-
cust: item.cust || uData?.username || 'Bilinmeyen',
|
|
187
|
-
picture: item.picture || uData?.picture || '',
|
|
188
|
-
userslug: userslug || item.userslug || '',
|
|
189
|
-
profileUrl: makeProfileUrl(userslug || item.userslug),
|
|
190
|
-
};
|
|
191
|
-
} catch (e) {
|
|
192
|
-
// tek item patlasa bile endpoint düşmesin
|
|
193
|
-
return item;
|
|
171
|
+
// Kayıtlar bazen JSON string, bazen bozuk olabilir → güvenli parse
|
|
172
|
+
const rows = (raw || [])
|
|
173
|
+
.map((x) => {
|
|
174
|
+
if (!x) return null;
|
|
175
|
+
if (typeof x === 'object') return x;
|
|
176
|
+
if (typeof x === 'string') {
|
|
177
|
+
try { return JSON.parse(x); } catch (e) { return null; }
|
|
194
178
|
}
|
|
195
|
-
|
|
179
|
+
return null;
|
|
180
|
+
})
|
|
181
|
+
.filter(Boolean)
|
|
182
|
+
.reverse();
|
|
183
|
+
|
|
184
|
+
// cuid’lerden uid listesi çıkar
|
|
185
|
+
const uids = rows
|
|
186
|
+
.map(r => parseInt(r.cuid, 10))
|
|
187
|
+
.filter(n => Number.isFinite(n) && n > 0);
|
|
188
|
+
|
|
189
|
+
// NodeBB core user datası (profile-looks mantığı)
|
|
190
|
+
const users = await user.getUsersFields(uids, [
|
|
191
|
+
'uid', 'username', 'userslug', 'picture', 'icon:bgColor',
|
|
192
|
+
]);
|
|
193
|
+
|
|
194
|
+
const userMap = {};
|
|
195
|
+
(users || []).forEach(u => { userMap[u.uid] = u; });
|
|
196
|
+
|
|
197
|
+
const rp = nconf.get('relative_path') || '';
|
|
198
|
+
|
|
199
|
+
const enriched = rows.map(r => {
|
|
200
|
+
const uid = parseInt(r.cuid, 10);
|
|
201
|
+
const u = userMap[uid];
|
|
202
|
+
if (!u) return r;
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
...r,
|
|
206
|
+
cust: u.username || r.cust || 'Bilinmeyen',
|
|
207
|
+
userslug: u.userslug || r.userslug || '',
|
|
208
|
+
picture: u.picture || r.picture || '',
|
|
209
|
+
iconBg: u['icon:bgColor'] || r.iconBg || '#4b5563',
|
|
210
|
+
profileUrl: (u.userslug ? `${rp}/user/${u.userslug}` : ''),
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
return res.json(enriched);
|
|
215
|
+
} catch (err) {
|
|
216
|
+
return res.status(500).json([]);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
196
220
|
|
|
197
|
-
return res.json(enriched);
|
|
198
|
-
} catch (err) {
|
|
199
|
-
return res.status(500).json([]);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
221
|
|
|
203
222
|
// 4) QR OLUŞTUR
|
|
204
223
|
router.post('/api/niki-loyalty/generate-qr', middleware.ensureLoggedIn, async (req, res) => {
|