mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-12 23:35:50 +00:00
fix problems
This commit is contained in:
parent
8b697bac5c
commit
49976b30b7
@ -8,7 +8,7 @@ import { CustomJwtPayload } from './CustomJwtPayload'
|
||||
export const decode = (token: string): CustomJwtPayload | null => {
|
||||
if (!token) throw new LogError('401 Unauthorized')
|
||||
try {
|
||||
return <CustomJwtPayload>verify(token, CONFIG.JWT_SECRET)
|
||||
return verify(token, CONFIG.JWT_SECRET) as CustomJwtPayload
|
||||
} catch (err) {
|
||||
return null
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -54,7 +54,7 @@ export async function validateCommunities(): Promise<void> {
|
||||
} else {
|
||||
logger.warn(
|
||||
`Federation: received not matching publicKey -> received: ${
|
||||
pubKey || 'null'
|
||||
pubKey ?? 'null'
|
||||
}, expected: ${dbCom.publicKey.toString()} `,
|
||||
)
|
||||
// DbCommunity.delete({ id: dbCom.id })
|
||||
|
||||
@ -12,7 +12,7 @@ export const isAuthorized: AuthChecker<Context> = async ({ context }, rights) =>
|
||||
context.role = ROLE_UNAUTHORIZED // unauthorized user
|
||||
|
||||
// is rights an inalienable right?
|
||||
if ((<RIGHTS[]>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<Context> = async ({ context }, rights) =>
|
||||
}
|
||||
|
||||
// check for correct rights
|
||||
const missingRights = (<RIGHTS[]>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')
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<boolean> {
|
||||
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')
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -14,7 +14,7 @@ export async function transactionLinkList(
|
||||
filters: TransactionLinkFilters | null,
|
||||
user: DbUser,
|
||||
): Promise<TransactionLinkResult> {
|
||||
const { withDeleted, withExpired, withRedeemed } = filters || {
|
||||
const { withDeleted, withExpired, withRedeemed } = filters ?? {
|
||||
withDeleted: false,
|
||||
withExpired: false,
|
||||
withRedeemed: false,
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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...')
|
||||
|
||||
|
||||
@ -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`)
|
||||
}
|
||||
|
||||
@ -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<string, string>) => {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@ -14,10 +14,10 @@ const getDBVersion = async (): Promise<string | null> => {
|
||||
|
||||
const checkDBVersion = async (DB_VERSION: string): Promise<boolean> => {
|
||||
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
|
||||
|
||||
@ -11,8 +11,7 @@ export async function retrieveNotRegisteredEmails(): Promise<string[]> {
|
||||
}
|
||||
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) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Decimal } from 'decimal.js-light'
|
||||
import i18n from 'i18n'
|
||||
|
||||
export const objectValuesToArray = (obj: { [x: string]: string }): Array<string> => {
|
||||
export const objectValuesToArray = (obj: Record<string, string>): string[] => {
|
||||
return Object.keys(obj).map(function (key) {
|
||||
return obj[key]
|
||||
})
|
||||
|
||||
@ -146,7 +146,7 @@ export const elopageWebhook = async (req: any, res: any): Promise<void> => {
|
||||
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
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user