Merge branch 'master' into 2803-open-contribution-edit-button

This commit is contained in:
Moriz Wahl 2023-03-30 15:11:18 +02:00
commit 10022c2247
119 changed files with 1438 additions and 571 deletions

View File

@ -1,12 +1,27 @@
// eslint-disable-next-line import/no-commonjs, import/unambiguous
module.exports = {
root: true,
env: {
node: true,
},
parser: '@typescript-eslint/parser',
plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest'],
extends: ['standard', 'eslint:recommended', 'plugin:prettier/recommended'],
// add your custom rules here
plugins: ['prettier', '@typescript-eslint', 'type-graphql', 'jest', 'import'],
extends: [
'standard',
'eslint:recommended',
'plugin:prettier/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
],
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
typescript: true,
node: true,
},
},
rules: {
'no-console': ['error'],
'no-debugger': 'error',
@ -22,6 +37,47 @@ module.exports = {
'jest/no-identical-title': 'error',
'jest/prefer-to-have-length': 'error',
'jest/valid-expect': 'error',
// import
'import/export': 'error',
'import/no-deprecated': 'error',
'import/no-empty-named-blocks': 'error',
'import/no-extraneous-dependencies': 'error',
'import/no-mutable-exports': 'error',
'import/no-unused-modules': 'error',
'import/no-named-as-default': 'error',
'import/no-named-as-default-member': 'error',
'import/no-amd': 'error',
'import/no-commonjs': 'error',
'import/no-import-module-exports': 'error',
'import/no-nodejs-modules': 'off',
'import/unambiguous': 'error',
'import/default': 'error',
'import/named': 'error',
'import/namespace': 'error',
'import/no-absolute-path': 'error',
'import/no-cycle': 'off',
'import/no-dynamic-require': 'error',
'import/no-internal-modules': 'off',
'import/no-relative-packages': 'error',
'import/no-relative-parent-imports': ['error', { ignore: ['@/*'] }],
'import/no-self-import': 'error',
'import/no-unresolved': 'error',
'import/no-useless-path-segments': 'error',
'import/no-webpack-loader-syntax': 'error',
'import/consistent-type-specifier-style': 'error',
'import/exports-last': 'off',
'import/extensions': 'error',
'import/first': 'error',
'import/group-exports': 'off',
'import/newline-after-import': 'error',
'import/no-anonymous-default-export': 'error',
'import/no-default-export': 'off',
'import/no-duplicates': 'error',
'import/no-named-default': 'error',
'import/no-namespace': 'error',
'import/no-unassigned-import': 'error',
'import/order': 'error',
'import/prefer-default-export': 'off', // TODO
},
overrides: [
// only for ts files
@ -38,9 +94,11 @@ module.exports = {
'no-void': ['error', { allowAsStatement: true }],
// ignore prefer-regexp-exec rule to allow string.match(regex)
'@typescript-eslint/prefer-regexp-exec': 'off',
// this should not run on ts files: https://github.com/import-js/eslint-plugin-import/issues/2215#issuecomment-911245486
'import/unambiguous': 'off',
},
parserOptions: {
tsconfigRootDir: __dirname,
tsconfigRootDir: './',
project: ['./tsconfig.json'],
// this is to properly reference the referenced project database without requirement of compiling it
EXPERIMENTAL_useSourceOfProjectReferenceRedirect: true,

View File

@ -1,4 +1,5 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
// eslint-disable-next-line import/no-commonjs, import/unambiguous
module.exports = {
verbose: true,
preset: 'ts-jest',

View File

@ -12,7 +12,7 @@
"clean": "tsc --build --clean",
"start": "cross-env TZ=UTC TS_NODE_BASEURL=./build node -r tsconfig-paths/register build/src/index.js",
"dev": "cross-env TZ=UTC nodemon -w src --ext ts --exec ts-node -r tsconfig-paths/register src/index.ts",
"lint": "eslint --max-warnings=0 --ext .js,.ts .",
"lint": "eslint --max-warnings=0 .",
"test": "cross-env TZ=UTC NODE_ENV=development jest --runInBand --forceExit --detectOpenHandles",
"seed": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/seeds/index.ts",
"klicktipp": "cross-env TZ=UTC NODE_ENV=development ts-node -r tsconfig-paths/register src/util/klicktipp.ts",
@ -29,6 +29,7 @@
"dotenv": "^10.0.0",
"email-templates": "^10.0.1",
"express": "^4.17.1",
"gradido-database": "file:../database",
"graphql": "^15.5.1",
"graphql-request": "5.0.0",
"i18n": "^0.15.1",
@ -61,13 +62,15 @@
"eslint": "^7.29.0",
"eslint-config-prettier": "^8.3.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-import-resolver-typescript": "^3.5.3",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-type-graphql": "^1.0.0",
"faker": "^5.5.3",
"graphql-tag": "^2.12.6",
"jest": "^27.2.4",
"klicktipp-api": "^1.0.2",
"nodemon": "^2.0.7",

View File

@ -4,6 +4,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
// eslint-disable-next-line import/no-relative-parent-imports
import KlicktippConnector from 'klicktipp-api'
import CONFIG from '@/config'

View File

@ -1,19 +1,19 @@
import jwt from 'jsonwebtoken'
import CONFIG from '@/config/'
import { verify, sign } from 'jsonwebtoken'
import { CustomJwtPayload } from './CustomJwtPayload'
import CONFIG from '@/config/'
import LogError from '@/server/LogError'
export const decode = (token: string): CustomJwtPayload | null => {
if (!token) throw new LogError('401 Unauthorized')
try {
return <CustomJwtPayload>jwt.verify(token, CONFIG.JWT_SECRET)
return <CustomJwtPayload>verify(token, CONFIG.JWT_SECRET)
} catch (err) {
return null
}
}
export const encode = (gradidoID: string): string => {
const token = jwt.sign({ gradidoID }, CONFIG.JWT_SECRET, {
const token = sign({ gradidoID }, CONFIG.JWT_SECRET, {
expiresIn: CONFIG.JWT_EXPIRES_IN,
})
return token

View File

@ -1,7 +1,8 @@
// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env)
import dotenv from 'dotenv'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
dotenv.config()
Decimal.set({
@ -10,7 +11,7 @@ Decimal.set({
})
const constants = {
DB_VERSION: '0063-event_link_fields',
DB_VERSION: '0064-event_rename',
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

View File

@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/unbound-method */
import { createTransport } from 'nodemailer'
import { sendEmailTranslated } from './sendEmailTranslated'
import { logger, i18n } from '@test/testSetup'
import CONFIG from '@/config'
import { sendEmailTranslated } from './sendEmailTranslated'
CONFIG.EMAIL = false
CONFIG.EMAIL_SMTP_URL = 'EMAIL_SMTP_URL'

View File

@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import CONFIG from '@/config'
import { backendLogger as logger } from '@/server/logger'
import path from 'path'
import { createTransport } from 'nodemailer'
import Email from 'email-templates'
import i18n from 'i18n'
import { backendLogger as logger } from '@/server/logger'
import CONFIG from '@/config'
import LogError from '@/server/LogError'
export const sendEmailTranslated = async (params: {

View File

@ -3,10 +3,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import Decimal from 'decimal.js-light'
import { testEnvironment } from '@test/helpers'
import { logger, i18n as localization } from '@test/testSetup'
import CONFIG from '@/config'
import { Decimal } from 'decimal.js-light'
import {
sendAddedContributionMessageEmail,
sendAccountActivationEmail,
@ -19,6 +16,9 @@ import {
sendTransactionReceivedEmail,
} from './sendEmailVariants'
import { sendEmailTranslated } from './sendEmailTranslated'
import { testEnvironment } from '@test/helpers'
import { logger, i18n as localization } from '@test/testSetup'
import CONFIG from '@/config'
let con: any
let testEnv: any

View File

@ -1,7 +1,7 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { sendEmailTranslated } from './sendEmailTranslated'
import CONFIG from '@/config'
import { decimalSeparatorByLanguage } from '@/util/utilities'
import { sendEmailTranslated } from './sendEmailTranslated'
export const sendAddedContributionMessageEmail = (data: {
firstName: string

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_ADMIN_USER_DELETE = async (user: DbUser, moderator: DbUser): Promise<DbEvent> =>
Event(EventType.ADMIN_USER_DELETE, user, moderator).save()

View File

@ -2,7 +2,7 @@ import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_ADMIN_SEND_CONFIRMATION_EMAIL = async (
export const EVENT_ADMIN_USER_ROLE_SET = async (
user: DbUser,
moderator: DbUser,
): Promise<DbEvent> => Event(EventType.ADMIN_SEND_CONFIRMATION_EMAIL, user, moderator).save()
): Promise<DbEvent> => Event(EventType.ADMIN_USER_ROLE_SET, user, moderator).save()

View File

@ -0,0 +1,8 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_ADMIN_USER_UNDELETE = async (
user: DbUser,
moderator: DbUser,
): Promise<DbEvent> => Event(EventType.ADMIN_USER_UNDELETE, user, moderator).save()

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { Contribution as DbContribution } from '@entity/Contribution'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Contribution as DbContribution } from '@entity/Contribution'
import { Event as DbEvent } from '@entity/Event'

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_EMAIL_ACCOUNT_MULTIREGISTRATION = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.EMAIL_ACCOUNT_MULTIREGISTRATION, user, { id: 0 } as DbUser).save()

View File

@ -0,0 +1,8 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_EMAIL_ADMIN_CONFIRMATION = async (
user: DbUser,
moderator: DbUser,
): Promise<DbEvent> => Event(EventType.EMAIL_ADMIN_CONFIRMATION, user, moderator).save()

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_EMAIL_CONFIRMATION = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.EMAIL_CONFIRMATION, user, user).save()

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_EMAIL_FORGOT_PASSWORD = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.EMAIL_FORGOT_PASSWORD, user, { id: 0 } as DbUser).save()

View File

@ -1,6 +0,0 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL, user, { id: 0 } as DbUser).save()

View File

@ -1,6 +0,0 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_SEND_CONFIRMATION_EMAIL = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.SEND_CONFIRMATION_EMAIL, user, user).save()

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { Event as DbEvent } from '@entity/Event'

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User as DbUser } from '@entity/User'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { Event as DbEvent } from '@entity/Event'

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_USER_ACTIVATE_ACCOUNT = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.USER_ACTIVATE_ACCOUNT, user, user).save()

View File

@ -2,5 +2,5 @@ import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_ACTIVATE_ACCOUNT = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.ACTIVATE_ACCOUNT, user, user).save()
export const EVENT_USER_INFO_UPDATE = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.USER_INFO_UPDATE, user, user).save()

View File

@ -2,5 +2,5 @@ import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_LOGIN = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.LOGIN, user, user).save()
export const EVENT_USER_LOGIN = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.USER_LOGIN, user, user).save()

View File

@ -2,5 +2,5 @@ import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_REGISTER = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.REGISTER, user, user).save()
export const EVENT_USER_LOGOUT = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.USER_LOGOUT, user, user).save()

View File

@ -0,0 +1,6 @@
import { User as DbUser } from '@entity/User'
import { Event as DbEvent } from '@entity/Event'
import { Event, EventType } from './Event'
export const EVENT_USER_REGISTER = async (user: DbUser): Promise<DbEvent> =>
Event(EventType.USER_REGISTER, user, user).save()

View File

@ -5,8 +5,8 @@ import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
import { Contribution as DbContribution } from '@entity/Contribution'
import { ContributionMessage as DbContributionMessage } from '@entity/ContributionMessage'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import Decimal from 'decimal.js-light'
import { EventType } from './Event'
import { Decimal } from 'decimal.js-light'
import { EventType } from './EventType'
export const Event = (
type: EventType,
@ -34,9 +34,8 @@ export const Event = (
return event
}
export { EventType } from './EventType'
export { EventType }
export { EVENT_ACTIVATE_ACCOUNT } from './EVENT_ACTIVATE_ACCOUNT'
export { EVENT_ADMIN_CONTRIBUTION_CONFIRM } from './EVENT_ADMIN_CONTRIBUTION_CONFIRM'
export { EVENT_ADMIN_CONTRIBUTION_CREATE } from './EVENT_ADMIN_CONTRIBUTION_CREATE'
export { EVENT_ADMIN_CONTRIBUTION_DELETE } from './EVENT_ADMIN_CONTRIBUTION_DELETE'
@ -46,18 +45,25 @@ export { EVENT_ADMIN_CONTRIBUTION_LINK_CREATE } from './EVENT_ADMIN_CONTRIBUTION
export { EVENT_ADMIN_CONTRIBUTION_LINK_DELETE } from './EVENT_ADMIN_CONTRIBUTION_LINK_DELETE'
export { EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE } from './EVENT_ADMIN_CONTRIBUTION_LINK_UPDATE'
export { EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE } from './EVENT_ADMIN_CONTRIBUTION_MESSAGE_CREATE'
export { EVENT_ADMIN_SEND_CONFIRMATION_EMAIL } from './EVENT_ADMIN_SEND_CONFIRMATION_EMAIL'
export { EVENT_ADMIN_USER_DELETE } from './EVENT_ADMIN_USER_DELETE'
export { EVENT_ADMIN_USER_UNDELETE } from './EVENT_ADMIN_USER_UNDELETE'
export { EVENT_ADMIN_USER_ROLE_SET } from './EVENT_ADMIN_USER_ROLE_SET'
export { EVENT_CONTRIBUTION_CREATE } from './EVENT_CONTRIBUTION_CREATE'
export { EVENT_CONTRIBUTION_DELETE } from './EVENT_CONTRIBUTION_DELETE'
export { EVENT_CONTRIBUTION_UPDATE } from './EVENT_CONTRIBUTION_UPDATE'
export { EVENT_CONTRIBUTION_MESSAGE_CREATE } from './EVENT_CONTRIBUTION_MESSAGE_CREATE'
export { EVENT_CONTRIBUTION_LINK_REDEEM } from './EVENT_CONTRIBUTION_LINK_REDEEM'
export { EVENT_LOGIN } from './EVENT_LOGIN'
export { EVENT_REGISTER } from './EVENT_REGISTER'
export { EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL } from './EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL'
export { EVENT_SEND_CONFIRMATION_EMAIL } from './EVENT_SEND_CONFIRMATION_EMAIL'
export { EVENT_EMAIL_ACCOUNT_MULTIREGISTRATION } from './EVENT_EMAIL_ACCOUNT_MULTIREGISTRATION'
export { EVENT_EMAIL_ADMIN_CONFIRMATION } from './EVENT_EMAIL_ADMIN_CONFIRMATION'
export { EVENT_EMAIL_CONFIRMATION } from './EVENT_EMAIL_CONFIRMATION'
export { EVENT_EMAIL_FORGOT_PASSWORD } from './EVENT_EMAIL_FORGOT_PASSWORD'
export { EVENT_TRANSACTION_SEND } from './EVENT_TRANSACTION_SEND'
export { EVENT_TRANSACTION_RECEIVE } from './EVENT_TRANSACTION_RECEIVE'
export { EVENT_TRANSACTION_LINK_CREATE } from './EVENT_TRANSACTION_LINK_CREATE'
export { EVENT_TRANSACTION_LINK_DELETE } from './EVENT_TRANSACTION_LINK_DELETE'
export { EVENT_TRANSACTION_LINK_REDEEM } from './EVENT_TRANSACTION_LINK_REDEEM'
export { EVENT_USER_ACTIVATE_ACCOUNT } from './EVENT_USER_ACTIVATE_ACCOUNT'
export { EVENT_USER_INFO_UPDATE } from './EVENT_USER_INFO_UPDATE'
export { EVENT_USER_LOGIN } from './EVENT_USER_LOGIN'
export { EVENT_USER_LOGOUT } from './EVENT_USER_LOGOUT'
export { EVENT_USER_REGISTER } from './EVENT_USER_REGISTER'

View File

@ -1,5 +1,4 @@
export enum EventType {
ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT',
// TODO CONTRIBUTION_CONFIRM = 'CONTRIBUTION_CONFIRM',
ADMIN_CONTRIBUTION_CONFIRM = 'ADMIN_CONTRIBUTION_CONFIRM',
ADMIN_CONTRIBUTION_CREATE = 'ADMIN_CONTRIBUTION_CREATE',
@ -10,28 +9,34 @@ export enum EventType {
ADMIN_CONTRIBUTION_LINK_DELETE = 'ADMIN_CONTRIBUTION_LINK_DELETE',
ADMIN_CONTRIBUTION_LINK_UPDATE = 'ADMIN_CONTRIBUTION_LINK_UPDATE',
ADMIN_CONTRIBUTION_MESSAGE_CREATE = 'ADMIN_CONTRIBUTION_MESSAGE_CREATE',
ADMIN_SEND_CONFIRMATION_EMAIL = 'ADMIN_SEND_CONFIRMATION_EMAIL',
ADMIN_USER_DELETE = 'ADMIN_USER_DELETE',
ADMIN_USER_UNDELETE = 'ADMIN_USER_UNDELETE',
ADMIN_USER_ROLE_SET = 'ADMIN_USER_ROLE_SET',
CONTRIBUTION_CREATE = 'CONTRIBUTION_CREATE',
CONTRIBUTION_DELETE = 'CONTRIBUTION_DELETE',
CONTRIBUTION_UPDATE = 'CONTRIBUTION_UPDATE',
CONTRIBUTION_MESSAGE_CREATE = 'CONTRIBUTION_MESSAGE_CREATE',
CONTRIBUTION_LINK_REDEEM = 'CONTRIBUTION_LINK_REDEEM',
LOGIN = 'LOGIN',
REGISTER = 'REGISTER',
REDEEM_REGISTER = 'REDEEM_REGISTER',
SEND_ACCOUNT_MULTIREGISTRATION_EMAIL = 'SEND_ACCOUNT_MULTIREGISTRATION_EMAIL',
SEND_CONFIRMATION_EMAIL = 'SEND_CONFIRMATION_EMAIL',
EMAIL_ACCOUNT_MULTIREGISTRATION = 'EMAIL_ACCOUNT_MULTIREGISTRATION',
EMAIL_ADMIN_CONFIRMATION = 'EMAIL_ADMIN_CONFIRMATION',
EMAIL_CONFIRMATION = 'EMAIL_CONFIRMATION',
EMAIL_FORGOT_PASSWORD = 'EMAIL_FORGOT_PASSWORD',
TRANSACTION_SEND = 'TRANSACTION_SEND',
TRANSACTION_RECEIVE = 'TRANSACTION_RECEIVE',
TRANSACTION_LINK_CREATE = 'TRANSACTION_LINK_CREATE',
TRANSACTION_LINK_DELETE = 'TRANSACTION_LINK_DELETE',
TRANSACTION_LINK_REDEEM = 'TRANSACTION_LINK_REDEEM',
USER_ACTIVATE_ACCOUNT = 'ACTIVATE_ACCOUNT',
USER_INFO_UPDATE = 'USER_INFO_UPDATE',
USER_LOGIN = 'USER_LOGIN',
USER_LOGOUT = 'USER_LOGOUT',
USER_REGISTER = 'USER_REGISTER',
USER_REGISTER_REDEEM = 'USER_REGISTER_REDEEM',
// VISIT_GRADIDO = 'VISIT_GRADIDO',
// VERIFY_REDEEM = 'VERIFY_REDEEM',
// INACTIVE_ACCOUNT = 'INACTIVE_ACCOUNT',
// CONFIRM_EMAIL = 'CONFIRM_EMAIL',
// REGISTER_EMAIL_KLICKTIPP = 'REGISTER_EMAIL_KLICKTIPP',
// LOGOUT = 'LOGOUT',
// REDEEM_LOGIN = 'REDEEM_LOGIN',
// SEND_FORGOT_PASSWORD_EMAIL = 'SEND_FORGOT_PASSWORD_EMAIL',
// PASSWORD_CHANGE = 'PASSWORD_CHANGE',

View File

@ -2,9 +2,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { gql } from 'graphql-request'
import { backendLogger as logger } from '@/server/logger'
import { Community as DbCommunity } from '@entity/Community'
import { GraphQLGetClient } from '../GraphQLGetClient'
import { GraphQLGetClient } from '@/federation/client/GraphQLGetClient'
import { backendLogger as logger } from '@/server/logger'
import LogError from '@/server/LogError'
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {

View File

@ -2,9 +2,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import { gql } from 'graphql-request'
import { backendLogger as logger } from '@/server/logger'
import { Community as DbCommunity } from '@entity/Community'
import { GraphQLGetClient } from '../GraphQLGetClient'
import { GraphQLGetClient } from '@/federation/client/GraphQLGetClient'
import { backendLogger as logger } from '@/server/logger'
import LogError from '@/server/LogError'
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {

View File

@ -5,10 +5,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { logger } from '@test/testSetup'
import { Community as DbCommunity } from '@entity/Community'
import { testEnvironment, cleanDB } from '@test/helpers'
import { validateCommunities } from './validateCommunities'
import { logger } from '@test/testSetup'
import { testEnvironment, cleanDB } from '@test/helpers'
let con: any
let testEnv: any

View File

@ -4,8 +4,8 @@ import { IsNull } from '@dbTools/typeorm'
import { requestGetPublicKey as v1_0_requestGetPublicKey } from './client/1_0/FederationClient'
// eslint-disable-next-line camelcase
import { requestGetPublicKey as v1_1_requestGetPublicKey } from './client/1_1/FederationClient'
import { backendLogger as logger } from '@/server/logger'
import { ApiVersionType } from './enum/apiVersionType'
import { backendLogger as logger } from '@/server/logger'
import LogError from '@/server/LogError'
export function startValidateCommunities(timerInterval: number): void {

View File

@ -1,5 +1,5 @@
import { ArgsType, Field, InputType } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@InputType()
@ArgsType()

View File

@ -1,5 +1,5 @@
import { ArgsType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ArgsType()
export default class AdminUpdateContributionArgs {

View File

@ -1,5 +1,5 @@
import { ArgsType, Field, InputType } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@InputType()
@ArgsType()

View File

@ -1,5 +1,5 @@
import { ArgsType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ArgsType()
export default class ContributionLinkArgs {

View File

@ -1,5 +1,5 @@
import { ArgsType, Field } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ArgsType()
export default class TransactionLinkArgs {

View File

@ -1,5 +1,5 @@
import { ArgsType, Field } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ArgsType()
export default class TransactionSendArgs {

View File

@ -4,11 +4,11 @@
import { AuthChecker } from 'type-graphql'
import { User } from '@entity/User'
import { decode, encode } from '@/auth/JWT'
import { ROLE_UNAUTHORIZED, ROLE_USER, ROLE_ADMIN } from '@/auth/ROLES'
import { RIGHTS } from '@/auth/RIGHTS'
import { INALIENABLE_RIGHTS } from '@/auth/INALIENABLE_RIGHTS'
import { User } from '@entity/User'
import LogError from '@/server/LogError'
const isAuthorized: AuthChecker<any> = async ({ context }, rights) => {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ObjectType()
export class AdminUpdateContribution {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int, Float } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ObjectType()
export class Balance {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ObjectType()
export class DynamicStatisticsFields {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Contribution as dbContribution } from '@entity/Contribution'
import { User } from '@entity/User'

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { ContributionLink as dbContributionLink } from '@entity/ContributionLink'
import CONFIG from '@/config'

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
interface DecayInterface {
balance: Decimal

View File

@ -3,8 +3,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { GdtEntry } from './GdtEntry'
import { ObjectType, Field, Int, Float } from 'type-graphql'
import { GdtEntry } from './GdtEntry'
@ObjectType()
export class GdtEntryList {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
@ObjectType()
export class OpenCreation {

View File

@ -1,9 +1,9 @@
import { ObjectType, Field, Int } from 'type-graphql'
import { Decay } from './Decay'
import { Transaction as dbTransaction } from '@entity/Transaction'
import Decimal from 'decimal.js-light'
import { TransactionTypeId } from '@enum/TransactionTypeId'
import { Decimal } from 'decimal.js-light'
import { Decay } from './Decay'
import { User } from './User'
import { TransactionTypeId } from '@enum/TransactionTypeId'
@ObjectType()
export class Transaction {

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
import { User } from './User'
import CONFIG from '@/config'

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Contribution } from '@entity/Contribution'
import { User } from '@entity/User'

View File

@ -1,6 +1,6 @@
import { ObjectType, Field, Int } from 'type-graphql'
import { KlickTipp } from './KlickTipp'
import { User as dbUser } from '@entity/User'
import { KlickTipp } from './KlickTipp'
import { UserContact } from './UserContact'
@ObjectType()

View File

@ -1,5 +1,5 @@
import { ObjectType, Field, Int } from 'type-graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { User } from '@entity/User'
@ObjectType()

View File

@ -1,11 +1,13 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Resolver, Query, Ctx, Authorized } from 'type-graphql'
import { getCustomRepository } from '@dbTools/typeorm'
import { Transaction as dbTransaction } from '@entity/Transaction'
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
import { GdtResolver } from './GdtResolver'
import { getLastTransaction } from './util/getLastTransaction'
import { TransactionLinkRepository } from '@repository/TransactionLink'
import { Balance } from '@model/Balance'
@ -14,9 +16,6 @@ import { backendLogger as logger } from '@/server/logger'
import { Context, getUser } from '@/server/context'
import { calculateDecay } from '@/util/decay'
import { RIGHTS } from '@/auth/RIGHTS'
import { GdtResolver } from './GdtResolver'
import { getLastTransaction } from './util/getLastTransaction'
@Resolver()
export class BalanceResolver {

View File

@ -5,8 +5,8 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { getCommunities } from '@/seeds/graphql/queries'
import { Community as DbCommunity } from '@entity/Community'
import { getCommunities } from '@/seeds/graphql/queries'
import { testEnvironment } from '@test/helpers'
let query: any

View File

@ -1,7 +1,7 @@
import { Resolver, Query, Authorized } from 'type-graphql'
import { Community } from '@model/Community'
import { Community as DbCommunity } from '@entity/Community'
import { Community } from '@model/Community'
import { RIGHTS } from '@/auth/RIGHTS'

View File

@ -4,9 +4,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-explicit-any */
import Decimal from 'decimal.js-light'
import { logger } from '@test/testSetup'
import { Decimal } from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Event as DbEvent } from '@entity/Event'
import { logger } from '@test/testSetup'
import {
login,
createContributionLink,
@ -18,9 +20,7 @@ import { cleanDB, testEnvironment, resetToken } from '@test/helpers'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { userFactory } from '@/seeds/factory/user'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { EventType } from '@/event/Event'
import { Event as DbEvent } from '@entity/Event'
let mutate: any, query: any, con: any
let testEnv: any

View File

@ -1,7 +1,8 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Resolver, Args, Arg, Authorized, Mutation, Query, Int, Ctx } from 'type-graphql'
import { MoreThan, IsNull } from '@dbTools/typeorm'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import {
CONTRIBUTIONLINK_NAME_MAX_CHARS,
CONTRIBUTIONLINK_NAME_MIN_CHARS,
@ -9,16 +10,15 @@ import {
MEMO_MIN_CHARS,
} from './const/const'
import { isStartEndDateValid } from './util/creations'
import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver'
import { ContributionLinkList } from '@model/ContributionLinkList'
import { ContributionLink } from '@model/ContributionLink'
import ContributionLinkArgs from '@arg/ContributionLinkArgs'
import { RIGHTS } from '@/auth/RIGHTS'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Order } from '@enum/Order'
import Paginated from '@arg/Paginated'
// TODO: this is a strange construct
import { transactionLinkCode as contributionLinkCode } from './TransactionLinkResolver'
import LogError from '@/server/LogError'
import { Context, getUser } from '@/server/context'
import {

View File

@ -6,9 +6,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { GraphQLError } from 'graphql'
import { Event as DbEvent } from '@entity/Event'
import { cleanDB, resetToken, testEnvironment } from '@test/helpers'
import { logger, i18n as localization } from '@test/testSetup'
import { GraphQLError } from 'graphql'
import {
adminCreateContributionMessage,
createContribution,
@ -21,7 +22,6 @@ import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { sendAddedContributionMessageEmail } from '@/emails/sendEmailVariants'
import { EventType } from '@/event/Event'
import { Event as DbEvent } from '@entity/Event'
jest.mock('@/emails/sendEmailVariants', () => {
const originalModule = jest.requireActual('@/emails/sendEmailVariants')

View File

@ -6,7 +6,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { Contribution } from '@entity/Contribution'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { User } from '@entity/User'
import { UserInputError } from 'apollo-server-express'
import { Event as DbEvent } from '@entity/Event'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { stephenHawking } from '@/seeds/users/stephen-hawking'
@ -41,18 +47,12 @@ import {
contributionDateFormatter,
resetEntity,
} from '@test/helpers'
import { GraphQLError } from 'graphql'
import { userFactory } from '@/seeds/factory/user'
import { creationFactory } from '@/seeds/factory/creation'
import { creations } from '@/seeds/creation/index'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { Event as DbEvent } from '@entity/Event'
import { Contribution } from '@entity/Contribution'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { User } from '@entity/User'
import { EventType } from '@/event/Event'
import { logger, i18n as localization } from '@test/testSetup'
import { UserInputError } from 'apollo-server-express'
import { raeuberHotzenplotz } from '@/seeds/users/raeuber-hotzenplotz'
import { UnconfirmedContribution } from '@model/UnconfirmedContribution'
import { ContributionListResult } from '@model/Contribution'
@ -2483,10 +2483,10 @@ describe('ContributionResolver', () => {
})
})
it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => {
it('stores the EMAIL_CONFIRMATION event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.SEND_CONFIRMATION_EMAIL,
type: EventType.EMAIL_CONFIRMATION,
}),
)
})

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Arg, Args, Authorized, Ctx, Int, Mutation, Query, Resolver } from 'type-graphql'
import { IsNull, getConnection } from '@dbTools/typeorm'
@ -9,6 +9,16 @@ import { UserContact } from '@entity/UserContact'
import { User as DbUser } from '@entity/User'
import { Transaction as DbTransaction } from '@entity/Transaction'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import { getLastTransaction } from './util/getLastTransaction'
import { findContributions } from './util/findContributions'
import {
getUserCreation,
validateContribution,
updateCreations,
isValidDateString,
getOpenCreations,
} from './util/creations'
import { AdminUpdateContribution } from '@model/AdminUpdateContribution'
import { Contribution, ContributionListResult } from '@model/Contribution'
import { Decay } from '@model/Decay'
@ -27,14 +37,6 @@ import AdminUpdateContributionArgs from '@arg/AdminUpdateContributionArgs'
import { RIGHTS } from '@/auth/RIGHTS'
import { Context, getUser, getClientTimezoneOffset } from '@/server/context'
import { backendLogger as logger } from '@/server/logger'
import {
getUserCreation,
validateContribution,
updateCreations,
isValidDateString,
getOpenCreations,
} from './util/creations'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import {
EVENT_CONTRIBUTION_CREATE,
EVENT_CONTRIBUTION_DELETE,
@ -54,9 +56,6 @@ import {
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import LogError from '@/server/LogError'
import { getLastTransaction } from './util/getLastTransaction'
import { findContributions } from './util/findContributions'
@Resolver()
export class ContributionResolver {
@Authorized([RIGHTS.CREATE_CONTRIBUTION])

View File

@ -4,12 +4,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { testEnvironment, cleanDB } from '@test/helpers'
import { User as DbUser } from '@entity/User'
import { GraphQLError } from 'graphql'
import { testEnvironment, cleanDB } from '@test/helpers'
import { createUser, setPassword, forgotPassword } from '@/seeds/graphql/mutations'
import { queryOptIn } from '@/seeds/graphql/queries'
import CONFIG from '@/config'
import { GraphQLError } from 'graphql'
let mutate: any, query: any, con: any
let testEnv: any

View File

@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-return */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Resolver, Query, Authorized, FieldResolver } from 'type-graphql'
import { getConnection } from '@dbTools/typeorm'

View File

@ -6,6 +6,13 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { User } from '@entity/User'
import { Decimal } from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { Transaction } from '@entity/Transaction'
import { Event as DbEvent } from '@entity/Event'
import { UserContact } from '@entity/UserContact'
import { transactionLinkCode } from './TransactionLinkResolver'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
@ -22,20 +29,14 @@ import {
createContribution,
updateContribution,
createTransactionLink,
deleteTransactionLink,
confirmContribution,
} from '@/seeds/graphql/mutations'
import { listTransactionLinksAdmin } from '@/seeds/graphql/queries'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { User } from '@entity/User'
import { Transaction } from '@entity/Transaction'
import { UnconfirmedContribution } from '@model/UnconfirmedContribution'
import Decimal from 'decimal.js-light'
import { GraphQLError } from 'graphql'
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import { logger } from '@test/testSetup'
import { EventType } from '@/event/Event'
import { Event as DbEvent } from '@entity/Event'
import { UserContact } from '@entity/UserContact'
// mock semaphore to allow use fake timers
jest.mock('@/util/TRANSACTIONS_LOCK')
@ -573,6 +574,7 @@ describe('TransactionLinkResolver', () => {
describe('link exists', () => {
let myCode: string
let myId: number
beforeAll(async () => {
await mutate({
@ -589,7 +591,7 @@ describe('TransactionLinkResolver', () => {
})
const {
data: {
createTransactionLink: { code },
createTransactionLink: { id, code },
},
} = await mutate({
mutation: createTransactionLink,
@ -599,6 +601,23 @@ describe('TransactionLinkResolver', () => {
},
})
myCode = code
myId = id
})
it('stores the TRANSACTION_LINK_CREATE event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.TRANSACTION_LINK_CREATE,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
involvedTransactionLinkId: myId,
amount: expect.decimalEqual(200),
}),
)
})
describe('own link', () => {
@ -625,6 +644,94 @@ describe('TransactionLinkResolver', () => {
expect.any(Number),
)
})
it('delete own link', async () => {
await expect(
mutate({
mutation: deleteTransactionLink,
variables: {
id: myId,
},
}),
).resolves.toMatchObject({
data: { deleteTransactionLink: true },
})
})
it('stores the TRANSACTION_LINK_DELETE event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.TRANSACTION_LINK_DELETE,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
involvedTransactionLinkId: myId,
}),
)
})
})
describe('other link', () => {
beforeAll(async () => {
await mutate({
mutation: login,
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
})
const {
data: {
createTransactionLink: { id, code },
},
} = await mutate({
mutation: createTransactionLink,
variables: {
amount: 200,
memo: 'This is a transaction link from bibi',
},
})
myCode = code
myId = id
await mutate({
mutation: login,
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
})
})
it('successfully redeems link', async () => {
await expect(
mutate({
mutation: redeemTransactionLink,
variables: {
code: myCode,
},
}),
).resolves.toMatchObject({
data: { redeemTransactionLink: true },
errors: undefined,
})
})
it('stores the TRANSACTION_LINK_REDEEM event in the database', async () => {
const creator = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
const redeemer = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.TRANSACTION_LINK_REDEEM,
affectedUserId: redeemer.user.id,
actingUserId: redeemer.user.id,
involvedUserId: creator.user.id,
involvedTransactionLinkId: myId,
amount: expect.decimalEqual(200),
}),
)
})
})
})
})

View File

@ -1,5 +1,5 @@
import { randomBytes } from 'crypto'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { getConnection } from '@dbTools/typeorm'
@ -9,6 +9,11 @@ import { Transaction as DbTransaction } from '@entity/Transaction'
import { Contribution as DbContribution } from '@entity/Contribution'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query, Int } from 'type-graphql'
import { getUserCreation, validateContribution } from './util/creations'
import { executeTransaction } from './TransactionResolver'
import { getLastTransaction } from './util/getLastTransaction'
import transactionLinkList from './util/transactionLinkList'
import { User } from '@model/User'
import { ContributionLink } from '@model/ContributionLink'
import { Decay } from '@model/Decay'
@ -20,21 +25,14 @@ import { ContributionCycleType } from '@enum/ContributionCycleType'
import TransactionLinkArgs from '@arg/TransactionLinkArgs'
import Paginated from '@arg/Paginated'
import TransactionLinkFilters from '@arg/TransactionLinkFilters'
import { backendLogger as logger } from '@/server/logger'
import { Context, getUser, getClientTimezoneOffset } from '@/server/context'
import { Resolver, Args, Arg, Authorized, Ctx, Mutation, Query, Int } from 'type-graphql'
import { calculateBalance } from '@/util/validate'
import { RIGHTS } from '@/auth/RIGHTS'
import { calculateDecay } from '@/util/decay'
import { getUserCreation, validateContribution } from './util/creations'
import { executeTransaction } from './TransactionResolver'
import QueryLinkResult from '@union/QueryLinkResult'
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import LogError from '@/server/LogError'
import { getLastTransaction } from './util/getLastTransaction'
import transactionLinkList from './util/transactionLinkList'
import {
EVENT_CONTRIBUTION_LINK_REDEEM,
EVENT_TRANSACTION_LINK_CREATE,

View File

@ -5,7 +5,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Transaction } from '@entity/Transaction'
import { User } from '@entity/User'
import { GraphQLError } from 'graphql'
import { Event as DbEvent } from '@entity/Event'
import { findUserByEmail } from './UserResolver'
import { EventType } from '@/event/Event'
import { userFactory } from '@/seeds/factory/user'
import {
@ -18,13 +23,8 @@ import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { stephenHawking } from '@/seeds/users/stephen-hawking'
import { Event as DbEvent } from '@entity/Event'
import { Transaction } from '@entity/Transaction'
import { User } from '@entity/User'
import { cleanDB, testEnvironment } from '@test/helpers'
import { logger } from '@test/testSetup'
import { GraphQLError } from 'graphql'
import { findUserByEmail } from './UserResolver'
let mutate: any, query: any, con: any
let testEnv: any

View File

@ -2,13 +2,17 @@
/* eslint-disable new-cap */
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { Resolver, Query, Args, Authorized, Ctx, Mutation } from 'type-graphql'
import { getCustomRepository, getConnection, In } from '@dbTools/typeorm'
import { User as dbUser } from '@entity/User'
import { Transaction as dbTransaction } from '@entity/Transaction'
import { TransactionLink as dbTransactionLink } from '@entity/TransactionLink'
import { BalanceResolver } from './BalanceResolver'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import { findUserByEmail } from './UserResolver'
import { getLastTransaction } from './util/getLastTransaction'
import { TransactionRepository } from '@repository/Transaction'
import { TransactionLinkRepository } from '@repository/TransactionLink'
@ -32,15 +36,9 @@ import {
} from '@/emails/sendEmailVariants'
import { EVENT_TRANSACTION_RECEIVE, EVENT_TRANSACTION_SEND } from '@/event/Event'
import { BalanceResolver } from './BalanceResolver'
import { MEMO_MAX_CHARS, MEMO_MIN_CHARS } from './const/const'
import { findUserByEmail } from './UserResolver'
import { TRANSACTIONS_LOCK } from '@/util/TRANSACTIONS_LOCK'
import LogError from '@/server/LogError'
import { getLastTransaction } from './util/getLastTransaction'
export const executeTransaction = async (
amount: Decimal,
memo: string,

View File

@ -6,6 +6,15 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { GraphQLError } from 'graphql'
import { User } from '@entity/User'
import { TransactionLink } from '@entity/TransactionLink'
import { validate as validateUUID, version as versionUUID } from 'uuid'
import { UserContact } from '@entity/UserContact'
import { Event as DbEvent } from '@entity/Event'
import { OptInType } from '@enum/OptInType'
import { UserContactType } from '@enum/UserContactType'
import { PasswordEncryptionType } from '@enum/PasswordEncryptionType'
import { objectValuesToArray } from '@/util/utilities'
import { testEnvironment, headerPushMock, resetToken, cleanDB } from '@test/helpers'
import { logger, i18n as localization } from '@test/testSetup'
@ -27,8 +36,6 @@ import {
sendActivationEmail,
} from '@/seeds/graphql/mutations'
import { verifyLogin, queryOptIn, searchAdminUsers, searchUsers } from '@/seeds/graphql/queries'
import { GraphQLError } from 'graphql'
import { User } from '@entity/User'
import CONFIG from '@/config'
import {
sendAccountActivationEmail,
@ -38,19 +45,12 @@ import {
import { contributionLinkFactory } from '@/seeds/factory/contributionLink'
import { transactionLinkFactory } from '@/seeds/factory/transactionLink'
import { ContributionLink } from '@model/ContributionLink'
import { TransactionLink } from '@entity/TransactionLink'
import { EventType } from '@/event/Event'
import { Event as DbEvent } from '@entity/Event'
import { validate as validateUUID, version as versionUUID } from 'uuid'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { UserContact } from '@entity/UserContact'
import { OptInType } from '../enum/OptInType'
import { UserContactType } from '../enum/UserContactType'
import { bobBaumeister } from '@/seeds/users/bob-baumeister'
import { stephenHawking } from '@/seeds/users/stephen-hawking'
import { garrickOllivander } from '@/seeds/users/garrick-ollivander'
import { encryptPassword } from '@/password/PasswordEncryptor'
import { PasswordEncryptionType } from '../enum/PasswordEncryptionType'
import { SecretKeyCryptographyCreateKey } from '@/password/EncryptorUtils'
// import { klicktippSignIn } from '@/apis/KlicktippController'
@ -182,14 +182,14 @@ describe('UserResolver', () => {
})
})
it('stores the REGISTER event in the database', async () => {
it('stores the USER_REGISTER event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.REGISTER,
type: EventType.USER_REGISTER,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}),
@ -216,10 +216,10 @@ describe('UserResolver', () => {
})
})
it('stores the SEND_CONFIRMATION_EMAIL event in the database', async () => {
it('stores the EMAIL_CONFIRMATION event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.SEND_CONFIRMATION_EMAIL,
type: EventType.EMAIL_CONFIRMATION,
affectedUserId: user[0].id,
actingUserId: user[0].id,
}),
@ -258,14 +258,14 @@ describe('UserResolver', () => {
)
})
it('stores the SEND_ACCOUNT_MULTIREGISTRATION_EMAIL event in the database', async () => {
it('stores the EMAIL_ACCOUNT_MULTIREGISTRATION event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
type: EventType.EMAIL_ACCOUNT_MULTIREGISTRATION,
affectedUserId: userConatct.user.id,
actingUserId: 0,
}),
@ -363,20 +363,20 @@ describe('UserResolver', () => {
)
})
it('stores the ACTIVATE_ACCOUNT event in the database', async () => {
it('stores the USER_ACTIVATE_ACCOUNT event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.ACTIVATE_ACCOUNT,
type: EventType.USER_ACTIVATE_ACCOUNT,
affectedUserId: user[0].id,
actingUserId: user[0].id,
}),
)
})
it('stores the REDEEM_REGISTER event in the database', async () => {
it('stores the USER_REGISTER_REDEEM event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.REDEEM_REGISTER,
type: EventType.USER_REGISTER_REDEEM,
affectedUserId: result.data.createUser.id,
actingUserId: result.data.createUser.id,
involvedContributionLinkId: link.id,
@ -458,10 +458,10 @@ describe('UserResolver', () => {
)
})
it('stores the REDEEM_REGISTER event in the database', async () => {
it('stores the USER_REGISTER_REDEEM event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.REDEEM_REGISTER,
type: EventType.USER_REGISTER_REDEEM,
affectedUserId: newUser.data.createUser.id,
actingUserId: newUser.data.createUser.id,
involvedTransactionLinkId: transactionLink.id,
@ -687,14 +687,14 @@ describe('UserResolver', () => {
expect(headerPushMock).toBeCalledWith({ key: 'token', value: expect.any(String) })
})
it('stores the LOGIN event in the database', async () => {
it('stores the USER_LOGIN event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.LOGIN,
type: EventType.USER_LOGIN,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}),
@ -868,6 +868,20 @@ describe('UserResolver', () => {
}),
)
})
it('stores the USER_LOGOUT event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.USER_LOGOUT,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}),
)
})
})
})
@ -941,10 +955,10 @@ describe('UserResolver', () => {
)
})
it('stores the LOGIN event in the database', async () => {
it('stores the USER_LOGIN event in the database', async () => {
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.LOGIN,
type: EventType.USER_LOGIN,
affectedUserId: user[0].id,
actingUserId: user[0].id,
}),
@ -1023,6 +1037,20 @@ describe('UserResolver', () => {
}),
})
})
it('stores the EMAIL_FORGOT_PASSWORD event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.EMAIL_FORGOT_PASSWORD,
affectedUserId: userConatct.user.id,
actingUserId: 0,
}),
)
})
})
describe('request reset password again', () => {
@ -1147,6 +1175,20 @@ describe('UserResolver', () => {
}),
)
})
it('stores the USER_INFO_UPDATE event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.USER_INFO_UPDATE,
affectedUserId: userConatct.user.id,
actingUserId: userConatct.user.id,
}),
)
})
})
describe('language is not valid', () => {
@ -1517,6 +1559,24 @@ describe('UserResolver', () => {
)
expect(new Date(result.data.setUserRole)).toEqual(expect.any(Date))
})
it('stores the ADMIN_USER_ROLE_SET event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
const adminConatct = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.ADMIN_USER_ROLE_SET,
affectedUserId: userConatct.user.id,
actingUserId: adminConatct.user.id,
}),
)
})
})
describe('to usual user', () => {
@ -1702,6 +1762,24 @@ describe('UserResolver', () => {
expect(new Date(result.data.deleteUser)).toEqual(expect.any(Date))
})
it('stores the ADMIN_USER_DELETE event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'], withDeleted: true },
)
const adminConatct = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.ADMIN_USER_DELETE,
affectedUserId: userConatct.user.id,
actingUserId: adminConatct.user.id,
}),
)
})
describe('delete deleted user', () => {
it('throws an error', async () => {
jest.clearAllMocks()
@ -1857,14 +1935,14 @@ describe('UserResolver', () => {
})
})
it('stores the ADMIN_SEND_CONFIRMATION_EMAIL event in the database', async () => {
it('stores the EMAIL_ADMIN_CONFIRMATION event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.ADMIN_SEND_CONFIRMATION_EMAIL,
type: EventType.EMAIL_ADMIN_CONFIRMATION,
affectedUserId: userConatct.user.id,
actingUserId: admin.id,
}),
@ -1977,6 +2055,24 @@ describe('UserResolver', () => {
}),
)
})
it('stores the ADMIN_USER_UNDELETE event in the database', async () => {
const userConatct = await UserContact.findOneOrFail(
{ email: 'bibi@bloxberg.de' },
{ relations: ['user'] },
)
const adminConatct = await UserContact.findOneOrFail(
{ email: 'peter@lustig.de' },
{ relations: ['user'] },
)
await expect(DbEvent.find()).resolves.toContainEqual(
expect.objectContaining({
type: EventType.ADMIN_USER_UNDELETE,
affectedUserId: userConatct.user.id,
actingUserId: adminConatct.user.id,
}),
)
})
})
})
})

View File

@ -21,6 +21,9 @@ import { User as DbUser } from '@entity/User'
import { UserContact as DbUserContact } from '@entity/UserContact'
import { TransactionLink as DbTransactionLink } from '@entity/TransactionLink'
import { ContributionLink as DbContributionLink } from '@entity/ContributionLink'
import { getUserCreations } from './util/creations'
import { FULL_CREATION_AVAILABLE } from './const/const'
import { PasswordEncryptionType } from '@enum/PasswordEncryptionType'
import { UserRepository } from '@repository/User'
import { User } from '@model/User'
@ -55,23 +58,26 @@ import { hasElopageBuys } from '@/util/hasElopageBuys'
import {
Event,
EventType,
EVENT_LOGIN,
EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL,
EVENT_SEND_CONFIRMATION_EMAIL,
EVENT_REGISTER,
EVENT_ACTIVATE_ACCOUNT,
EVENT_ADMIN_SEND_CONFIRMATION_EMAIL,
EVENT_USER_LOGIN,
EVENT_EMAIL_ACCOUNT_MULTIREGISTRATION,
EVENT_EMAIL_CONFIRMATION,
EVENT_USER_REGISTER,
EVENT_USER_ACTIVATE_ACCOUNT,
EVENT_EMAIL_ADMIN_CONFIRMATION,
EVENT_USER_LOGOUT,
EVENT_EMAIL_FORGOT_PASSWORD,
EVENT_USER_INFO_UPDATE,
EVENT_ADMIN_USER_ROLE_SET,
EVENT_ADMIN_USER_DELETE,
EVENT_ADMIN_USER_UNDELETE,
} from '@/event/Event'
import { getUserCreations } from './util/creations'
import { isValidPassword } from '@/password/EncryptorUtils'
import { FULL_CREATION_AVAILABLE } from './const/const'
import { encryptPassword, verifyPassword } from '@/password/PasswordEncryptor'
import { PasswordEncryptionType } from '../enum/PasswordEncryptionType'
import LogError from '@/server/LogError'
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs
const sodium = require('sodium-native')
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs
const random = require('random-bigint')
const LANGUAGES = ['de', 'en', 'es', 'fr', 'nl']
@ -182,22 +188,16 @@ export class UserResolver {
value: encode(dbUser.gradidoID),
})
await EVENT_LOGIN(dbUser)
await EVENT_USER_LOGIN(dbUser)
logger.info(`successful Login: ${JSON.stringify(user, null, 2)}`)
return user
}
@Authorized([RIGHTS.LOGOUT])
@Mutation(() => Boolean)
logout(): boolean {
// TODO: Event still missing here!!
// TODO: We dont need this anymore, but might need this in the future in oder to invalidate a valid JWT-Token.
// Furthermore this hook can be useful for tracking user behaviour (did he logout or not? Warn him if he didn't on next login)
// The functionality is fully client side - the client just needs to delete his token with the current implementation.
// we could try to force this by sending `token: null` or `token: ''` with this call. But since it bares no real security
// we should just return true for now.
logger.info('Logout...')
// remove user.pubKey from logger-context to ensure a correct filter on log-messages belonging to the same user
async logout(@Ctx() context: Context): Promise<boolean> {
await EVENT_USER_LOGOUT(getUser(context))
// remove user from logger context
logger.addContext('user', 'unknown')
return true
}
@ -251,8 +251,7 @@ export class UserResolver {
email,
language: foundUser.language, // use language of the emails owner for sending
})
await EVENT_SEND_ACCOUNT_MULTIREGISTRATION_EMAIL(foundUser)
await EVENT_EMAIL_ACCOUNT_MULTIREGISTRATION(foundUser)
logger.info(
`sendAccountMultiRegistrationEmail by ${firstName} ${lastName} to ${foundUser.firstName} ${foundUser.lastName} <${email}>`,
@ -271,7 +270,7 @@ export class UserResolver {
const gradidoID = await newGradidoID()
const eventRegisterRedeem = Event(
EventType.REDEEM_REGISTER,
EventType.USER_REGISTER_REDEEM,
{ id: 0 } as DbUser,
{ id: 0 } as DbUser,
)
@ -337,7 +336,7 @@ export class UserResolver {
})
logger.info(`sendAccountActivationEmail of ${firstName}.${lastName} to ${email}`)
await EVENT_SEND_CONFIRMATION_EMAIL(dbUser)
await EVENT_EMAIL_CONFIRMATION(dbUser)
if (!emailSent) {
logger.debug(`Account confirmation link: ${activationLink}`)
@ -358,7 +357,7 @@ export class UserResolver {
eventRegisterRedeem.actingUser = dbUser
await eventRegisterRedeem.save()
} else {
await EVENT_REGISTER(dbUser)
await EVENT_USER_REGISTER(dbUser)
}
return new User(dbUser)
@ -411,6 +410,7 @@ export class UserResolver {
)
}
logger.info(`forgotPassword(${email}) successful...`)
await EVENT_EMAIL_FORGOT_PASSWORD(user)
return true
}
@ -473,8 +473,6 @@ export class UserResolver {
await queryRunner.commitTransaction()
logger.info('User and UserContact data written successfully...')
await EVENT_ACTIVATE_ACCOUNT(user)
} catch (e) {
await queryRunner.rollbackTransaction()
throw new LogError('Error on writing User and User Contact data', e)
@ -492,13 +490,9 @@ export class UserResolver {
)
} catch (e) {
logger.error('Error subscribing to klicktipp', e)
// TODO is this a problem?
// eslint-disable-next-line no-console
/* uncomment this, when you need the activation link on the console
console.log('Could not subscribe to klicktipp')
*/
}
}
await EVENT_USER_ACTIVATE_ACCOUNT(user)
return true
}
@ -535,21 +529,21 @@ export class UserResolver {
@Ctx() context: Context,
): Promise<boolean> {
logger.info(`updateUserInfos(${firstName}, ${lastName}, ${language}, ***, ***)...`)
const userEntity = getUser(context)
const user = getUser(context)
if (firstName) {
userEntity.firstName = firstName
user.firstName = firstName
}
if (lastName) {
userEntity.lastName = lastName
user.lastName = lastName
}
if (language) {
if (!isLanguage(language)) {
throw new LogError('Given language is not a valid language', language)
}
userEntity.language = language
user.language = language
i18n.setLocale(language)
}
@ -561,22 +555,22 @@ export class UserResolver {
)
}
if (!verifyPassword(userEntity, password)) {
if (!verifyPassword(user, password)) {
throw new LogError(`Old password is invalid`)
}
// Save new password hash and newly encrypted private key
userEntity.passwordEncryptionType = PasswordEncryptionType.GRADIDO_ID
userEntity.password = encryptPassword(userEntity, passwordNew)
user.passwordEncryptionType = PasswordEncryptionType.GRADIDO_ID
user.password = encryptPassword(user, passwordNew)
}
// Save hideAmountGDD value
if (hideAmountGDD !== undefined) {
userEntity.hideAmountGDD = hideAmountGDD
user.hideAmountGDD = hideAmountGDD
}
// Save hideAmountGDT value
if (hideAmountGDT !== undefined) {
userEntity.hideAmountGDT = hideAmountGDT
user.hideAmountGDT = hideAmountGDT
}
const queryRunner = getConnection().createQueryRunner()
@ -584,7 +578,7 @@ export class UserResolver {
await queryRunner.startTransaction('REPEATABLE READ')
try {
await queryRunner.manager.save(userEntity).catch((error) => {
await queryRunner.manager.save(user).catch((error) => {
throw new LogError('Error saving user', error)
})
@ -597,6 +591,8 @@ export class UserResolver {
await queryRunner.release()
}
logger.info('updateUserInfos() successfully finished...')
await EVENT_USER_INFO_UPDATE(user)
return true
}
@ -722,8 +718,8 @@ export class UserResolver {
throw new LogError('Could not find user with given ID', userId)
}
// administrator user changes own role?
const moderatorUser = getUser(context)
if (moderatorUser.id === userId) {
const moderator = getUser(context)
if (moderator.id === userId) {
throw new LogError('Administrator can not change his own role')
}
// change isAdmin
@ -744,6 +740,7 @@ export class UserResolver {
break
}
await user.save()
await EVENT_ADMIN_USER_ROLE_SET(user, moderator)
const newUser = await DbUser.findOne({ id: userId })
return newUser ? newUser.isAdmin : null
}
@ -760,19 +757,23 @@ export class UserResolver {
throw new LogError('Could not find user with given ID', userId)
}
// moderator user disabled own account?
const moderatorUser = getUser(context)
if (moderatorUser.id === userId) {
const moderator = getUser(context)
if (moderator.id === userId) {
throw new LogError('Moderator can not delete his own account')
}
// soft-delete user
await user.softRemove()
await EVENT_ADMIN_USER_DELETE(user, moderator)
const newUser = await DbUser.findOne({ id: userId }, { withDeleted: true })
return newUser ? newUser.deletedAt : null
}
@Authorized([RIGHTS.UNDELETE_USER])
@Mutation(() => Date, { nullable: true })
async unDeleteUser(@Arg('userId', () => Int) userId: number): Promise<Date | null> {
async unDeleteUser(
@Arg('userId', () => Int) userId: number,
@Ctx() context: Context,
): Promise<Date | null> {
const user = await DbUser.findOne({ id: userId }, { withDeleted: true })
if (!user) {
throw new LogError('Could not find user with given ID', userId)
@ -781,6 +782,7 @@ export class UserResolver {
throw new LogError('User is not deleted')
}
await user.recover()
await EVENT_ADMIN_USER_UNDELETE(user, getUser(context))
return null
}
@ -814,9 +816,8 @@ export class UserResolver {
// In case EMails are disabled log the activation link for the user
if (!emailSent) {
logger.info(`Account confirmation link: ${activationLink}`)
} else {
await EVENT_ADMIN_SEND_CONFIRMATION_EMAIL(user, getUser(context))
}
await EVENT_EMAIL_ADMIN_CONFIRMATION(user, getUser(context))
return true
}

View File

@ -1,4 +1,4 @@
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
export const MAX_CREATION_AMOUNT = new Decimal(1000)
export const FULL_CREATION_AVAILABLE = [

View File

@ -4,7 +4,7 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/no-explicit-any */
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { userFactory } from '@/seeds/factory/user'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { bobBaumeister } from '@/seeds/users/bob-baumeister'

View File

@ -4,14 +4,14 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { User } from '@entity/User'
import { Contribution } from '@entity/Contribution'
import { getUserCreation } from './creations'
import { testEnvironment, cleanDB, contributionDateFormatter } from '@test/helpers'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { User } from '@entity/User'
import { Contribution } from '@entity/Contribution'
import { userFactory } from '@/seeds/factory/user'
import { login, createContribution, adminCreateContribution } from '@/seeds/graphql/mutations'
import { getUserCreation } from './creations'
let mutate: any, con: any
let testEnv: any

View File

@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import LogError from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { getConnection } from '@dbTools/typeorm'
import { Contribution } from '@entity/Contribution'
import Decimal from 'decimal.js-light'
import { FULL_CREATION_AVAILABLE, MAX_CREATION_AMOUNT } from '../const/const'
import { Decimal } from 'decimal.js-light'
import { FULL_CREATION_AVAILABLE, MAX_CREATION_AMOUNT } from '@/graphql/resolver/const/const'
import { backendLogger as logger } from '@/server/logger'
import { OpenCreation } from '@model/OpenCreation'
import LogError from '@/server/LogError'
interface CreationMap {
id: number

View File

@ -1,7 +1,7 @@
import { ContributionStatus } from '@enum/ContributionStatus'
import { Order } from '@enum/Order'
import { Contribution as DbContribution } from '@entity/Contribution'
import { In } from '@dbTools/typeorm'
import { ContributionStatus } from '@enum/ContributionStatus'
import { Order } from '@enum/Order'
interface FindContributionsOptions {
order: Order

View File

@ -1,7 +1,7 @@
import { GraphQLScalarType, Kind } from 'graphql'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
export default new GraphQLScalarType({
const DecimalType = new GraphQLScalarType({
name: 'Decimal',
description: 'The `Decimal` scalar type to represent currency values',
@ -21,3 +21,5 @@ export default new GraphQLScalarType({
return new Decimal(ast.value)
},
})
export default DecimalType

View File

@ -1,10 +1,10 @@
import path from 'path'
import { GraphQLSchema } from 'graphql'
import { buildSchema } from 'type-graphql'
import path from 'path'
import { Decimal } from 'decimal.js-light'
import isAuthorized from './directive/isAuthorized'
import DecimalScalar from './scalar/Decimal'
import Decimal from 'decimal.js-light'
const schema = async (): Promise<GraphQLSchema> => {
return buildSchema({

View File

@ -1,6 +1,7 @@
import { createUnionType } from 'type-graphql'
import { TransactionLink } from '@model/TransactionLink'
import { ContributionLink } from '@model/ContributionLink'
export default createUnionType({
name: 'QueryLinkResult', // the name of the GraphQL union
types: () => [TransactionLink, ContributionLink] as const, // function that returns tuple of object types classes

View File

@ -1,13 +1,13 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { User } from '@entity/User'
import CONFIG from '@/config'
import LogError from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { User } from '@entity/User'
import { PasswordEncryptionType } from '@enum/PasswordEncryptionType'
// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-commonjs
const sodium = require('sodium-native')
// We will reuse this for changePassword

View File

@ -1,5 +1,5 @@
import { CreationInterface } from './CreationInterface'
import { nMonthsBefore } from '../factory/creation'
import { nMonthsBefore } from '@/seeds/factory/creation'
const bobsSendings = [
{

View File

@ -5,11 +5,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { login, createContribution, confirmContribution } from '@/seeds/graphql/mutations'
import { CreationInterface } from '@/seeds/creation/CreationInterface'
import { ApolloServerTestClient } from 'apollo-server-testing'
import { Transaction } from '@entity/Transaction'
import { Contribution } from '@entity/Contribution'
import { CreationInterface } from '@/seeds/creation/CreationInterface'
import { login, createContribution, confirmContribution } from '@/seeds/graphql/mutations'
import { findUserByEmail } from '@/graphql/resolver/UserResolver'
// import CONFIG from '@/config/index'

View File

@ -1,10 +1,10 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/unbound-method */
import { ApolloServerTestClient } from 'apollo-server-testing'
import { TransactionLink } from '@entity/TransactionLink'
import { login, createTransactionLink } from '@/seeds/graphql/mutations'
import { TransactionLinkInterface } from '@/seeds/transactionLink/TransactionLinkInterface'
import { transactionLinkExpireDate } from '@/graphql/resolver/TransactionLinkResolver'
import { TransactionLink } from '@entity/TransactionLink'
export const transactionLinkFactory = async (
client: ApolloServerTestClient,

View File

@ -1,9 +1,9 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/unbound-method */
import { createUser, setPassword } from '@/seeds/graphql/mutations'
import { User } from '@entity/User'
import { UserInterface } from '@/seeds/users/UserInterface'
import { ApolloServerTestClient } from 'apollo-server-testing'
import { createUser, setPassword } from '@/seeds/graphql/mutations'
import { UserInterface } from '@/seeds/users/UserInterface'
export const userFactory = async (
client: ApolloServerTestClient,

View File

@ -1,4 +1,4 @@
import gql from 'graphql-tag'
import { gql } from 'graphql-tag'
export const subscribeNewsletter = gql`
mutation ($email: String!, $language: String!) {

View File

@ -1,4 +1,4 @@
import gql from 'graphql-tag'
import { gql } from 'graphql-tag'
export const verifyLogin = gql`
query {

View File

@ -5,11 +5,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { backendLogger as logger } from '@/server/logger'
import createServer from '../server/createServer'
import { createTestClient } from 'apollo-server-testing'
import { name, internet, datatype } from 'faker'
import { entities } from '@entity/index'
import { users } from './users/index'
import { creations } from './creation/index'
@ -19,7 +17,8 @@ import { userFactory } from './factory/user'
import { creationFactory } from './factory/creation'
import { transactionLinkFactory } from './factory/transactionLink'
import { contributionLinkFactory } from './factory/contributionLink'
import { entities } from '@entity/index'
import createServer from '@/server/createServer'
import { backendLogger as logger } from '@/server/logger'
import CONFIG from '@/config'
CONFIG.EMAIL = false

View File

@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/unbound-method */
import { logger } from '@test/testSetup'
import LogError from './LogError'
import { logger } from '@test/testSetup'
describe('LogError', () => {
it('logs an Error when created', () => {

View File

@ -1,9 +1,9 @@
import { Role } from '@/auth/Role'
import { User as dbUser } from '@entity/User'
import { Transaction as dbTransaction } from '@entity/Transaction'
import Decimal from 'decimal.js-light'
import { Decimal } from 'decimal.js-light'
import { ExpressContext } from 'apollo-server-express'
import LogError from './LogError'
import { Role } from '@/auth/Role'
export interface Context {
token: string | null

View File

@ -1,35 +1,20 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable @typescript-eslint/unbound-method */
import 'reflect-metadata'
import { ApolloServer } from 'apollo-server-express'
import express, { Express } from 'express'
// database
import connection from '@/typeorm/connection'
import { checkDBVersion } from '@/typeorm/DBVersion'
// server
import express, { Express, json, urlencoded } from 'express'
import { Connection } from '@dbTools/typeorm'
import { Logger } from 'log4js'
import cors from './cors'
import serverContext from './context'
import plugins from './plugins'
// config
import CONFIG from '@/config'
// graphql
import schema from '@/graphql/schema'
// webhooks
import { elopageWebhook } from '@/webhook/elopage'
import { Connection } from '@dbTools/typeorm'
import { apolloLogger } from './logger'
import { Logger } from 'log4js'
// i18n
import { i18n } from './localization'
import connection from '@/typeorm/connection'
import { checkDBVersion } from '@/typeorm/DBVersion'
import CONFIG from '@/config'
import schema from '@/graphql/schema'
import { elopageWebhook } from '@/webhook/elopage'
// TODO implement
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
@ -66,9 +51,9 @@ const createServer = async (
app.use(cors)
// bodyparser json
app.use(express.json())
app.use(json())
// bodyparser urlencoded for elopage
app.use(express.urlencoded({ extended: true }))
app.use(urlencoded({ extended: true }))
// i18n
app.use(localization.init)

Some files were not shown because too many files have changed in this diff Show More