nodebb-plugin-niki-loyalty 1.0.12 → 1.0.14
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 +14 -14
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -7,8 +7,8 @@ const routeHelpers = require.main.require('./src/controllers/helpers');
|
|
|
7
7
|
const Plugin = {};
|
|
8
8
|
|
|
9
9
|
const SETTINGS = {
|
|
10
|
-
pointsPerHeartbeat:
|
|
11
|
-
dailyCap:
|
|
10
|
+
pointsPerHeartbeat: 50,
|
|
11
|
+
dailyCap: 2500000,
|
|
12
12
|
coffeeCost: 250
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -16,11 +16,11 @@ const SETTINGS = {
|
|
|
16
16
|
async function addUserLog(uid, type, amount, desc) {
|
|
17
17
|
const logEntry = {
|
|
18
18
|
ts: Date.now(),
|
|
19
|
-
type: type,
|
|
19
|
+
type: type, // 'earn' veya 'spend'
|
|
20
20
|
amt: amount,
|
|
21
|
-
txt: desc
|
|
21
|
+
txt: desc // "Kahve Keyfi ☕" gibi metin
|
|
22
22
|
};
|
|
23
|
-
//
|
|
23
|
+
// Öğrenci geçmişine ekle (Son 50 işlem)
|
|
24
24
|
await db.listAppend(`niki:activity:${uid}`, logEntry);
|
|
25
25
|
await db.listTrim(`niki:activity:${uid}`, -50, -1);
|
|
26
26
|
}
|
|
@@ -33,7 +33,7 @@ async function addKasaLog(staffUid, customerName, customerUid) {
|
|
|
33
33
|
cuid: customerUid,
|
|
34
34
|
amt: SETTINGS.coffeeCost
|
|
35
35
|
};
|
|
36
|
-
// Kasa
|
|
36
|
+
// Kasa defterine ekle (Son 100 işlem)
|
|
37
37
|
await db.listAppend('niki:kasa:history', logEntry);
|
|
38
38
|
await db.listTrim('niki:kasa:history', -100, -1);
|
|
39
39
|
}
|
|
@@ -61,7 +61,7 @@ Plugin.init = async function (params) {
|
|
|
61
61
|
return res.json({ earned: true, points: SETTINGS.pointsPerHeartbeat, total: newBalance });
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
// 2. WALLET DATA (Cüzdan
|
|
64
|
+
// 2. WALLET DATA (Cüzdan + Geçmiş)
|
|
65
65
|
router.get('/api/niki-loyalty/wallet-data', middleware.ensureLoggedIn, async (req, res) => {
|
|
66
66
|
const uid = req.uid;
|
|
67
67
|
const today = new Date().toISOString().slice(0, 10).replace(/-/g, '');
|
|
@@ -82,11 +82,11 @@ Plugin.init = async function (params) {
|
|
|
82
82
|
dailyScore: dailyScore,
|
|
83
83
|
dailyCap: SETTINGS.dailyCap,
|
|
84
84
|
dailyPercent: dailyPercent,
|
|
85
|
-
history: (history || []).reverse() // En
|
|
85
|
+
history: (history || []).reverse() // En yeni en üstte
|
|
86
86
|
});
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
// 3. KASA GEÇMİŞİ (
|
|
89
|
+
// 3. KASA GEÇMİŞİ (Niki Kasa'nın Görmediği Kısım Burasıydı)
|
|
90
90
|
router.get('/api/niki-loyalty/kasa-history', middleware.ensureLoggedIn, async (req, res) => {
|
|
91
91
|
const isAdmin = await user.isAdministrator(req.uid);
|
|
92
92
|
const isMod = await user.isGlobalModerator(req.uid);
|
|
@@ -95,7 +95,7 @@ Plugin.init = async function (params) {
|
|
|
95
95
|
|
|
96
96
|
const history = await db.getListRange('niki:kasa:history', 0, -1);
|
|
97
97
|
|
|
98
|
-
// Kullanıcı resimlerini de
|
|
98
|
+
// Kullanıcı resimlerini de ekleyerek gönder
|
|
99
99
|
const enrichedHistory = await Promise.all((history || []).reverse().map(async (item) => {
|
|
100
100
|
const uData = await user.getUserFields(item.cuid, ['picture']);
|
|
101
101
|
item.picture = uData.picture;
|
|
@@ -119,7 +119,7 @@ Plugin.init = async function (params) {
|
|
|
119
119
|
return res.json({ success: true, token: token });
|
|
120
120
|
});
|
|
121
121
|
|
|
122
|
-
// 5. QR OKUT (Ödeme Alma)
|
|
122
|
+
// 5. QR OKUT (Ödeme Alma + LOGLAMA)
|
|
123
123
|
router.post('/api/niki-loyalty/scan-qr', middleware.ensureLoggedIn, async (req, res) => {
|
|
124
124
|
const { token } = req.body;
|
|
125
125
|
|
|
@@ -137,13 +137,13 @@ Plugin.init = async function (params) {
|
|
|
137
137
|
await user.decrementUserFieldBy(customerUid, 'niki_points', SETTINGS.coffeeCost);
|
|
138
138
|
await db.delete(`niki:qr:${token}`);
|
|
139
139
|
|
|
140
|
-
//
|
|
140
|
+
// DETAYLI LOG KAYDI
|
|
141
141
|
const customerData = await user.getUserFields(customerUid, ['username', 'picture']);
|
|
142
142
|
|
|
143
|
-
//
|
|
143
|
+
// Cüzdan için açıklama: "Kahve Keyfi ☕"
|
|
144
144
|
await addUserLog(customerUid, 'spend', SETTINGS.coffeeCost, 'Kahve Keyfi ☕');
|
|
145
145
|
|
|
146
|
-
//
|
|
146
|
+
// Kasa için kayıt
|
|
147
147
|
await addKasaLog(req.uid, customerData.username, customerUid);
|
|
148
148
|
|
|
149
149
|
return res.json({ success: true, customer: customerData, message: 'Onaylandı!' });
|