Persist events in database
This commit is contained in:
parent
7b742d4750
commit
565048fca8
2 changed files with 23 additions and 6 deletions
3
app.js
3
app.js
|
@ -111,7 +111,8 @@ appRouter.post('/', basicAuth(basicAuthConfig), (req, res) => {
|
|||
.then((app) => {
|
||||
res.json(app);
|
||||
}).catch((err) => {
|
||||
res.status(500).send();
|
||||
console.error(err);
|
||||
res.sendStatus(500);
|
||||
})
|
||||
});
|
||||
|
||||
|
|
26
event.js
26
event.js
|
@ -127,6 +127,19 @@ export class EventRepository {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
static createEvent(event) {
|
||||
return new Promise((resolve, reject) => {
|
||||
pool.query('INSERT INTO events SET ?', event, (err, res, fields) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(event);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const eventRouter = express.Router()
|
||||
|
@ -173,7 +186,7 @@ eventRouter.post('/', (req, res) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const event = new Event(
|
||||
EventRepository.createEvent(new Event(
|
||||
req.body.appId,
|
||||
req.body.date,
|
||||
req.body.userAgent,
|
||||
|
@ -185,8 +198,11 @@ eventRouter.post('/', (req, res) => {
|
|||
req.body.sessionId,
|
||||
req.body.data,
|
||||
req.body.type,
|
||||
);
|
||||
|
||||
events.push(event);
|
||||
res.json(event);
|
||||
))
|
||||
.then((event) => {
|
||||
res.json(event);
|
||||
}).catch((err) => {
|
||||
console.error(err);
|
||||
res.sendStatus(500);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue