add new api endpoint

This commit is contained in:
Mystikfluu 2022-08-10 23:57:26 +02:00
parent 3147af35ec
commit 2eb7ed0ccf

View File

@ -15,9 +15,32 @@ module.exports = {
const columns = [
"dms_user_name","dms_text","dms_time","dms_special_text","dms_id","dms_from_bot","dms_reply_id"
]
//dms_user_name = sender
//dms_receiver = receiver
//if (sender == current and receiver == other) or (receiver == current and sender == other)
let sql = `select ${columns.join(",")} from ipost.dms where ((dms_receiver = ? and dms_user_name = ?) or (dms_receiver = ? and dms_user_name = ?)) order by dms_id desc;`
con.query(sql, [otherperson,encodeURIComponent(res.locals.username),encodeURIComponent(res.locals.username),otherperson], function (err, result) {
if (err) throw err;
res.json(result)
});
})
let sql = `select ${columns.join(",")} from ipost.dms where (dms_receiver = ? or dms_receiver = ?) order by dms_id desc;`
con.query(sql, [otherperson,encodeURIComponent(res.locals.username)], function (err, result) {
router.get("/api/dms/conversations", async function(req,res) {
res.set("Access-Control-Allow-Origin","*")
let otherperson = encodeURIComponent(req.query.otherperson||"")
if(typeof otherperson != "string" || otherperson.length > 100 || otherperson=="") {
res.status(400).json({"error": "invalid otherperson given"})
return
}
const columns = [
"dms_user_name","dms_receiver"
]
let sql = `select ${columns.join(",")} from ipost.dms where ((dms_receiver = ? and dms_user_name = ?) or (dms_receiver = ? and dms_user_name = ?)) group by dms_receiver;`
con.query(sql, [otherperson,encodeURIComponent(res.locals.username),encodeURIComponent(res.locals.username),otherperson], function (err, result) {
if (err) throw err;
res.json(result)
});