1
This commit is contained in:
parent
4d2538531f
commit
60da68c342
@ -6,7 +6,39 @@ const metaFactory = require('../metadata/factory');
|
||||
const serviceFactory = require('../services/factory');
|
||||
const { config, webhook } = require('@imtbl/sdk');
|
||||
|
||||
async function procEvent(req, rsp) {
|
||||
async function procEvent(event, rsp) {
|
||||
const idx = 0;
|
||||
const dbKey = 'BcEventDb' + idx;
|
||||
const {err, conn} = await app.getDbConn(dbKey);
|
||||
if (err) {
|
||||
rsp.status(500).send(err);
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const eventName = event.event_name;
|
||||
const eventId = event.event_id;
|
||||
const chain = event.chain;
|
||||
await conn.upsert(
|
||||
't_webhook_event',
|
||||
[
|
||||
['event_id', eventId],
|
||||
],
|
||||
[],
|
||||
[
|
||||
['event_name', eventName],
|
||||
['event_id', eventId],
|
||||
['chain', chain],
|
||||
['raw_data', utils.jsonEncode(event)],
|
||||
]
|
||||
);
|
||||
rsp.send(utils.jsonEncode({"status": "ok"}));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
rsp.status(500).send(e);
|
||||
} finally {
|
||||
conn.release();
|
||||
}
|
||||
}
|
||||
|
||||
async function webhooks(req, rsp) {
|
||||
@ -23,38 +55,10 @@ async function webhooks(req, rsp) {
|
||||
}
|
||||
);
|
||||
|
||||
const idx = 0;
|
||||
const dbKey = 'BcEventDb' + idx;
|
||||
const {err, conn} = await app.getDbConn(dbKey);
|
||||
if (err) {
|
||||
rsp.status(500).send(err);
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const body = req.body;
|
||||
const eventName = body.Message.event_name;
|
||||
const eventId = body.Message.event_id;
|
||||
const chain = body.Message.chain;
|
||||
await conn.upsert(
|
||||
't_webhook_event',
|
||||
[
|
||||
['event_id', eventId],
|
||||
],
|
||||
[],
|
||||
[
|
||||
['event_name', eventName],
|
||||
['event_id', eventId],
|
||||
['chain', chain],
|
||||
['raw_data', body],
|
||||
]
|
||||
);
|
||||
if (events.length > 0) {
|
||||
|
||||
} else {
|
||||
rsp.send(utils.jsonEncode({"status": "ok"}));
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
rsp.status(500).send(e);
|
||||
} finally {
|
||||
conn.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user