mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: change theme
This commit is contained in:
parent
aca521b54f
commit
9426b73940
17 changed files with 326 additions and 21 deletions
|
|
@ -1,23 +1,35 @@
|
|||
const pool = require('../db/pool');
|
||||
|
||||
const PROFILE_FIELDS = 'id, authentik_sub, name, username, email, avatar_url, groups, is_admin, created_at';
|
||||
|
||||
async function findById(id) {
|
||||
const { rows } = await pool.query(
|
||||
'SELECT id, authentik_sub, name, email, is_admin, created_at FROM users WHERE id = $1',
|
||||
[id]
|
||||
);
|
||||
const { rows } = await pool.query(`SELECT ${PROFILE_FIELDS} FROM users WHERE id = $1`, [id]);
|
||||
return rows[0] || null;
|
||||
}
|
||||
|
||||
async function upsertFromClaims({ sub, name, email, isAdmin }) {
|
||||
async function upsertFromClaims({ sub, name, username, email, avatarUrl, groups, isAdmin }) {
|
||||
const { rows } = await pool.query(
|
||||
`INSERT INTO users (authentik_sub, name, email, is_admin)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
`INSERT INTO users (authentik_sub, name, username, email, avatar_url, groups, is_admin)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||
ON CONFLICT (authentik_sub)
|
||||
DO UPDATE SET name = $2, email = $3, is_admin = $4, updated_at = now()
|
||||
RETURNING id, authentik_sub, name, email, is_admin, created_at`,
|
||||
[sub, name, email, isAdmin]
|
||||
DO UPDATE SET name = $2, username = $3, email = $4, avatar_url = $5, groups = $6, is_admin = $7, updated_at = now()
|
||||
RETURNING ${PROFILE_FIELDS}`,
|
||||
[sub, name, username || null, email, avatarUrl || null, groups || [], isAdmin]
|
||||
);
|
||||
return rows[0];
|
||||
}
|
||||
|
||||
module.exports = { findById, upsertFromClaims };
|
||||
async function getActivityStats(userId) {
|
||||
const [songs, suggestions, votes] = await Promise.all([
|
||||
pool.query('SELECT COUNT(*)::int AS count FROM songs WHERE added_by = $1', [userId]),
|
||||
pool.query('SELECT COUNT(*)::int AS count FROM suggestions WHERE suggested_by = $1', [userId]),
|
||||
pool.query('SELECT COUNT(*)::int AS count FROM suggestion_votes WHERE user_id = $1', [userId]),
|
||||
]);
|
||||
return {
|
||||
songsAdded: songs.rows[0].count,
|
||||
suggestionsProposed: suggestions.rows[0].count,
|
||||
votesCast: votes.rows[0].count,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { findById, upsertFromClaims, getActivityStats };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue