add get line msg log api
This commit is contained in:
+33
-1
@@ -5,7 +5,9 @@ const {
|
||||
resObject,
|
||||
APIError,
|
||||
genError,
|
||||
checkSession
|
||||
checkSession,
|
||||
calPage,
|
||||
toInt
|
||||
} = require('@libs/route-utils')
|
||||
const DB = require('@libs/database')
|
||||
const r = new Router()
|
||||
@@ -67,6 +69,36 @@ r.get('/session', checkSession, async (c, n) => {
|
||||
})
|
||||
})
|
||||
|
||||
r.get('/line_msg', checkSession, async (c, n) => {
|
||||
let p = toInt(c.query.p, 1, 1)
|
||||
|
||||
let text = `select count(*) as c from "public"."line_message_log"`
|
||||
let msgCount = await c.db.query({text})
|
||||
if (msgCount.rowCount === 0) throw genError('InternalError', 'database query fail')
|
||||
if (!('c' in msgCount.rows[0])) throw genError('InternalError', 'database query fail')
|
||||
let page = calPage(msgCount.rows[0].c, p, 20)
|
||||
text = `select g.name, u.name as user, m.message, m.ctime from "public"."line_message_log" m
|
||||
left join "public"."line_group" g
|
||||
on g.id = m.group
|
||||
left join "public"."line_user" u
|
||||
on u.id = m.user
|
||||
order by m.ctime desc
|
||||
offset $1
|
||||
limit $2`
|
||||
let values = [page.offset, page.limit]
|
||||
let msgData = await c.db.query({
|
||||
text,
|
||||
values
|
||||
})
|
||||
c.obj = resObject('Success', {
|
||||
messages: msgData.rows,
|
||||
page: {
|
||||
cur: page.page,
|
||||
total: page.totalPage
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
r.use('/twitch', require('./twitch').routes())
|
||||
|
||||
module.exports = r
|
||||
|
||||
Reference in New Issue
Block a user