diff --git a/backend/src/auth/JWT.ts b/backend/src/auth/JWT.ts index 75a69cd0c..90e6947ba 100644 --- a/backend/src/auth/JWT.ts +++ b/backend/src/auth/JWT.ts @@ -8,7 +8,7 @@ import { CustomJwtPayload } from './CustomJwtPayload' export const decode = (token: string): CustomJwtPayload | null => { if (!token) throw new LogError('401 Unauthorized') try { - return verify(token, CONFIG.JWT_SECRET) + return verify(token, CONFIG.JWT_SECRET) as CustomJwtPayload } catch (err) { return null } diff --git a/backend/src/config/index.ts b/backend/src/config/index.ts index fc88011ea..ea3b5c19e 100644 --- a/backend/src/config/index.ts +++ b/backend/src/config/index.ts @@ -16,7 +16,7 @@ const constants = { DECAY_START_TIME: new Date('2021-05-13 17:46:31-0000'), // GMT+0 LOG4JS_CONFIG: 'log4js-config.json', // default log level on production should be info - LOG_LEVEL: process.env.LOG_LEVEL || 'info', + LOG_LEVEL: process.env.LOG_LEVEL ?? 'info', CONFIG_VERSION: { DEFAULT: 'DEFAULT', EXPECTED: 'v15.2023-02-07', @@ -25,67 +25,67 @@ const constants = { } const server = { - PORT: process.env.PORT || 4000, - JWT_SECRET: process.env.JWT_SECRET || 'secret123', - JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN || '10m', + PORT: process.env.PORT ?? 4000, + JWT_SECRET: process.env.JWT_SECRET ?? 'secret123', + JWT_EXPIRES_IN: process.env.JWT_EXPIRES_IN ?? '10m', GRAPHIQL: process.env.GRAPHIQL === 'true' || false, - GDT_API_URL: process.env.GDT_API_URL || 'https://gdt.gradido.net', + GDT_API_URL: process.env.GDT_API_URL ?? 'https://gdt.gradido.net', PRODUCTION: process.env.NODE_ENV === 'production' || false, } const database = { - DB_HOST: process.env.DB_HOST || 'localhost', + DB_HOST: process.env.DB_HOST ?? 'localhost', DB_PORT: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306, - DB_USER: process.env.DB_USER || 'root', - DB_PASSWORD: process.env.DB_PASSWORD || '', - DB_DATABASE: process.env.DB_DATABASE || 'gradido_community', - TYPEORM_LOGGING_RELATIVE_PATH: process.env.TYPEORM_LOGGING_RELATIVE_PATH || 'typeorm.backend.log', + DB_USER: process.env.DB_USER ?? 'root', + DB_PASSWORD: process.env.DB_PASSWORD ?? '', + DB_DATABASE: process.env.DB_DATABASE ?? 'gradido_community', + TYPEORM_LOGGING_RELATIVE_PATH: process.env.TYPEORM_LOGGING_RELATIVE_PATH ?? 'typeorm.backend.log', } const klicktipp = { KLICKTIPP: process.env.KLICKTIPP === 'true' || false, - KLICKTTIPP_API_URL: process.env.KLICKTIPP_API_URL || 'https://api.klicktipp.com', - KLICKTIPP_USER: process.env.KLICKTIPP_USER || 'gradido_test', - KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD || 'secret321', - KLICKTIPP_APIKEY_DE: process.env.KLICKTIPP_APIKEY_DE || 'SomeFakeKeyDE', - KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN || 'SomeFakeKeyEN', + KLICKTTIPP_API_URL: process.env.KLICKTIPP_API_URL ?? 'https://api.klicktipp.com', + KLICKTIPP_USER: process.env.KLICKTIPP_USER ?? 'gradido_test', + KLICKTIPP_PASSWORD: process.env.KLICKTIPP_PASSWORD ?? 'secret321', + KLICKTIPP_APIKEY_DE: process.env.KLICKTIPP_APIKEY_DE ?? 'SomeFakeKeyDE', + KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN ?? 'SomeFakeKeyEN', } const community = { - COMMUNITY_NAME: process.env.COMMUNITY_NAME || 'Gradido Entwicklung', - COMMUNITY_URL: process.env.COMMUNITY_URL || 'http://localhost/', - COMMUNITY_REGISTER_URL: process.env.COMMUNITY_REGISTER_URL || 'http://localhost/register', - COMMUNITY_REDEEM_URL: process.env.COMMUNITY_REDEEM_URL || 'http://localhost/redeem/{code}', + COMMUNITY_NAME: process.env.COMMUNITY_NAME ?? 'Gradido Entwicklung', + COMMUNITY_URL: process.env.COMMUNITY_URL ?? 'http://localhost/', + COMMUNITY_REGISTER_URL: process.env.COMMUNITY_REGISTER_URL ?? 'http://localhost/register', + COMMUNITY_REDEEM_URL: process.env.COMMUNITY_REDEEM_URL ?? 'http://localhost/redeem/{code}', COMMUNITY_REDEEM_CONTRIBUTION_URL: - process.env.COMMUNITY_REDEEM_CONTRIBUTION_URL || 'http://localhost/redeem/CL-{code}', + process.env.COMMUNITY_REDEEM_CONTRIBUTION_URL ?? 'http://localhost/redeem/CL-{code}', COMMUNITY_DESCRIPTION: - process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.', - COMMUNITY_SUPPORT_MAIL: process.env.COMMUNITY_SUPPORT_MAIL || 'support@supportmail.com', + process.env.COMMUNITY_DESCRIPTION ?? 'Die lokale Entwicklungsumgebung von Gradido.', + COMMUNITY_SUPPORT_MAIL: process.env.COMMUNITY_SUPPORT_MAIL ?? 'support@supportmail.com', } const loginServer = { - LOGIN_APP_SECRET: process.env.LOGIN_APP_SECRET || '21ffbbc616fe', - LOGIN_SERVER_KEY: process.env.LOGIN_SERVER_KEY || 'a51ef8ac7ef1abf162fb7a65261acd7a', + LOGIN_APP_SECRET: process.env.LOGIN_APP_SECRET ?? '21ffbbc616fe', + LOGIN_SERVER_KEY: process.env.LOGIN_SERVER_KEY ?? 'a51ef8ac7ef1abf162fb7a65261acd7a', } const email = { EMAIL: process.env.EMAIL === 'true' || false, EMAIL_TEST_MODUS: process.env.EMAIL_TEST_MODUS === 'true' || false, - EMAIL_TEST_RECEIVER: process.env.EMAIL_TEST_RECEIVER || 'stage1@gradido.net', - EMAIL_USERNAME: process.env.EMAIL_USERNAME || '', - EMAIL_SENDER: process.env.EMAIL_SENDER || 'info@gradido.net', - EMAIL_PASSWORD: process.env.EMAIL_PASSWORD || '', - EMAIL_SMTP_URL: process.env.EMAIL_SMTP_URL || 'mailserver', + EMAIL_TEST_RECEIVER: process.env.EMAIL_TEST_RECEIVER ?? 'stage1@gradido.net', + EMAIL_USERNAME: process.env.EMAIL_USERNAME ?? '', + EMAIL_SENDER: process.env.EMAIL_SENDER ?? 'info@gradido.net', + EMAIL_PASSWORD: process.env.EMAIL_PASSWORD ?? '', + EMAIL_SMTP_URL: process.env.EMAIL_SMTP_URL ?? 'mailserver', EMAIL_SMTP_PORT: Number(process.env.EMAIL_SMTP_PORT) || 1025, // eslint-disable-next-line no-unneeded-ternary EMAIL_TLS: process.env.EMAIL_TLS === 'false' ? false : true, EMAIL_LINK_VERIFICATION: - process.env.EMAIL_LINK_VERIFICATION || 'http://localhost/checkEmail/{optin}{code}', + process.env.EMAIL_LINK_VERIFICATION ?? 'http://localhost/checkEmail/{optin}{code}', EMAIL_LINK_SETPASSWORD: - process.env.EMAIL_LINK_SETPASSWORD || 'http://localhost/reset-password/{optin}', + process.env.EMAIL_LINK_SETPASSWORD ?? 'http://localhost/reset-password/{optin}', EMAIL_LINK_FORGOTPASSWORD: - process.env.EMAIL_LINK_FORGOTPASSWORD || 'http://localhost/forgot-password', - EMAIL_LINK_OVERVIEW: process.env.EMAIL_LINK_OVERVIEW || 'http://localhost/overview', + process.env.EMAIL_LINK_FORGOTPASSWORD ?? 'http://localhost/forgot-password', + EMAIL_LINK_OVERVIEW: process.env.EMAIL_LINK_OVERVIEW ?? 'http://localhost/overview', // time in minutes a optin code is valid EMAIL_CODE_VALID_TIME: process.env.EMAIL_CODE_VALID_TIME ? parseInt(process.env.EMAIL_CODE_VALID_TIME) || 1440 @@ -98,14 +98,14 @@ const email = { const webhook = { // Elopage - WEBHOOK_ELOPAGE_SECRET: process.env.WEBHOOK_ELOPAGE_SECRET || 'secret', + WEBHOOK_ELOPAGE_SECRET: process.env.WEBHOOK_ELOPAGE_SECRET ?? 'secret', } // This is needed by graphql-directive-auth process.env.APP_SECRET = server.JWT_SECRET // Check config version -constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION || constants.CONFIG_VERSION.DEFAULT +constants.CONFIG_VERSION.CURRENT = process.env.CONFIG_VERSION ?? constants.CONFIG_VERSION.DEFAULT if ( ![constants.CONFIG_VERSION.EXPECTED, constants.CONFIG_VERSION.DEFAULT].includes( constants.CONFIG_VERSION.CURRENT, diff --git a/backend/src/federation/client/GraphQLGetClient.ts b/backend/src/federation/client/GraphQLGetClient.ts index 2f5281532..e2d3e6ed3 100644 --- a/backend/src/federation/client/GraphQLGetClient.ts +++ b/backend/src/federation/client/GraphQLGetClient.ts @@ -1,7 +1,7 @@ import { GraphQLClient } from 'graphql-request' import { PatchedRequestInit } from 'graphql-request/dist/types' -type ClientInstance = { +interface ClientInstance { url: string // eslint-disable-next-line no-use-before-define client: GraphQLGetClient diff --git a/backend/src/federation/validateCommunities.ts b/backend/src/federation/validateCommunities.ts index b38f38ee9..073a8eded 100644 --- a/backend/src/federation/validateCommunities.ts +++ b/backend/src/federation/validateCommunities.ts @@ -54,7 +54,7 @@ export async function validateCommunities(): Promise { } else { logger.warn( `Federation: received not matching publicKey -> received: ${ - pubKey || 'null' + pubKey ?? 'null' }, expected: ${dbCom.publicKey.toString()} `, ) // DbCommunity.delete({ id: dbCom.id }) diff --git a/backend/src/graphql/directive/isAuthorized.ts b/backend/src/graphql/directive/isAuthorized.ts index b8595a2bd..8f4c6e22c 100644 --- a/backend/src/graphql/directive/isAuthorized.ts +++ b/backend/src/graphql/directive/isAuthorized.ts @@ -12,7 +12,7 @@ export const isAuthorized: AuthChecker = async ({ context }, rights) => context.role = ROLE_UNAUTHORIZED // unauthorized user // is rights an inalienable right? - if ((rights).reduce((acc, right) => acc && INALIENABLE_RIGHTS.includes(right), true)) + if ((rights as RIGHTS[]).reduce((acc, right) => acc && INALIENABLE_RIGHTS.includes(right), true)) return true // Do we have a token? @@ -43,7 +43,7 @@ export const isAuthorized: AuthChecker = async ({ context }, rights) => } // check for correct rights - const missingRights = (rights).filter((right) => !context.role?.hasRight(right)) + const missingRights = (rights as RIGHTS[]).filter((right) => !context.role?.hasRight(right)) if (missingRights.length !== 0) { throw new LogError('401 Unauthorized') } diff --git a/backend/src/graphql/model/Balance.ts b/backend/src/graphql/model/Balance.ts index 162ccc3c0..d992677b1 100644 --- a/backend/src/graphql/model/Balance.ts +++ b/backend/src/graphql/model/Balance.ts @@ -10,7 +10,7 @@ export class Balance { linkCount: number }) { this.balance = data.balance - this.balanceGDT = data.balanceGDT || null + this.balanceGDT = data.balanceGDT ?? null this.count = data.count this.linkCount = data.linkCount } diff --git a/backend/src/graphql/model/Transaction.ts b/backend/src/graphql/model/Transaction.ts index 3334dea84..bfc96089b 100644 --- a/backend/src/graphql/model/Transaction.ts +++ b/backend/src/graphql/model/Transaction.ts @@ -43,13 +43,12 @@ export class Transaction { this.memo = transaction.memo this.creationDate = transaction.creationDate this.linkedUser = linkedUser - this.linkedTransactionId = transaction.linkedTransactionId || null + this.linkedTransactionId = transaction.linkedTransactionId ?? null this.linkId = transaction.contribution ? transaction.contribution.contributionLinkId - : transaction.transactionLinkId || null + : transaction.transactionLinkId ?? null this.previousBalance = - (transaction.previousTransaction && - transaction.previousTransaction.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN)) || + transaction.previousTransaction?.balance.toDecimalPlaces(2, Decimal.ROUND_DOWN) ?? new Decimal(0) } diff --git a/backend/src/graphql/resolver/BalanceResolver.ts b/backend/src/graphql/resolver/BalanceResolver.ts index deedb9dff..c8fdacdcf 100644 --- a/backend/src/graphql/resolver/BalanceResolver.ts +++ b/backend/src/graphql/resolver/BalanceResolver.ts @@ -70,7 +70,10 @@ export class BalanceResolver { now, ) logger.info( - `calculatedDecay(balance=${lastTransaction.balance}, balanceDate=${lastTransaction.balanceDate})=${calculatedDecay}`, + 'calculatedDecay', + lastTransaction.balance, + lastTransaction.balanceDate, + calculatedDecay, ) // The final balance is reduced by the link amount withheld @@ -96,9 +99,7 @@ export class BalanceResolver { count, linkCount, }) - logger.info( - `new Balance(balance=${balance}, balanceGDT=${balanceGDT}, count=${count}, linkCount=${linkCount}) = ${newBalance}`, - ) + logger.info('new Balance', balance, balanceGDT, count, linkCount, newBalance) return newBalance } diff --git a/backend/src/graphql/resolver/ContributionResolver.test.ts b/backend/src/graphql/resolver/ContributionResolver.test.ts index 17c739fcb..d4c84b4f3 100644 --- a/backend/src/graphql/resolver/ContributionResolver.test.ts +++ b/backend/src/graphql/resolver/ContributionResolver.test.ts @@ -66,7 +66,7 @@ let testEnv: { query: ApolloServerTestClient['query'] con: Connection } -let creation: Contribution | void +let creation: Contribution | null let admin: User let pendingContribution: any let inProgressContribution: any @@ -2071,7 +2071,7 @@ describe('ContributionResolver', () => { mutate({ mutation: updateContribution, variables: { - contributionId: (adminContribution && adminContribution.id) || -1, + contributionId: adminContribution?.id ?? -1, amount: 100.0, memo: 'Test Test Test', creationDate: new Date().toString(), @@ -2565,8 +2565,8 @@ describe('ContributionResolver', () => { }) describe('confirm two creations one after the other quickly', () => { - let c1: Contribution | void - let c2: Contribution | void + let c1: Contribution | null + let c2: Contribution | null beforeAll(async () => { const now = new Date() diff --git a/backend/src/graphql/resolver/ContributionResolver.ts b/backend/src/graphql/resolver/ContributionResolver.ts index 1884fecc4..d2203dac3 100644 --- a/backend/src/graphql/resolver/ContributionResolver.ts +++ b/backend/src/graphql/resolver/ContributionResolver.ts @@ -269,7 +269,7 @@ export class ContributionResolver { withDeleted: true, relations: ['user'], }) - if (!emailContact || !emailContact.user) { + if (!emailContact?.user) { throw new LogError('Could not find user', email) } if (emailContact.deletedAt || emailContact.user.deletedAt) { diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts index 04df0dc86..9d39a80ae 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.test.ts @@ -817,8 +817,8 @@ describe('TransactionLinkResolver', () => { const bibisTransaktionLinks = transactionLinks.filter( (transactionLink) => transactionLink.email === 'bibi@bloxberg.de', ) - for (let i = 0; i < bibisTransaktionLinks.length; i++) { - await transactionLinkFactory(testEnv, bibisTransaktionLinks[i]) + for (const bibisTransaktionLink of bibisTransaktionLinks) { + await transactionLinkFactory(testEnv, bibisTransaktionLink) } // admin: only now log in diff --git a/backend/src/graphql/resolver/TransactionLinkResolver.ts b/backend/src/graphql/resolver/TransactionLinkResolver.ts index ab322a50b..ca638d0be 100644 --- a/backend/src/graphql/resolver/TransactionLinkResolver.ts +++ b/backend/src/graphql/resolver/TransactionLinkResolver.ts @@ -146,7 +146,7 @@ export class TransactionLinkResolver { const transactionLink = await DbTransactionLink.findOneOrFail({ code }, { withDeleted: true }) const user = await DbUser.findOneOrFail({ id: transactionLink.userId }) let redeemedBy: User | null = null - if (transactionLink && transactionLink.redeemedBy) { + if (transactionLink?.redeemedBy) { redeemedBy = new User(await DbUser.findOneOrFail({ id: transactionLink.redeemedBy })) } return new TransactionLink(transactionLink, new User(user), redeemedBy) diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index bda108638..80c8be070 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -48,9 +48,7 @@ export const executeTransaction = async ( // acquire lock const releaseLock = await TRANSACTIONS_LOCK.acquire() try { - logger.info( - `executeTransaction(amount=${amount}, memo=${memo}, sender=${sender}, recipient=${recipient})...`, - ) + logger.info('executeTransaction', amount, memo, sender, recipient) if (sender.id === recipient.id) { throw new LogError('Sender and Recipient are the same', sender.id) @@ -119,10 +117,10 @@ export const executeTransaction = async ( // Save linked transaction id for send transactionSend.linkedTransactionId = transactionReceive.id await queryRunner.manager.update(dbTransaction, { id: transactionSend.id }, transactionSend) - logger.debug(`send Transaction updated: ${transactionSend}`) + logger.debug('send Transaction updated', transactionSend) if (transactionLink) { - logger.info(`transactionLink: ${transactionLink}`) + logger.info('transactionLink', transactionLink) transactionLink.redeemedAt = receivedCallDate transactionLink.redeemedBy = recipient.id await queryRunner.manager.update( @@ -271,8 +269,8 @@ export class TransactionResolver { sumAmount.mul(-1), sumHoldAvailableAmount.mul(-1), sumHoldAvailableAmount.minus(sumAmount.toString()).mul(-1), - firstDate || now, - lastDate || now, + firstDate ?? now, + lastDate ?? now, self, (userTransactions.length && userTransactions[0].balance) || new Decimal(0), ), @@ -325,9 +323,7 @@ export class TransactionResolver { } await executeTransaction(amount, memo, senderUser, recipientUser) - logger.info( - `successful executeTransaction(amount=${amount}, memo=${memo}, senderUser=${senderUser}, recipientUser=${recipientUser})`, - ) + logger.info('successful executeTransaction', amount, memo, senderUser, recipientUser) return true } } diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 23b3c6aa4..e16de98b9 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -94,7 +94,7 @@ const newEmailContact = (email: string, userId: number): DbUserContact => { emailContact.emailChecked = false emailContact.emailOptInTypeId = OptInType.EMAIL_OPT_IN_REGISTER emailContact.emailVerificationCode = random(64) - logger.debug(`newEmailContact...successful: ${emailContact}`) + logger.debug('newEmailContact...successful', emailContact) return emailContact } @@ -225,7 +225,7 @@ export class UserResolver { email = email.trim().toLowerCase() if (await checkEmailExists(email)) { const foundUser = await findUserByEmail(email) - logger.info(`DbUser.findOne(email=${email}) = ${foundUser}`) + logger.info('DbUser.findOne', email, foundUser) if (foundUser) { // ATTENTION: this logger-message will be exactly expected during tests, next line @@ -275,7 +275,7 @@ export class UserResolver { dbUser.firstName = firstName dbUser.lastName = lastName dbUser.language = language - dbUser.publisherId = publisherId || 0 + dbUser.publisherId = publisherId ?? 0 dbUser.passwordEncryptionType = PasswordEncryptionType.NO_PASSWORD logger.debug('new dbUser', dbUser) if (redeemCode) { @@ -382,7 +382,7 @@ export class UserResolver { throw new LogError('Unable to save email verification code', user.emailContact) }) - logger.info(`optInCode for ${email}=${user.emailContact}`) + logger.info('optInCode for', email, user.emailContact) void sendResetPasswordEmail({ firstName: user.firstName, @@ -486,7 +486,7 @@ export class UserResolver { async queryOptIn(@Arg('optIn') optIn: string): Promise { logger.info(`queryOptIn(${optIn})...`) const userContact = await DbUserContact.findOneOrFail({ emailVerificationCode: optIn }) - logger.debug(`found optInCode=${userContact}`) + logger.debug('found optInCode', userContact) // Code is only valid for `CONFIG.EMAIL_CODE_VALID_TIME` minutes if (!isEmailVerificationCodeValid(userContact.updatedAt || userContact.createdAt)) { throw new LogError( @@ -586,7 +586,7 @@ export class UserResolver { logger.info(`hasElopage()...`) const userEntity = getUser(context) const elopageBuys = hasElopageBuys(userEntity.emailContact.email) - logger.debug(`has ElopageBuys = ${elopageBuys}`) + logger.debug('has ElopageBuys', elopageBuys) return elopageBuys } @@ -643,7 +643,7 @@ export class UserResolver { return 'user.' + fieldName }), searchText, - filters || null, + filters ?? null, currentPage, pageSize, ) @@ -709,14 +709,14 @@ export class UserResolver { // change isAdmin switch (user.isAdmin) { case null: - if (isAdmin === true) { + if (isAdmin) { user.isAdmin = new Date() } else { throw new LogError('User is already an usual user') } break default: - if (isAdmin === false) { + if (!isAdmin) { user.isAdmin = null } else { throw new LogError('User is already admin') diff --git a/backend/src/graphql/resolver/util/findContributions.ts b/backend/src/graphql/resolver/util/findContributions.ts index a08631e2c..28984d5b1 100644 --- a/backend/src/graphql/resolver/util/findContributions.ts +++ b/backend/src/graphql/resolver/util/findContributions.ts @@ -24,7 +24,7 @@ export const findContributions = async ( } return DbContribution.findAndCount({ where: { - ...(statusFilter && statusFilter.length && { contributionStatus: In(statusFilter) }), + ...(statusFilter?.length && { contributionStatus: In(statusFilter) }), ...(userId && { userId }), }, withDeleted, diff --git a/backend/src/graphql/resolver/util/transactionLinkList.ts b/backend/src/graphql/resolver/util/transactionLinkList.ts index 0dba5a400..ee79216c8 100644 --- a/backend/src/graphql/resolver/util/transactionLinkList.ts +++ b/backend/src/graphql/resolver/util/transactionLinkList.ts @@ -14,7 +14,7 @@ export async function transactionLinkList( filters: TransactionLinkFilters | null, user: DbUser, ): Promise { - const { withDeleted, withExpired, withRedeemed } = filters || { + const { withDeleted, withExpired, withRedeemed } = filters ?? { withDeleted: false, withExpired: false, withRedeemed: false, diff --git a/backend/src/index.ts b/backend/src/index.ts index 86f78326d..6e0191155 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -13,7 +13,7 @@ async function main() { console.log(`GraphIQL available at http://localhost:${CONFIG.PORT}`) } }) - void startValidateCommunities(Number(CONFIG.FEDERATION_VALIDATE_COMMUNITY_TIMER)) + startValidateCommunities(Number(CONFIG.FEDERATION_VALIDATE_COMMUNITY_TIMER)) } main().catch((e) => { diff --git a/backend/src/seeds/index.ts b/backend/src/seeds/index.ts index c2533765e..fab81eb95 100644 --- a/backend/src/seeds/index.ts +++ b/backend/src/seeds/index.ts @@ -31,8 +31,8 @@ const context = { export const cleanDB = async () => { // this only works as long we do not have foreign key constraints - for (let i = 0; i < entities.length; i++) { - await resetEntity(entities[i]) + for (const entity of entities) { + await resetEntity(entity) } } @@ -73,20 +73,20 @@ const run = async () => { logger.info('##seed## seeding all random users successful...') // create GDD - for (let i = 0; i < creations.length; i++) { - await creationFactory(seedClient, creations[i]) + for (const creation of creations) { + await creationFactory(seedClient, creation) } logger.info('##seed## seeding all creations successful...') // create Transaction Links - for (let i = 0; i < transactionLinks.length; i++) { - await transactionLinkFactory(seedClient, transactionLinks[i]) + for (const transactionLink of transactionLinks) { + await transactionLinkFactory(seedClient, transactionLink) } logger.info('##seed## seeding all transactionLinks successful...') // create Contribution Links - for (let i = 0; i < contributionLinks.length; i++) { - await contributionLinkFactory(seedClient, contributionLinks[i]) + for (const contributionLink of contributionLinks) { + await contributionLinkFactory(seedClient, contributionLink) } logger.info('##seed## seeding all contributionLinks successful...') diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts index 777d6dfbe..d813c541e 100644 --- a/backend/src/server/createServer.ts +++ b/backend/src/server/createServer.ts @@ -21,7 +21,11 @@ import { plugins } from './plugins' // TODO implement // import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; -type ServerDef = { apollo: ApolloServer; app: Express; con: Connection } +interface ServerDef { + apollo: ApolloServer + app: Express + con: Connection +} export const createServer = async ( // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -34,7 +38,7 @@ export const createServer = async ( // open mysql connection const con = await connection() - if (!con || !con.isConnected) { + if (!con?.isConnected) { logger.fatal(`Couldn't open connection to database!`) throw new Error(`Fatal: Couldn't open connection to database`) } diff --git a/backend/src/server/plugins.ts b/backend/src/server/plugins.ts index 1da062b83..3e0fc50e1 100644 --- a/backend/src/server/plugins.ts +++ b/backend/src/server/plugins.ts @@ -12,7 +12,7 @@ const setHeadersPlugin = { return { willSendResponse(requestContext: any) { const { setHeaders = [] } = requestContext.context - setHeaders.forEach(({ key, value }: { [key: string]: string }) => { + setHeaders.forEach(({ key, value }: Record) => { if (requestContext.response.http.headers.get(key)) { requestContext.response.http.headers.set(key, value) } else { @@ -27,8 +27,8 @@ const setHeadersPlugin = { const filterVariables = (variables: any) => { const vars = clonedeep(variables) - if (vars && vars.password) vars.password = '***' - if (vars && vars.passwordNew) vars.passwordNew = '***' + if (vars?.password) vars.password = '***' + if (vars?.passwordNew) vars.passwordNew = '***' return vars } diff --git a/backend/src/typeorm/DBVersion.ts b/backend/src/typeorm/DBVersion.ts index c4c8d6c78..f465069d3 100644 --- a/backend/src/typeorm/DBVersion.ts +++ b/backend/src/typeorm/DBVersion.ts @@ -14,10 +14,10 @@ const getDBVersion = async (): Promise => { const checkDBVersion = async (DB_VERSION: string): Promise => { const dbVersion = await getDBVersion() - if (!dbVersion || dbVersion.indexOf(DB_VERSION) === -1) { + if (!dbVersion?.includes(DB_VERSION)) { logger.error( `Wrong database version detected - the backend requires '${DB_VERSION}' but found '${ - dbVersion || 'None' + dbVersion ?? 'None' }`, ) return false diff --git a/backend/src/util/klicktipp.ts b/backend/src/util/klicktipp.ts index e34a9c384..a0ba3c0f7 100644 --- a/backend/src/util/klicktipp.ts +++ b/backend/src/util/klicktipp.ts @@ -11,8 +11,7 @@ export async function retrieveNotRegisteredEmails(): Promise { } const users = await User.find({ relations: ['emailContact'] }) const notRegisteredUser = [] - for (let i = 0; i < users.length; i++) { - const user = users[i] + for (const user of users) { try { await getKlickTippUser(user.emailContact.email) } catch (err) { diff --git a/backend/src/util/utilities.ts b/backend/src/util/utilities.ts index 2cf53f1e4..e9935bbd4 100644 --- a/backend/src/util/utilities.ts +++ b/backend/src/util/utilities.ts @@ -1,7 +1,7 @@ import { Decimal } from 'decimal.js-light' import i18n from 'i18n' -export const objectValuesToArray = (obj: { [x: string]: string }): Array => { +export const objectValuesToArray = (obj: Record): string[] => { return Object.keys(obj).map(function (key) { return obj[key] }) diff --git a/backend/src/webhook/elopage.ts b/backend/src/webhook/elopage.ts index f386b6e99..7a779fadd 100644 --- a/backend/src/webhook/elopage.ts +++ b/backend/src/webhook/elopage.ts @@ -146,7 +146,7 @@ export const elopageWebhook = async (req: any, res: any): Promise => { email, firstName, lastName, - publisherId: loginElopageBuy.publisherId || 0, // This seemed to be the default value if not set + publisherId: loginElopageBuy.publisherId ?? 0, // This seemed to be the default value if not set }) } catch (error) { // eslint-disable-next-line no-console diff --git a/backend/test/helpers.ts b/backend/test/helpers.ts index d42db959f..7f55b3c70 100644 --- a/backend/test/helpers.ts +++ b/backend/test/helpers.ts @@ -22,8 +22,8 @@ const context = { export const cleanDB = async () => { // this only works as lond we do not have foreign key constraints - for (let i = 0; i < entities.length; i++) { - await resetEntity(entities[i]) + for (const entity of entities) { + await resetEntity(entity) } }