Skip to content

Commit

Permalink
Fix eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
OmTheTurtle committed Jul 10, 2021
1 parent a6bdfbd commit a2542d0
Show file tree
Hide file tree
Showing 18 changed files with 56 additions and 47 deletions.
11 changes: 2 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
{
"eslint.validate": ["javascript", "typescript"],
"editor.formatOnSave": true,
"[javascript]": {
"editor.formatOnSave": false
},
"[typescript]": {
"editor.formatOnSave": false
},
"[markdown]": {
"editor.formatOnSave": false
},
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/dist": true,
"**/coverage": true
},
"typescript.referencesCodeLens.enabled": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.insertFinalNewline": true
"files.insertFinalNewline": true,
"eslint.enable": true
}
3 changes: 1 addition & 2 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
module.exports = (/*on, config*/) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
2 changes: 1 addition & 1 deletion knexfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
require('dotenv').config()
require('ts-node/register')
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { knexSnakeCaseMappers } = require('objection')

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion public/js/picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const options = {
enableTime: true,
dateFormat: 'Y-m-d H:i',
minDate: 'today',
// eslint-disable-next-line @typescript-eslint/camelcase
/* eslint-disable-next-line @typescript-eslint/naming-convention */
time_24hr: true,
disableMobile: 'true',
}
Expand Down
2 changes: 1 addition & 1 deletion public/js/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;(function () {
(function () {
const templates = document.querySelectorAll('svg template')
let el, template, attribs, attrib, count, child, content
for (let i = 0; i < templates.length; i++) {
Expand Down
6 changes: 3 additions & 3 deletions src/components/groups/group.middlewares.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextFunction, Request, Response } from 'express'
import { check } from 'express-validator'
import { check, ValidationChain } from 'express-validator'
import { writeFileSync } from 'fs'
import * as ics from 'ics'
import winston from 'winston'
Expand Down Expand Up @@ -111,7 +111,7 @@ export const isGroupOwnerOrAdmin = asyncWrapper(
}
)

export const createICSEvent = (req: Request, res: Response) => {
export const createICSEvent = (req: Request, res: Response): void => {
const group = req.group
const { startDate, endDate } = group

Expand Down Expand Up @@ -174,7 +174,7 @@ function isValidHttpsUrl(str) {
return pattern.test(str) && url.protocol === 'https:'
}

export const validateGroup = () => {
export const validateGroup = (): ValidationChain[] => {
return [
check('name', 'A csoport neve max 100 karakter hosszú nem üres szöveg lehet')
.isString()
Expand Down
10 changes: 6 additions & 4 deletions src/components/groups/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ export class Group extends Model {
createdAt: Date
maxAttendees: number

$beforeInsert() {
$beforeInsert(): void {
this.createdAt = new Date()
}

static get tableName() {
static get tableName(): string {
return 'groups'
}

static get relationMappings() {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
static get relationMappings(): Record<string, any> {
return {
users: {
relation: Model.ManyToManyRelation,
Expand All @@ -45,7 +46,8 @@ export class Group extends Model {
}
}

static get jsonSchema() {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
static get jsonSchema(): Record<string, any> {
return {
type: 'object',
required: ['name', 'description', 'doNotDisturb', 'tags', 'startDate', 'endDate'],
Expand Down
13 changes: 9 additions & 4 deletions src/components/rooms/room.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import { DAYS_OF_WEEK, ROOMS } from '../../util/constants'
import { RawUsageData } from './rawusagedata'
import { raw } from 'objection'

export const getBusyRooms = async () => {
type ParsedUsageData = Map<number, {
day: typeof DAYS_OF_WEEK[number]
count: number
}[]>

export const getBusyRooms = async (): Promise<Group[]> => {
const currentTime = new Date()
return (await Group.query()
.where('startDate', '<', currentTime)
.andWhere('endDate', '>', currentTime))
}

export const getEventsForRoom = async (roomId: number) =>
export const getEventsForRoom = async (roomId: number): Promise<Group[]> =>
await Group.query().where({ room: roomId })

const fetchUsageData = async (start: Date, end: Date) => {
Expand All @@ -30,7 +35,7 @@ const fetchUsageData = async (start: Date, end: Date) => {
.groupBy('day') as Promise<RawUsageData[]>
}

const parseUsageData = (rawData: RawUsageData[], today: Date) => {
const parseUsageData = (rawData: RawUsageData[], today: Date): ParsedUsageData => {

const result = new Map<number, { day: typeof DAYS_OF_WEEK[number], count: number }[]>()

Expand All @@ -57,7 +62,7 @@ const parseUsageData = (rawData: RawUsageData[], today: Date) => {
/**
* Usage data for the next seven days for all rooms
*/
export const getUsageData = async () => {
export const getUsageData = async (): Promise<ParsedUsageData> => {
const now = new Date()
const today = startOfDay(now)
const usageData = await fetchUsageData(now, addWeeks(today, 1))
Expand Down
9 changes: 5 additions & 4 deletions src/components/tickets/ticket.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Model } from 'objection'

export enum StatusType {
export enum StatusType {
SENT = 'SENT',
IN_PROGRESS = 'IN_PROGRESS',
DONE = 'DONE',
Expand All @@ -15,15 +15,16 @@ export class Ticket extends Model {
createdAt: Date
userId: number

$beforeInsert() {
$beforeInsert(): void {
this.createdAt = new Date()
}

static get tableName() {
static get tableName(): string {
return 'tickets'
}

static get jsonSchema() {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
static get jsonSchema(): Record<string, any> {
return {
type: 'object',
required: ['roomNumber', 'description', 'userId'],
Expand Down
2 changes: 1 addition & 1 deletion src/components/users/user.middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Request, Response, NextFunction } from 'express'

import { User } from './user'

export const isSameUser = (req: Request, res: Response, next: NextFunction) => {
export const isSameUser = (req: Request, res: Response, next: NextFunction): void => {
if (parseInt(req.params.id) !== (req.user as User).id) {
res.status(400).json({ errors: [{ msg: 'Nem találahtó felhasználó a megadott ID-val' }] })
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/components/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const updateUser = asyncWrapper(async (req: Request, res: Response, next:
next()
})

export const createUser = async (user: OAuthUser) => {
export const createUser = async (user: OAuthUser): Promise<User> => {
return await User.transaction(async trx => {
return await User.query(trx)
.insert(
Expand Down
8 changes: 5 additions & 3 deletions src/components/users/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export class User extends Model {
floor: number
wantEmail: boolean
groups: Group[]
static get tableName() {
static get tableName(): string {
return 'users'
}

static get relationMappings() {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
static get relationMappings(): Record<string, any> {
return {
groups: {
relation: Model.ManyToManyRelation,
Expand All @@ -40,7 +41,8 @@ export class User extends Model {
}
}

static get jsonSchema() {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
static get jsonSchema(): Record<string, any> {
return {
type: 'object',
required: ['name', 'email', 'authSchId'],
Expand Down
9 changes: 6 additions & 3 deletions src/config/passport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ passport.use(
async (
accessToken: string,
_refreshToken: string,
_profile: {},
_profile: unknown,
done: (err: Error, user: User) => void
) => {
const responseUser = await fetch(
Expand Down Expand Up @@ -55,7 +55,9 @@ passport.deserializeUser(async (id: number, done) => {
/**
* Login Required middleware.
*/
export const isAuthenticated = (req: Request, res: Response, next: NextFunction) => {
export const isAuthenticated =
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
(req: Request, res: Response, next: NextFunction): Response<any, Record<string, any>> => {
const contentType = req.headers['content-type']

if (req.isAuthenticated()) {
Expand All @@ -75,7 +77,8 @@ export const isAuthenticated = (req: Request, res: Response, next: NextFunction)
* Authorization Required middleware.
*/
export const requireRoles = (...roles: RoleType[]) => {
return (req: Request, res: Response, next: NextFunction) => {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return (req: Request, res: Response, next: NextFunction): Response<any, Record<string, any>> => {
const role = (req.user as User)?.role
if (roles.some((element) => role == element)) {
next()
Expand Down
11 changes: 6 additions & 5 deletions src/util/asyncWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Request, Response , NextFunction } from 'express'


export const asyncWrapper = fn => (req: Request, res: Response, next: NextFunction) =>
Promise
.resolve(fn(req, res, next))
.catch(next)
export const asyncWrapper = (fn: (...params: any[]) => any) =>
(req: Request, res: Response, next: NextFunction): Promise<any> =>
Promise
.resolve(fn(req, res, next))
.catch(next)
3 changes: 2 additions & 1 deletion src/util/emailTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const styles = {
margin-top:2rem;
margin-bottom: 0px;"`
}
export const generateEmailHTML = (user: User, email: Email) => {

export const generateEmailHTML = (user: User, email: Email): string => {
return `<html>
<body style=${styles.body}>
<div style=${styles.titleDiv}>
Expand Down
2 changes: 1 addition & 1 deletion src/util/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Email {
linkTitle?: string
}

export const sendEmail = (recipients: User[], email: Email) => {
export const sendEmail = (recipients: User[], email: Email): void => {
if (process.env.NODE_ENV === 'production') {
recipients.filter(user => user.wantEmail).forEach(user => {
transporter.sendMail({
Expand Down
2 changes: 1 addition & 1 deletion src/util/sendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Response } from 'express'

type MessageType = 'danger' | 'success' | 'warning'

const sendMessage = (res: Response, message: string, type: MessageType = 'danger') => {
const sendMessage = (res: Response, message: string, type: MessageType = 'danger'): void => {
res.cookie('message', JSON.stringify({
mes: message,
type: type,
Expand Down
6 changes: 4 additions & 2 deletions src/util/validators.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Request, Response, NextFunction } from 'express'
import { validationResult } from 'express-validator'

type ExpressMiddleware = (req: Request, res: Response, next: NextFunction) => void

export interface ValidationError {
msg: string
}

export function handleValidationError(statusCode: number) {
export function handleValidationError(statusCode: number): ExpressMiddleware {
return function (req: Request, res: Response, next: NextFunction) {
const errors = validationResult(req)

Expand All @@ -16,7 +18,7 @@ export function handleValidationError(statusCode: number) {
}
}

export function checkIdParam(req: Request, res: Response, next: NextFunction) {
export function checkIdParam(req: Request, res: Response, next: NextFunction): void {
if (isNaN(parseInt(req.params.id))) {
res.render('error/not-found')
} else {
Expand Down

0 comments on commit a2542d0

Please sign in to comment.