mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #2922 from gradido/eslint-disable-more-typesafety
refactor(backend): eslint disable more typesafety
This commit is contained in:
commit
f3af9aaec1
@ -1,8 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
|
||||
import { User } from '@entity/User'
|
||||
import { AuthChecker } from 'type-graphql'
|
||||
|
||||
@ -10,9 +5,10 @@ import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS'
|
||||
import { decode, encode } from '@/auth/JWT'
|
||||
import { RIGHTS } from '@/auth/RIGHTS'
|
||||
import { ROLE_UNAUTHORIZED, ROLE_USER, ROLE_ADMIN } from '@/auth/ROLES'
|
||||
import { Context } from '@/server/context'
|
||||
import { LogError } from '@/server/LogError'
|
||||
|
||||
export const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
|
||||
export const isAuthorized: AuthChecker<Context> = async ({ context }, rights) => {
|
||||
context.role = ROLE_UNAUTHORIZED // unauthorized user
|
||||
|
||||
// is rights an inalienable right?
|
||||
@ -47,7 +43,7 @@ export const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {
|
||||
}
|
||||
|
||||
// check for correct rights
|
||||
const missingRights = (<RIGHTS[]>rights).filter((right) => !context.role.hasRight(right))
|
||||
const missingRights = (<RIGHTS[]>rights).filter((right) => !context.role?.hasRight(right))
|
||||
if (missingRights.length !== 0) {
|
||||
throw new LogError('401 Unauthorized')
|
||||
}
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
||||
import { IsNull, getConnection } from '@dbTools/typeorm'
|
||||
import { Contribution as DbContribution } from '@entity/Contribution'
|
||||
import { ContributionMessage } from '@entity/ContributionMessage'
|
||||
@ -229,11 +228,11 @@ export class ContributionResolver {
|
||||
contributionMessage.createdAt = contributionToUpdate.updatedAt
|
||||
? contributionToUpdate.updatedAt
|
||||
: contributionToUpdate.createdAt
|
||||
const changeMessage = `${contributionToUpdate.contributionDate}
|
||||
const changeMessage = `${contributionToUpdate.contributionDate.toString()}
|
||||
---
|
||||
${contributionToUpdate.memo}
|
||||
---
|
||||
${contributionToUpdate.amount}`
|
||||
${contributionToUpdate.amount.toString()}`
|
||||
contributionMessage.message = changeMessage
|
||||
contributionMessage.isModerator = false
|
||||
contributionMessage.userId = user.id
|
||||
@ -259,7 +258,7 @@ export class ContributionResolver {
|
||||
@Ctx() context: Context,
|
||||
): Promise<Decimal[]> {
|
||||
logger.info(
|
||||
`adminCreateContribution(email=${email}, amount=${amount}, memo=${memo}, creationDate=${creationDate})`,
|
||||
`adminCreateContribution(email=${email}, amount=${amount.toString()}, memo=${memo}, creationDate=${creationDate})`,
|
||||
)
|
||||
const clientTimezoneOffset = getClientTimezoneOffset(context)
|
||||
if (!isValidDateString(creationDate)) {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { CONFIG } from './config'
|
||||
import { startValidateCommunities } from './federation/validateCommunities'
|
||||
import { createServer } from './server/createServer'
|
||||
|
||||
@ -2,9 +2,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { Contribution } from '@entity/Contribution'
|
||||
import { Transaction } from '@entity/Transaction'
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
@ -12,7 +9,6 @@ import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { findUserByEmail } from '@/graphql/resolver/UserResolver'
|
||||
import { CreationInterface } from '@/seeds/creation/CreationInterface'
|
||||
import { login, createContribution, confirmContribution } from '@/seeds/graphql/mutations'
|
||||
// import CONFIG from '@/config/index'
|
||||
|
||||
export const nMonthsBefore = (date: Date, months = 1): string => {
|
||||
return new Date(date.getFullYear(), date.getMonth() - months, 1).toISOString()
|
||||
|
||||
@ -1,10 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import { entities } from '@entity/index'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
import { name, internet, datatype } from 'faker'
|
||||
@ -43,10 +36,12 @@ export const cleanDB = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const resetEntity = async (entity: any) => {
|
||||
const [entityTypes] = entities
|
||||
|
||||
const resetEntity = async (entity: typeof entityTypes) => {
|
||||
const items = await entity.find({ withDeleted: true })
|
||||
if (items.length > 0) {
|
||||
const ids = items.map((i: any) => i.id)
|
||||
const ids = items.map((i) => i.id)
|
||||
await entity.delete(ids)
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ export interface Context {
|
||||
role?: Role
|
||||
user?: dbUser
|
||||
clientTimezoneOffset?: number
|
||||
gradidoID?: string
|
||||
// hack to use less DB calls for Balance Resolver
|
||||
lastTransaction?: dbTransaction
|
||||
transactionCount?: number
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
|
||||
import clonedeep from 'lodash.clonedeep'
|
||||
|
||||
const setHeadersPlugin = {
|
||||
|
||||
@ -1,12 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/unbound-method */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
|
||||
import { entities } from '@entity/index'
|
||||
import { createTestClient } from 'apollo-server-testing'
|
||||
|
||||
@ -15,6 +7,7 @@ import { createServer } from '@/server/createServer'
|
||||
import { i18n, logger } from './testSetup'
|
||||
|
||||
export const headerPushMock = jest.fn((t) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
||||
context.token = t.value
|
||||
})
|
||||
|
||||
@ -34,7 +27,7 @@ export const cleanDB = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
export const testEnvironment = async (testLogger: any = logger, testI18n: any = i18n) => {
|
||||
export const testEnvironment = async (testLogger = logger, testI18n = i18n) => {
|
||||
const server = await createServer(context, testLogger, testI18n)
|
||||
const con = server.con
|
||||
const testClient = createTestClient(server.apollo)
|
||||
@ -43,10 +36,12 @@ export const testEnvironment = async (testLogger: any = logger, testI18n: any =
|
||||
return { mutate, query, con }
|
||||
}
|
||||
|
||||
export const resetEntity = async (entity: any) => {
|
||||
const [entityTypes] = entities
|
||||
|
||||
export const resetEntity = async (entity: typeof entityTypes) => {
|
||||
const items = await entity.find({ withDeleted: true })
|
||||
if (items.length > 0) {
|
||||
const ids = items.map((i: any) => i.id)
|
||||
const ids = items.map((i) => i.id)
|
||||
await entity.delete(ids)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
import { CONFIG } from '@/config'
|
||||
import { i18n } from '@/server/localization'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
@ -10,7 +8,7 @@ CONFIG.EMAIL_TEST_MODUS = false
|
||||
jest.setTimeout(1000000)
|
||||
|
||||
jest.mock('@/server/logger', () => {
|
||||
const originalModule = jest.requireActual('@/server/logger')
|
||||
const originalModule = jest.requireActual<typeof logger>('@/server/logger')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
@ -27,7 +25,7 @@ jest.mock('@/server/logger', () => {
|
||||
})
|
||||
|
||||
jest.mock('@/server/localization', () => {
|
||||
const originalModule = jest.requireActual('@/server/localization')
|
||||
const originalModule = jest.requireActual<typeof i18n>('@/server/localization')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user