From 8822596952d6ab5d47d7d3917f9bd40fa93372a8 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 12 Nov 2024 12:52:16 +0100 Subject: [PATCH] fixing ts errors --- server/controllers/analytic.ts | 6 +++--- server/h5p/get-h5p-router.ts | 8 ++++---- server/middlewares/authenticate.ts | 2 +- server/middlewares/handleErrors.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/server/controllers/analytic.ts b/server/controllers/analytic.ts index d70256379..4bc60e959 100644 --- a/server/controllers/analytic.ts +++ b/server/controllers/analytic.ts @@ -278,8 +278,8 @@ analyticController.router.post( // Retrieve current user session or save the new one. // eslint-disable-next-line prefer-const let [sessionCount, userPhase] = await Promise.all([ - AppDataSource.getRepository(AnalyticSession).count({ where: { id: data.sessionId } }), - AppDataSource.getRepository(User).createQueryBuilder('user').select('user.firstlogin').where({ id: data.userId }).getRawOne(), + AppDataSource.getRepository(AnalyticSession).count({where: {id: data.sessionId}}), + AppDataSource.getRepository(User).createQueryBuilder('user').select('user.firstlogin').where({id: data.userId}).getRawOne(), ]); if (sessionCount === 0 && data.event === 'pageview' && data.params?.isInitial) { @@ -331,7 +331,7 @@ analyticController.router.post( pagePerf.data = data.params.perf as BrowserPerf; AppDataSource.getRepository(AnalyticPerformance).save(pagePerf).catch(); // no need to wait } else if (data.event === 'session' && data.params?.duration) { - AppDataSource.getRepository(AnalyticSession).update({ id: data.sessionId }, { duration: data.params?.duration }).catch(); // no need to wait + AppDataSource.getRepository(AnalyticSession).update({id: data.sessionId}, {duration: data.params?.duration}).catch(); // no need to wait } } catch (e) { logger.error(e); diff --git a/server/h5p/get-h5p-router.ts b/server/h5p/get-h5p-router.ts index bd27ec81f..9b83ca577 100644 --- a/server/h5p/get-h5p-router.ts +++ b/server/h5p/get-h5p-router.ts @@ -220,14 +220,14 @@ export const getH5pRouter = async () => { res.status(400).send('Malformed request'); return; } - const { id: contentId, metadata } = await h5pEditor.saveOrUpdateContentReturnMetaData( + const {id: contentId, metadata} = await h5pEditor.saveOrUpdateContentReturnMetaData( undefined as unknown as string, req.body.params.params, req.body.params.metadata, req.body.library, req.user as unknown as H5pUser, ); - res.status(200).json({ contentId, metadata }); + res.status(200).json({contentId, metadata}); }), ); @@ -238,14 +238,14 @@ export const getH5pRouter = async () => { res.status(400).send('Malformed request'); return; } - const { id: contentId, metadata } = await h5pEditor.saveOrUpdateContentReturnMetaData( + const {id: contentId, metadata} = await h5pEditor.saveOrUpdateContentReturnMetaData( req.params.contentId, req.body.params.params, req.body.params.metadata, req.body.library, req.user as unknown as H5pUser, ); - res.status(200).sendJSON({ contentId, metadata }); + res.status(200).sendJSON({contentId, metadata}); }), ); diff --git a/server/middlewares/authenticate.ts b/server/middlewares/authenticate.ts index 758938c33..9df9634c1 100644 --- a/server/middlewares/authenticate.ts +++ b/server/middlewares/authenticate.ts @@ -9,7 +9,7 @@ import { AppDataSource } from '../utils/data-source'; const secret: string = process.env.APP_SECRET || ''; -export function authenticate(userType: UserType | undefined = undefined): RequestHandler { +export function authenticate(userType?: UserType | UserType[] | undefined) { return async (req: Request, res: Response, next: NextFunction): Promise => { let token: string; if (req.cookies && req.cookies['access-token']) { diff --git a/server/middlewares/handleErrors.ts b/server/middlewares/handleErrors.ts index 37b32cf54..5356f7f38 100644 --- a/server/middlewares/handleErrors.ts +++ b/server/middlewares/handleErrors.ts @@ -31,7 +31,7 @@ interface PromiseRequestHandler extends RequestHandler { (req: Request, res: Response, next: NextFunction): Promise | void; } -export function handleErrors(fn: RequestHandler): RequestHandler { +export function handleErrors(fn: PromiseRequestHandler): PromiseRequestHandler { return (req: Request, res: Response, next: NextFunction): void => { const sendError = (err: Error | AppError): void => { logger.error(err.message);