|
|
@ -242,11 +242,12 @@ export async function createApiRouter() {
|
|
|
|
r.get('/api/solutions', async (req, res) => {
|
|
|
|
r.get('/api/solutions', async (req, res) => {
|
|
|
|
let queryUser = (req.query.user ?? null) as UserId | null
|
|
|
|
let queryUser = (req.query.user ?? null) as UserId | null
|
|
|
|
let queryProblem = (req.query.problem ?? null) as ProblemId | null
|
|
|
|
let queryProblem = (req.query.problem ?? null) as ProblemId | null
|
|
|
|
|
|
|
|
let isPublic = (req.query.public === '')
|
|
|
|
|
|
|
|
|
|
|
|
const requestUser = await getRequestUser(req)
|
|
|
|
const requestUser = await getRequestUser(req)
|
|
|
|
|
|
|
|
|
|
|
|
let solutions = await getSolutions(db)
|
|
|
|
let solutions = await getSolutions(db)
|
|
|
|
// se l'utente non è loggato o se non è un amministratore allora mostra solo le soluzioni "visibili"
|
|
|
|
// se l'utente non è loggato o se non è un amministratore, mostra solo le soluzioni "visibili"
|
|
|
|
if (!requestUser || !isAdministrator(requestUser.role)) {
|
|
|
|
if (!requestUser || !isAdministrator(requestUser.role)) {
|
|
|
|
solutions = solutions.filter(s => s.visible || (requestUser && s.sentBy === requestUser.id))
|
|
|
|
solutions = solutions.filter(s => s.visible || (requestUser && s.sentBy === requestUser.id))
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -254,6 +255,11 @@ export async function createApiRouter() {
|
|
|
|
if (queryUser !== null) {
|
|
|
|
if (queryUser !== null) {
|
|
|
|
solutions = solutions.filter(s => s.sentBy === queryUser)
|
|
|
|
solutions = solutions.filter(s => s.sentBy === queryUser)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isPublic) {
|
|
|
|
|
|
|
|
solutions = solutions.filter(s => s.visible)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// filtra rispetto ai problemi
|
|
|
|
// filtra rispetto ai problemi
|
|
|
|
if (queryProblem !== null) {
|
|
|
|
if (queryProblem !== null) {
|
|
|
|
solutions = solutions.filter(s => s.forProblem === queryProblem)
|
|
|
|
solutions = solutions.filter(s => s.forProblem === queryProblem)
|
|
|
|