Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Aug 17, 2023
1 parent 2b23622 commit 0e2dae4
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ app.use((request, response, next) => {
response.locals.urlPrefix = getConfigProperty('reverseProxy.urlPrefix');
next();
});
app.get(urlPrefix + '/', sessionChecker, (_request, response) => {
app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => {
response.redirect(`${urlPrefix}/dashboard`);
});
app.use(`${urlPrefix}/dashboard`, sessionChecker, routerDashboard);
Expand All @@ -127,15 +127,15 @@ app.get(`${urlPrefix}/logout`, (request, response) => {
Object.hasOwn(request.cookies, sessionCookieName)) {
request.session.destroy(() => {
response.clearCookie(sessionCookieName);
response.redirect(urlPrefix + '/');
response.redirect(`${urlPrefix}/`);
});
}
else {
response.redirect(urlPrefix + '/login');
response.redirect(`${urlPrefix}/login`);
}
});
app.use((request, _response, next) => {
debug(request.url);
next(createError(404, 'File not found: ' + request.url));
next(createError(404, `File not found: ${request.url}`));
});
export default app;
8 changes: 4 additions & 4 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ app.use((request, response, next) => {
next()
})

app.get(urlPrefix + '/', sessionChecker, (_request, response) => {
app.get(`${urlPrefix}/`, sessionChecker, (_request, response) => {
response.redirect(`${urlPrefix}/dashboard`)
})

Expand All @@ -247,17 +247,17 @@ app.get(`${urlPrefix}/logout`, (request, response) => {
) {
request.session.destroy(() => {
response.clearCookie(sessionCookieName)
response.redirect(urlPrefix + '/')
response.redirect(`${urlPrefix}/`)
})
} else {
response.redirect(urlPrefix + '/login')
response.redirect(`${urlPrefix}/login`)
}
})

// Catch 404 and forward to error handler
app.use((request, _response, next) => {
debug(request.url)
next(createError(404, 'File not found: ' + request.url))
next(createError(404, `File not found: ${request.url}`))
})

export default app
4 changes: 2 additions & 2 deletions handlers/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const adminGetHandler = (request, response, next) => {
next();
return;
}
response.redirect(urlPrefix + '/dashboard');
response.redirect(`${urlPrefix}/dashboard`);
};
export const adminPostHandler = (request, response, next) => {
if (request.session.user?.isAdmin ?? false) {
Expand All @@ -25,7 +25,7 @@ export const updateGetHandler = (request, response, next) => {
next();
return;
}
response.redirect(urlPrefix + '/dashboard');
response.redirect(`${urlPrefix}/dashboard`);
};
export const updatePostHandler = (request, response, next) => {
if (request.session.user?.canUpdate ?? false) {
Expand Down
4 changes: 2 additions & 2 deletions handlers/permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const adminGetHandler: RequestHandler = (request, response, next) => {
return
}

response.redirect(urlPrefix + '/dashboard')
response.redirect(`${urlPrefix}/dashboard`)
}

export const adminPostHandler: RequestHandler = (request, response, next) => {
Expand All @@ -35,7 +35,7 @@ export const updateGetHandler: RequestHandler = (request, response, next) => {
return
}

response.redirect(urlPrefix + '/dashboard')
response.redirect(`${urlPrefix}/dashboard`)
}

export const updatePostHandler: RequestHandler = (request, response, next) => {
Expand Down
6 changes: 3 additions & 3 deletions helpers/functions.authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function authenticateViaActiveDirectory(userName, password) {
return await new Promise((resolve) => {
try {
const ad = new ActiveDirectory(activeDirectoryConfig);
ad.authenticate(userDomain + '\\' + userName, password, (error, auth) => {
ad.authenticate(`${userDomain}\\${userName}`, password, (error, auth) => {
let authenticated = false;
if ((error ?? '') === '') {
authenticated = auth;
Expand All @@ -25,7 +25,7 @@ async function authenticateViaActiveDirectory(userName, password) {
}
const adWebAuthConfig = getConfigProperty('adWebAuthConfig');
async function authenticateViaADWebAuth(userName, password) {
return await adWebAuth.authenticate(userDomain + '\\' + userName, password, adWebAuthConfig);
return await adWebAuth.authenticate(`${userDomain}\\${userName}`, password, adWebAuthConfig);
}
const authenticateFunction = activeDirectoryConfig === undefined
? authenticateViaADWebAuth
Expand All @@ -48,5 +48,5 @@ export function getSafeRedirectURL(possibleRedirectURL = '') {
return urlPrefix + urlToCheck;
}
}
return urlPrefix + '/dashboard/';
return `${urlPrefix}/dashboard/`;
}
6 changes: 3 additions & 3 deletions helpers/functions.authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function authenticateViaActiveDirectory(
try {
const ad = new ActiveDirectory(activeDirectoryConfig)

ad.authenticate(userDomain + '\\' + userName, password, (error, auth) => {
ad.authenticate(`${userDomain}\\${userName}`, password, (error, auth) => {
let authenticated = false

if ((error ?? '') === '') {
Expand All @@ -41,7 +41,7 @@ async function authenticateViaADWebAuth(
password: string
): Promise<boolean> {
return await adWebAuth.authenticate(
userDomain + '\\' + userName,
`${userDomain}\\${userName}`,
password,
adWebAuthConfig
)
Expand Down Expand Up @@ -80,5 +80,5 @@ export function getSafeRedirectURL(possibleRedirectURL = ''): string {
}
}

return urlPrefix + '/dashboard/'
return `${urlPrefix}/dashboard/`
}
4 changes: 1 addition & 3 deletions tasks/uploadedFilesProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ async function processUploadedFiles() {
processAgainOnComplete = false;
const fileNames = await fs.readdir(uploadsFolder);
const rightNow = new Date();
const systemFolderPath = path.join(importedFolderRoot, rightNow.getFullYear().toString() +
'-' +
(rightNow.getMonth() + 1).toString());
const systemFolderPath = path.join(importedFolderRoot, `${rightNow.getFullYear().toString()}-${(rightNow.getMonth() + 1).toString()}`);
try {
await fs.mkdir(systemFolderPath);
}
Expand Down
4 changes: 1 addition & 3 deletions tasks/uploadedFilesProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ async function processUploadedFiles(): Promise<void> {

const systemFolderPath = path.join(
importedFolderRoot,
rightNow.getFullYear().toString() +
'-' +
(rightNow.getMonth() + 1).toString()
`${rightNow.getFullYear().toString()}-${(rightNow.getMonth() + 1).toString()}`
)

try {
Expand Down

0 comments on commit 0e2dae4

Please sign in to comment.