making better use of the notification system
This commit is contained in:
@@ -125,7 +125,7 @@ export default (router, tpl) => {
|
||||
if (req.url.qs?.id) {
|
||||
const id = +req.url.qs.id;
|
||||
const f0ck = await db`
|
||||
select dest, mime
|
||||
select dest, mime, username, id
|
||||
from "items"
|
||||
where
|
||||
id = ${id} and
|
||||
@@ -138,6 +138,19 @@ export default (router, tpl) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Notify User
|
||||
try {
|
||||
const uploader = await db`select id from "user" where login = ${f0ck[0].username} limit 1`;
|
||||
if (uploader.length > 0) {
|
||||
await db`
|
||||
INSERT INTO notifications (user_id, type, reference_id, item_id)
|
||||
VALUES (${uploader[0].id}, 'approve', 0, ${id})
|
||||
`;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[ADMIN APPROVE] Failed to notify user:', err);
|
||||
}
|
||||
|
||||
await db`update "items" set active = 'true', is_deleted = false where id = ${id}`;
|
||||
|
||||
// Check if files need moving (if they are in deleted/)
|
||||
|
||||
@@ -9,10 +9,11 @@ export default (router, tpl) => {
|
||||
try {
|
||||
const notifications = await db`
|
||||
SELECT n.id, n.type, n.item_id, n.reference_id, n.created_at, n.is_read,
|
||||
u.user as from_user, u.id as from_user_id
|
||||
COALESCE(u.user, 'System') as from_user,
|
||||
COALESCE(u.id, 0) as from_user_id
|
||||
FROM notifications n
|
||||
JOIN comments c ON n.reference_id = c.id
|
||||
JOIN "user" u ON c.user_id = u.id
|
||||
LEFT JOIN comments c ON n.reference_id = c.id
|
||||
LEFT JOIN "user" u ON c.user_id = u.id
|
||||
WHERE n.user_id = ${req.session.id} AND n.is_read = false
|
||||
ORDER BY n.created_at DESC
|
||||
LIMIT 20
|
||||
|
||||
Reference in New Issue
Block a user