Skip to content

Commit

Permalink
fix: 🚨 eslint manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerZade committed Oct 6, 2023
1 parent be5e426 commit 085519e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
3 changes: 2 additions & 1 deletion api/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
extends: ['standard-with-typescript'],
rules: {
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/semi': ['error', 'always']
'@typescript-eslint/semi': ['error', 'always'],
'@typescript-eslint/strict-boolean-expressions': 'off'
}
};
2 changes: 1 addition & 1 deletion api/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ const sequelize = new Sequelize({
});

sequelize.addModels([Container, Page]);
sequelize.sync();
void sequelize.sync();

export default sequelize;
21 changes: 11 additions & 10 deletions api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import v1Router from './v1';

import './database';
import { getSitemap } from './utils/sitemap';
import { wrapAsync } from './utils/express';
import { Page } from './models';

const app = express();
Expand All @@ -24,11 +25,11 @@ const app = express();
app.use(cors({
credentials: true,
origin: [
new RegExp('gruppe-adler.de$', 'i'),
new RegExp('localhost:[0-9]+$', 'i'),
new RegExp('127.0.0.1:[0-9]+$', 'i'),
new RegExp('127.0.0.1$', 'i'),
new RegExp('localhost$', 'i')
/gruppe-adler.de$/i,
/localhost:[0-9]+$/i,
/127.0.0.1:[0-9]+$/i,
/127.0.0.1$/i,
/localhost$/i
]
}));

Expand All @@ -48,7 +49,7 @@ app.use('/api/v1', v1Router);

app.use('/uploads', express.static(join(__dirname, '../data/uploads')));

app.get('/sitemap.xml', async (req, res) => {
app.get('/sitemap.xml', wrapAsync(async (req, res) => {
res.header('Content-Type', 'application/xml');
res.header('Content-Encoding', 'gzip');

Expand All @@ -59,7 +60,7 @@ app.get('/sitemap.xml', async (req, res) => {
console.error(err);
res.status(500).end();
}
});
}));

// frontend
if (existsSync(join(__dirname, '../frontend'))) {
Expand All @@ -86,7 +87,7 @@ if (existsSync(join(__dirname, '../frontend'))) {
express.static(join(__dirname, '../frontend'), {
setHeaders: (res: Response, path: string) => {
if (/.+\.(?!html).*$/i.test(path)) {
const cacheControl = cacheHeaders[path] || 'public, max-age=2678400';
const cacheControl = cacheHeaders[path] ?? 'public, max-age=2678400';

res.header('Cache-Control', cacheControl);
} else {
Expand All @@ -97,7 +98,7 @@ if (existsSync(join(__dirname, '../frontend'))) {
);

let pages: string[] = [];
const cachePages = async () => {
const cachePages = async (): Promise<void> => {
const newPages = await Page.findAll({ attributes: ['slug'] }) as Array<Pick<Page, 'slug'>>;

const slugs = newPages.map(p => p.slug);
Expand All @@ -108,7 +109,7 @@ if (existsSync(join(__dirname, '../frontend'))) {

Page.addHook('afterCreate', cachePages);
Page.addHook('afterDestroy', cachePages);
cachePages();
void cachePages();
app.get('*', (req: Request, res: Response, next: NextFunction) => {
if (!req.accepts('application/html')) {
next();
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/EventsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ArmaEventsService {
// this constructor is actually important to make sure it is private (singleton pattern)
// eslint-disable-next-line no-useless-constructor, @typescript-eslint/no-empty-function
private constructor () {
this.cacheEvents();
void this.cacheEvents();

// fetch new events every half an hour
setInterval(this.cacheEvents.bind(this), 1000 * 60 * 30);
Expand Down
4 changes: 3 additions & 1 deletion api/src/utils/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { type Request, type Response, type NextFunction, type RequestHandler } f
import { validationResult } from 'express-validator';
import ResponseError from './ResponseError';

export const wrapAsync = (fn: RequestHandler): RequestHandler => (req: Request, res: Response, next: NextFunction): void => {
type AsyncRequestHandler = (...params: Parameters<RequestHandler>) => Promise<ReturnType<RequestHandler>>;

export const wrapAsync = (fn: AsyncRequestHandler): RequestHandler => (req: Request, res: Response, next: NextFunction): void => {
// Make sure to `.catch()` any errors and pass them along to the `next()`
// middleware in the chain, in this case the error handler.
fn(req, res, next).catch(next);
Expand Down
2 changes: 1 addition & 1 deletion api/src/utils/sso.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function fetchUser (token: string): Promise<SSOUser | null> {
return json.data.authenticate;
}

async function validateToken (token: string) {
async function validateToken (token: string): Promise<void> {
const user = await fetchUser(token);

if (user === null) throw new ReponseError(401);
Expand Down

0 comments on commit 085519e

Please sign in to comment.