generated from lucien/api-template
add: added mentions
This commit is contained in:
parent
dfb6639ecf
commit
6c8f354bf6
9 changed files with 208 additions and 9 deletions
|
@ -1,12 +1,22 @@
|
|||
const express = require('express');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const { getConnection, getLastMessages } = require('../libs/mysql');
|
||||
const { getConnection, getLastMessages, getMentions } = require('../libs/mysql');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
const connection = await getConnection();
|
||||
const messages = await getLastMessages(connection);
|
||||
|
||||
for (const message of messages) {
|
||||
if (message.content.includes('@')) {
|
||||
const mentions = await getMentions(connection, message.id);
|
||||
message.mentions = mentions;
|
||||
} else {
|
||||
message.mentions = [];
|
||||
}
|
||||
}
|
||||
|
||||
connection.end();
|
||||
res.send(messages);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue