settings: set avatar
This commit is contained in:
43
src/inc/routes/apiv2/settings.mjs
Normal file
43
src/inc/routes/apiv2/settings.mjs
Normal file
@ -0,0 +1,43 @@
|
||||
import sql from '../../sql.mjs';
|
||||
import lib from '../../lib.mjs';
|
||||
|
||||
export default router => {
|
||||
router.group(/^\/api\/v2\/settings/, group => {
|
||||
group.put(/\/setAvatar/, lib.auth, async (req, res) => {
|
||||
if(!req.post.avatar) {
|
||||
return res.json({
|
||||
msg: 'no avatar provided',
|
||||
debug: req.post
|
||||
}, 400); // bad request
|
||||
}
|
||||
|
||||
const avatar = +req.post.avatar;
|
||||
|
||||
const itemid = (
|
||||
await sql('items')
|
||||
.select('id')
|
||||
.where('id', avatar)
|
||||
)?.[0]?.id;
|
||||
|
||||
if(!itemid) {
|
||||
return res.json({
|
||||
msg: 'itemid not found'
|
||||
}, 404); // not found
|
||||
}
|
||||
|
||||
const q = await sql('user_options')
|
||||
.update({
|
||||
avatar
|
||||
})
|
||||
.where('user_id', req.session.id);
|
||||
|
||||
return res.json({
|
||||
msg: q
|
||||
}, 200);
|
||||
});
|
||||
|
||||
return group;
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
Reference in New Issue
Block a user