corebasic 1.0.69 → 1.0.70
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/libs/features.js +11 -3
- package/package.json +1 -1
package/libs/features.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as Dip from './dip.js'
|
|
2
2
|
import * as Kafka from './kafka.js'
|
|
3
3
|
import * as Utils from './utils.js'
|
|
4
4
|
import * as Messaging from './messaging.js'
|
|
@@ -70,8 +70,9 @@ export const start = async (app, url, file) => {
|
|
|
70
70
|
topic = topic.replace('Features.','')
|
|
71
71
|
while (true) {
|
|
72
72
|
try {
|
|
73
|
+
await Dip.update(`users.txns.${message.user}`, {_id: message.txn}, { $setOnInsert: { user: message.user, feature: message.feature, date: message.date, created: message.date, updated: message.date, status: "Queued" } }, {upsert: true}) // Can always update the status later
|
|
73
74
|
await features[message.feature].handler(topic, message)
|
|
74
|
-
await
|
|
75
|
+
await Dip.insert("Features.txns", {_id: message.txn, status: "Processed"})
|
|
75
76
|
break
|
|
76
77
|
} catch {
|
|
77
78
|
console.warn(`Feature: ${message.feature}, error in executing handler during Kafka.receive(topic: ${topic})`)
|
|
@@ -84,7 +85,7 @@ export const start = async (app, url, file) => {
|
|
|
84
85
|
// Transaction status api
|
|
85
86
|
app.get('/transactions/:id', async (req, res) => {
|
|
86
87
|
try {
|
|
87
|
-
let items = await
|
|
88
|
+
let items = await Dip.query("Features.txns", {_id: req.params.id})
|
|
88
89
|
if (items.length)
|
|
89
90
|
res.json({ data: { ...items[0], txn: items._id } })
|
|
90
91
|
else
|
|
@@ -93,6 +94,13 @@ export const start = async (app, url, file) => {
|
|
|
93
94
|
res.status(500).json({ message: "Failed to retreive data" })
|
|
94
95
|
}
|
|
95
96
|
})
|
|
97
|
+
app.get('/users/transactions', async (req, res) => {
|
|
98
|
+
try {
|
|
99
|
+
res.json({ data: await Dip.query(`users.txns.${message.user}`, {}, { $orderby: { date: -1 } }) })
|
|
100
|
+
} catch {
|
|
101
|
+
res.status(500).json({ message: "Failed to retreive data" })
|
|
102
|
+
}
|
|
103
|
+
})
|
|
96
104
|
|
|
97
105
|
try { await Messaging.start(app) } catch { console.log('Messaging failed to start. Maybe missing redis') }
|
|
98
106
|
}
|