nodebb-plugin-niki-loyalty 1.0.23 → 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/library.js CHANGED
@@ -423,6 +423,45 @@ router.post('/api/niki-loyalty/scan-coupon', middleware.ensureLoggedIn, async (r
423
423
  return res.status(500).json({ success: false, message: 'Sunucu hatası' });
424
424
  }
425
425
  });
426
+ const TIERS = [60, 120, 180, 250];
427
+
428
+ function pickTier(points) {
429
+ // en büyük uygun tier
430
+ let chosen = 0;
431
+ for (const t of TIERS) if (points >= t) chosen = t;
432
+ return chosen; // 0 ise yetersiz
433
+ }
434
+
435
+ router.post('/api/niki-loyalty/claim-auto', middleware.ensureLoggedIn, async (req, res) => {
436
+ try {
437
+ const uid = req.uid;
438
+ const points = parseInt((await user.getUserField(uid, 'niki_points')) || 0, 10);
439
+
440
+ if (TEST_MODE_UNLIMITED) {
441
+ // testte 250 gibi davran
442
+ const token = makeToken();
443
+ await db.set(`niki:coupon:${token}`, safeStringify({ token, ts: Date.now(), ownerUid: uid, cost: 250 }));
444
+ await db.expire(`niki:coupon:${token}`, 120);
445
+ return res.json({ success: true, token, cost: 250 });
446
+ }
447
+
448
+ const cost = pickTier(points);
449
+ if (!cost) return res.json({ success: false, message: 'En az 60 puan gerekli.' });
450
+
451
+ const token = makeToken();
452
+ await db.set(`niki:coupon:${token}`, safeStringify({
453
+ token,
454
+ ts: Date.now(),
455
+ ownerUid: uid,
456
+ cost, // ✅ kasada düşülecek miktar
457
+ }));
458
+ await db.expire(`niki:coupon:${token}`, 120); // ✅ 2 dk
459
+
460
+ return res.json({ success: true, token, cost });
461
+ } catch (e) {
462
+ return res.status(500).json({ success: false, message: 'Sunucu hatası' });
463
+ }
464
+ });
426
465
 
427
466
  router.post('/api/niki-loyalty/scan-qr', middleware.ensureLoggedIn, async (req, res) => {
428
467
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-niki-loyalty",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Niki The Cat Coffee Loyalty System - Earn points while studying on IEU Forum.",
5
5
  "main": "library.js",
6
6
  "nbbpm": {
@@ -61,6 +61,27 @@ $(document).ready(function () {
61
61
  $('#my-points, #niki-wallet-points, .niki-wallet-points').text(p);
62
62
  $('#target-txt').text(`${p} / 250`);
63
63
  }
64
+ $(document).on('click', '#btn-qr-auto', function () {
65
+ $.post('/api/niki-loyalty/claim-auto', { _csrf: config.csrf_token }, function (res) {
66
+ if (!res || !res.success) {
67
+ app.alertError(res?.message || 'QR oluşturulamadı');
68
+ return;
69
+ }
70
+
71
+ // modal aç (tpl’deki openCouponModal varsa onu çağır)
72
+ const title = `ÖDÜL • ${res.cost} PUAN`;
73
+ if (typeof window.openCouponModal === 'function') {
74
+ window.openCouponModal(title, res.token);
75
+ } else {
76
+ // client.js içindeki openQRModal fallback’ı varsa kullan
77
+ openQRModal({ token: res.token, title, ttlSeconds: 120 });
78
+ }
79
+
80
+ // ✅ polling: puan düşünce success’e geç
81
+ initialPointsForQR = parseInt(localStorage.getItem('niki_last_points') || '0', 10) || null;
82
+ startPollingForSuccess();
83
+ });
84
+ });
64
85
 
65
86
  function initNikiWidget() {
66
87
  if (!app.user.uid || app.user.uid <= 0) return;
@@ -34,7 +34,13 @@
34
34
  </div>
35
35
 
36
36
  <!-- ✅ REWARD KARTLARI (client.js buraya basacak: QR OLUŞTUR butonları) -->
37
- <div id="niki-rewards" style="margin-top:16px;"></div>
37
+ <button id="btn-qr-auto" class="niki-btn">
38
+ <i class="fa fa-qrcode"></i> QR OLUŞTUR
39
+ </button>
40
+
41
+ <div style="font-size:11px; color:#888; margin-top:10px;">
42
+ QR oluşturduktan sonra <b>kasada okutulunca</b> puanın düşer. (QR 2 dakika geçerli)
43
+ </div>
38
44
 
39
45
  <div class="niki-daily-stats" style="margin-top:18px;">
40
46
  <div style="display:flex; justify-content:space-between; font-size:12px; color:#888; font-weight:700;">