fix: added BASE_URL support
This commit is contained in:
+3
-8
@@ -53,7 +53,7 @@ export async function createApiRouter() {
|
||||
},
|
||||
}
|
||||
|
||||
const db = createDatabase('./db.local.json', initialDatabaseValue)
|
||||
const db = createDatabase(process.env.DATABASE_PATH ?? './db.local.json', initialDatabaseValue)
|
||||
|
||||
async function getRequestUser(req: Request) {
|
||||
const userId = sessions.getUserForSession(req.cookies.sid)
|
||||
@@ -159,9 +159,7 @@ export async function createApiRouter() {
|
||||
let solutions = await getSolutions(db)
|
||||
// se l'utente non è loggato o se non è un amministratore allora mostra solo le soluzioni "visibili"
|
||||
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))
|
||||
}
|
||||
// filtra rispetto agli utenti
|
||||
if (queryUser !== null) {
|
||||
@@ -232,10 +230,7 @@ export async function createApiRouter() {
|
||||
return
|
||||
}
|
||||
// uno studente può modificare solo il campo "content"
|
||||
if (
|
||||
user.role === 'student' &&
|
||||
!validateObjectKeys<keyof SolutionModel>(req.body, ['content'])
|
||||
) {
|
||||
if (user.role === 'student' && !validateObjectKeys<keyof SolutionModel>(req.body, ['content'])) {
|
||||
res.status(StatusCodes.UNAUTHORIZED)
|
||||
res.send(`a student can only modify the field "content"`)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user