From 89529149aed1645d8e1c75d1d8f9c207c3250c05 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:17:15 +0100 Subject: [PATCH 01/87] Create new table for admin interface so that we can store the pending creations. --- database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts diff --git a/database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts b/database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts new file mode 100644 index 000000000..e76d31fd6 --- /dev/null +++ b/database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts @@ -0,0 +1,4 @@ +import { BaseEntity, Entity } from "typeorm"; + +@Entity('login_pending_tasks_admin') +export class LoginPendingTasksAdmin extends BaseEntity {} From b3d69bae0df6998eceb9a48689563005fab3536d Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:21:06 +0100 Subject: [PATCH 02/87] Moved new entity to folder 0005 since it needs to correspond to migrations scripts. --- .../LoginPendingTasksAdmin.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename database/entity/{0004-admin_tables => 0005-admin_tables}/LoginPendingTasksAdmin.ts (100%) diff --git a/database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts similarity index 100% rename from database/entity/0004-admin_tables/LoginPendingTasksAdmin.ts rename to database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts From d79a40cbb0873bf10e15ff23d2b93d72d293a365 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:21:38 +0100 Subject: [PATCH 03/87] Export of the new entity. --- database/entity/LoginPendingTasksAdmin.ts | 1 + 1 file changed, 1 insertion(+) create mode 100644 database/entity/LoginPendingTasksAdmin.ts diff --git a/database/entity/LoginPendingTasksAdmin.ts b/database/entity/LoginPendingTasksAdmin.ts new file mode 100644 index 000000000..b8580a638 --- /dev/null +++ b/database/entity/LoginPendingTasksAdmin.ts @@ -0,0 +1 @@ +export { LoginPendingTasksAdmin } from './0004-admin_tables/LoginPendingTasksAdmin' From 84387c9a02d5eda3dcdd6a5da176e3b0e7045a39 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:22:41 +0100 Subject: [PATCH 04/87] Deploy new entity. --- database/entity/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/entity/index.ts b/database/entity/index.ts index 5e4e98118..2db836904 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -10,6 +10,7 @@ import { TransactionSendCoin } from './TransactionSendCoin' import { User } from './User' import { UserSetting } from './UserSetting' import { UserTransaction } from './UserTransaction' +import { LoginPendingTasksAdmin } from './LoginPendingTasksAdmin' export const entities = [ Balance, @@ -24,4 +25,5 @@ export const entities = [ User, UserSetting, UserTransaction, + LoginPendingTasksAdmin, ] From 9915a78c7e441f94c7e2fb2705f8810ef150cf5c Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:37:35 +0100 Subject: [PATCH 05/87] Creation script and deletion script. --- database/migrations/0005-admin_tables.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 database/migrations/0005-admin_tables.ts diff --git a/database/migrations/0005-admin_tables.ts b/database/migrations/0005-admin_tables.ts new file mode 100644 index 000000000..3730755f0 --- /dev/null +++ b/database/migrations/0005-admin_tables.ts @@ -0,0 +1,24 @@ +/* MIGRATION FOR ADMIN INTERFACE + */ + +export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(` + CREATE TABLE \`login_pending_tasks_admin\` ( + \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, + \`user_id\` int UNSIGNED DEFAULT 0, + \`request\` varbinary(2048) NOT NULL, + \`created\` datetime NOT NULL, + \`finished\` datetime DEFAULT '2000-01-01 000000', + \`result_json\` text DEFAULT NULL, + \`param_json\` text DEFAULT NULL, + \`task_type_id\` int UNSIGNED NOT NULL, + \`child_pending_task_id\` int UNSIGNED DEFAULT 0, + \`parent_pending_task_id\` int UNSIGNED DEFAULT 0, + PRIMARY KEY (\`id\`) + ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; + `) +} + +export async function downgrade(queryFn: (query: string, values?: any[]) => Promise>) { + await queryFn(`DROP TABLE \`login_pending_tasks_admin\`;`) +} From 3e363db42e4ba46223bb4c57ffd1174efb6070d6 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:40:45 +0100 Subject: [PATCH 06/87] Adding a description of the migration. --- database/migrations/0005-admin_tables.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/database/migrations/0005-admin_tables.ts b/database/migrations/0005-admin_tables.ts index 3730755f0..8e1219715 100644 --- a/database/migrations/0005-admin_tables.ts +++ b/database/migrations/0005-admin_tables.ts @@ -1,19 +1,24 @@ /* MIGRATION FOR ADMIN INTERFACE + * + * This migration is special since it takes into account that + * the database can be setup already but also may not be. + * Therefore you will find all `CREATE TABLE` statements with + * a `IF NOT EXISTS`, all `INSERT` with an `IGNORE` and in the + * downgrade function all `DROP TABLE` with a `IF EXISTS`. + * This ensures compatibility for existing or non-existing + * databases. */ export async function upgrade(queryFn: (query: string, values?: any[]) => Promise>) { await queryFn(` CREATE TABLE \`login_pending_tasks_admin\` ( \`id\` int UNSIGNED NOT NULL AUTO_INCREMENT, - \`user_id\` int UNSIGNED DEFAULT 0, - \`request\` varbinary(2048) NOT NULL, + \`userId\` int UNSIGNED DEFAULT 0, \`created\` datetime NOT NULL, - \`finished\` datetime DEFAULT '2000-01-01 000000', - \`result_json\` text DEFAULT NULL, - \`param_json\` text DEFAULT NULL, - \`task_type_id\` int UNSIGNED NOT NULL, - \`child_pending_task_id\` int UNSIGNED DEFAULT 0, - \`parent_pending_task_id\` int UNSIGNED DEFAULT 0, + \`date\` datetime NOT NULL, + \`note\` text DEFAULT NULL, + \`amount\` bigint(20) NOT NULL, + \`moderator\` int UNSIGNED DEFAULT 0, PRIMARY KEY (\`id\`) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4; `) From b939feb0e14bb99ef50aa54c77e0513199ff2a68 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 09:41:59 +0100 Subject: [PATCH 07/87] Folder change added --- database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts | 2 +- database/entity/LoginPendingTasksAdmin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts index e76d31fd6..afd09ad68 100644 --- a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts +++ b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts @@ -1,4 +1,4 @@ -import { BaseEntity, Entity } from "typeorm"; +import { BaseEntity, Entity } from 'typeorm' @Entity('login_pending_tasks_admin') export class LoginPendingTasksAdmin extends BaseEntity {} diff --git a/database/entity/LoginPendingTasksAdmin.ts b/database/entity/LoginPendingTasksAdmin.ts index b8580a638..f766b74dd 100644 --- a/database/entity/LoginPendingTasksAdmin.ts +++ b/database/entity/LoginPendingTasksAdmin.ts @@ -1 +1 @@ -export { LoginPendingTasksAdmin } from './0004-admin_tables/LoginPendingTasksAdmin' +export { LoginPendingTasksAdmin } from './0005-admin_tables/LoginPendingTasksAdmin' From 6b3d28d1ff0fc5ab11549dab080c7aff93e3d886 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 10:01:13 +0100 Subject: [PATCH 08/87] Definition of the entity based on the database table. --- .../LoginPendingTasksAdmin.ts | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts index afd09ad68..8e5d57d3a 100644 --- a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts +++ b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts @@ -1,4 +1,25 @@ -import { BaseEntity, Entity } from 'typeorm' +import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm' @Entity('login_pending_tasks_admin') -export class LoginPendingTasksAdmin extends BaseEntity {} +export class LoginPendingTasksAdmin extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ unsigned: true, nullable: false }) + userId: number + + @Column({ type: 'datetime', default: () => 'CURRENT_TIMESTAMP' }) + created: Date + + @Column({ type: 'datetime', nullable: false }) + date: Date + + @Column({ length: 256, nullable: true, default: null }) + note: string + + @Column({ type: 'bigint', nullable: false }) + amount: BigInt + + @Column() + moderator: number +} From 4b80507c9b885552119abcdfb7d73766cd69d6ae Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 24 Nov 2021 10:12:57 +0100 Subject: [PATCH 09/87] Change the database version in backend. --- backend/src/server/createServer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/server/createServer.ts b/backend/src/server/createServer.ts index 4350483ff..d5fbc20ee 100644 --- a/backend/src/server/createServer.ts +++ b/backend/src/server/createServer.ts @@ -25,7 +25,7 @@ import schema from '../graphql/schema' // TODO implement // import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity"; -const DB_VERSION = '0004-login_server_data' +const DB_VERSION = '0005-admin_tables' const createServer = async (context: any = serverContext): Promise => { // open mysql connection From c2c03d103297ed2a348f8ec9db58dcce5343d420 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 10:40:49 +0100 Subject: [PATCH 10/87] implementation of createPendingCreation search for the state_user. --- backend/src/graphql/resolver/AdminResolver.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9af50faad..65419523f 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,7 +1,8 @@ -import { Resolver, Query, Arg } from 'type-graphql' +import { Resolver, Query, Arg, Args } from 'type-graphql' import { getCustomRepository } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' +import { UserRepository } from '../../typeorm/repository/User' @Resolver() export class AdminResolver { @@ -23,4 +24,14 @@ export class AdminResolver { }) return users } + + @Query(() => Boolean) + async createPendingCreation( + @Args() { email, amount, note, creationDate }: CreatePendingCreationArgs, + ): Promise { + // TODO: Check user validity + const userRepository = getCustomRepository(UserRepository) + const user = await userRepository.findByEmail(email) + return true + } } From f3cd722e9fdc070dff7d35d4063c57f6b70238a2 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 10:41:34 +0100 Subject: [PATCH 11/87] User creations logic in comments. --- backend/src/graphql/resolver/AdminResolver.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 65419523f..69a0e7c83 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -32,6 +32,13 @@ export class AdminResolver { // TODO: Check user validity const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) + // TODO: Check user open creation state (Open creation) + // SELECT * FROM transaction_creations WHERE state_user_id = loginUser.id AND target_date > Date - 2 Monat + // SELECT * FROM pending_creations WHERE userId = loginUser.id + // COUNT amount from 2 tables + // if amount < 3000 => Store in pending_creations + const creations = getUserCreations(user.id) + // UserAdmin.creations() return true } } From 5f8235c7af3053a24ca0de4f4329439b20b4a1b2 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 10:42:05 +0100 Subject: [PATCH 12/87] Added last todo before sending success. --- backend/src/graphql/resolver/AdminResolver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 69a0e7c83..c595692c0 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -39,6 +39,7 @@ export class AdminResolver { // if amount < 3000 => Store in pending_creations const creations = getUserCreations(user.id) // UserAdmin.creations() + // TODO: Write pending creation to DB return true } } From cd12d621fe14a57f51601eb414292850df6fcafb Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 10:51:40 +0100 Subject: [PATCH 13/87] Methode to get user creations. --- backend/src/graphql/resolver/AdminResolver.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index c595692c0..7a0872258 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -33,13 +33,17 @@ export class AdminResolver { const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) // TODO: Check user open creation state (Open creation) - // SELECT * FROM transaction_creations WHERE state_user_id = loginUser.id AND target_date > Date - 2 Monat - // SELECT * FROM pending_creations WHERE userId = loginUser.id - // COUNT amount from 2 tables - // if amount < 3000 => Store in pending_creations const creations = getUserCreations(user.id) // UserAdmin.creations() // TODO: Write pending creation to DB return true } } + +function getUserCreations(id: number): Promise { + // SELECT * FROM transaction_creations WHERE state_user_id = loginUser.id AND target_date > Date - 2 Monat + // SELECT * FROM pending_creations WHERE userId = loginUser.id + // COUNT amount from 2 tables + // if amount < 3000 => Store in pending_creations + throw new Error('Function not implemented.') +} From e011d0a803c8af44dfd9aa06694862cf6e44d478 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:09:13 +0100 Subject: [PATCH 14/87] Implemented the arguments for graphql. --- .../src/graphql/arg/CreatePendingCreationArgs.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 backend/src/graphql/arg/CreatePendingCreationArgs.ts diff --git a/backend/src/graphql/arg/CreatePendingCreationArgs.ts b/backend/src/graphql/arg/CreatePendingCreationArgs.ts new file mode 100644 index 000000000..89b1e8c26 --- /dev/null +++ b/backend/src/graphql/arg/CreatePendingCreationArgs.ts @@ -0,0 +1,16 @@ +import { ArgsType, Field } from 'type-graphql' + +@ArgsType() +export default class CreatePendingCreationArgs { + @Field(() => String) + email: string + + @Field(() => Number) + amount: number + + @Field(() => String) + note: string + + @Field(() => Date) + creationDate: Date +} From 048d75f167c7be34ddf773ac375cfb007c755e30 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:09:53 +0100 Subject: [PATCH 15/87] Added a default random value for the last three creations. --- backend/src/graphql/resolver/AdminResolver.ts | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 7a0872258..e63cc6efe 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -3,6 +3,7 @@ import { getCustomRepository } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' import { UserRepository } from '../../typeorm/repository/User' +import { CreatePendingCreationArgs } from '../arg/CreatePendingCreationArgs' @Resolver() export class AdminResolver { @@ -15,11 +16,7 @@ export class AdminResolver { user.firstName = loginUser.firstName user.lastName = loginUser.lastName user.email = loginUser.email - user.creation = [ - (Math.floor(Math.random() * 50) + 1) * 20, - (Math.floor(Math.random() * 50) + 1) * 20, - (Math.floor(Math.random() * 50) + 1) * 20, - ] + user.creation = getUserCreations(loginUser.id) return user }) return users @@ -33,17 +30,27 @@ export class AdminResolver { const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) // TODO: Check user open creation state (Open creation) - const creations = getUserCreations(user.id) - // UserAdmin.creations() - // TODO: Write pending creation to DB - return true + const creations = await getUserCreations(user.id) + if (isCreationValid(creations, amount, creationDate)) { + // UserAdmin.creations() + // TODO: Write pending creation to DB + } + return false } } function getUserCreations(id: number): Promise { - // SELECT * FROM transaction_creations WHERE state_user_id = loginUser.id AND target_date > Date - 2 Monat - // SELECT * FROM pending_creations WHERE userId = loginUser.id + // SELECT * FROM transaction_creations WHERE state_user_id = id AND target_date > Date - 2 Monat + // SELECT * FROM pending_creations WHERE userId = id // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations - throw new Error('Function not implemented.') + return [ + (Math.floor(Math.random() * 50) + 1) * 20, + (Math.floor(Math.random() * 50) + 1) * 20, + (Math.floor(Math.random() * 50) + 1) * 20, + ] +} + +function isCreationValid(creations: number[], amount: any, creationDate: any) { + return true } From 0dcceb682edd7860fea49f1d54e6e9d0e5b1e238 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:11:48 +0100 Subject: [PATCH 16/87] add function getUserCreations --- backend/src/graphql/resolver/AdminResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index e63cc6efe..7fd6266e1 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -40,7 +40,7 @@ export class AdminResolver { } function getUserCreations(id: number): Promise { - // SELECT * FROM transaction_creations WHERE state_user_id = id AND target_date > Date - 2 Monat + // SELECT * FROM transaction_creations WHERE state_user_id = id AND target_date > Date - 2 Monate // SELECT * FROM pending_creations WHERE userId = id // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations From 4544d701fb71b93b992eee63ab49462f810ff492 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:23:21 +0100 Subject: [PATCH 17/87] Withdrew Promise --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 7fd6266e1..3536538cb 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -3,7 +3,7 @@ import { getCustomRepository } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' import { UserRepository } from '../../typeorm/repository/User' -import { CreatePendingCreationArgs } from '../arg/CreatePendingCreationArgs' +import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs' @Resolver() export class AdminResolver { @@ -39,7 +39,7 @@ export class AdminResolver { } } -function getUserCreations(id: number): Promise { +function getUserCreations(id: number): number[] { // SELECT * FROM transaction_creations WHERE state_user_id = id AND target_date > Date - 2 Monate // SELECT * FROM pending_creations WHERE userId = id // COUNT amount from 2 tables From c68386be85194ac9aff73470b61426bb80b9e0ab Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:27:22 +0100 Subject: [PATCH 18/87] Test log. --- backend/src/graphql/resolver/AdminResolver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 3536538cb..c3a311f65 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -31,6 +31,7 @@ export class AdminResolver { const user = await userRepository.findByEmail(email) // TODO: Check user open creation state (Open creation) const creations = await getUserCreations(user.id) + console.log('creations', creations) if (isCreationValid(creations, amount, creationDate)) { // UserAdmin.creations() // TODO: Write pending creation to DB From ed5baeccc0cfa9c8a51fa3473a78a4169385182e Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 11:46:12 +0100 Subject: [PATCH 19/87] Implementation of the TransactionCreationRepository. --- backend/src/graphql/resolver/AdminResolver.ts | 6 +++++- backend/src/typeorm/repository/TransactionCreation.ts | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 backend/src/typeorm/repository/TransactionCreation.ts diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index c3a311f65..2d8934ffe 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -2,6 +2,7 @@ import { Resolver, Query, Arg, Args } from 'type-graphql' import { getCustomRepository } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' +import { TransactionCreationRepository } from '../../typeorm/repository/TransactionCreation' import { UserRepository } from '../../typeorm/repository/User' import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs' @@ -41,7 +42,10 @@ export class AdminResolver { } function getUserCreations(id: number): number[] { - // SELECT * FROM transaction_creations WHERE state_user_id = id AND target_date > Date - 2 Monate + // SELECT count(amount) FROM transaction_creations WHERE state_user_id = id AND target_date > (NOW()-ActualDays - 2 Monate) + const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ + currentDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' */ }), + }) // SELECT * FROM pending_creations WHERE userId = id // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations diff --git a/backend/src/typeorm/repository/TransactionCreation.ts b/backend/src/typeorm/repository/TransactionCreation.ts new file mode 100644 index 000000000..89266838a --- /dev/null +++ b/backend/src/typeorm/repository/TransactionCreation.ts @@ -0,0 +1,5 @@ +import { EntityRepository, Repository } from 'typeorm' +import { TransactionCreation } from '@entity/TransactionCreation' + +@EntityRepository(TransactionCreation) +export class TransactionCreationRepository extends Repository {} From 367122fb1b59d18d5003d5ae11eeaa82494d3d49 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 12:08:38 +0100 Subject: [PATCH 20/87] Search db for transactions. --- backend/src/graphql/resolver/AdminResolver.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 2d8934ffe..f28fb13ab 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,5 +1,5 @@ import { Resolver, Query, Arg, Args } from 'type-graphql' -import { getCustomRepository } from 'typeorm' +import { getCustomRepository, Raw } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' import { TransactionCreationRepository } from '../../typeorm/repository/TransactionCreation' @@ -17,7 +17,7 @@ export class AdminResolver { user.firstName = loginUser.firstName user.lastName = loginUser.lastName user.email = loginUser.email - user.creation = getUserCreations(loginUser.id) + user.creation = [] // await getUserCreations(loginUser.id) return user }) return users @@ -41,11 +41,13 @@ export class AdminResolver { } } -function getUserCreations(id: number): number[] { +async function getUserCreations(id: number): Promise { // SELECT count(amount) FROM transaction_creations WHERE state_user_id = id AND target_date > (NOW()-ActualDays - 2 Monate) const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ - currentDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' */ }), + userId: id, + targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' */ }), }) + console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations From b5baa9d8830bf1d3306ceaeaf09ddf0b1b084d5b Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 24 Nov 2021 12:29:49 +0100 Subject: [PATCH 21/87] Added PendingCreationRepository and added find all pending creations. --- backend/src/graphql/resolver/AdminResolver.ts | 12 +++++++++--- backend/src/typeorm/repository/PendingCreation.ts | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 backend/src/typeorm/repository/PendingCreation.ts diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index f28fb13ab..8cdd78535 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -3,6 +3,7 @@ import { getCustomRepository, Raw } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' import { TransactionCreationRepository } from '../../typeorm/repository/TransactionCreation' +import { PendingCreationRepository } from '../../typeorm/repository/PendingCreation' import { UserRepository } from '../../typeorm/repository/User' import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs' @@ -12,7 +13,7 @@ export class AdminResolver { async searchUsers(@Arg('searchText') searchText: string): Promise { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUsers = await loginUserRepository.findBySearchCriteria(searchText) - const users = loginUsers.map((loginUser) => { + const users = gloginUsers.map((loginUser) => { const user = new UserAdmin() user.firstName = loginUser.firstName user.lastName = loginUser.lastName @@ -42,13 +43,18 @@ export class AdminResolver { } async function getUserCreations(id: number): Promise { - // SELECT count(amount) FROM transaction_creations WHERE state_user_id = id AND target_date > (NOW()-ActualDays - 2 Monate) + // TODO: NOW()-ActualDays - 2 Monate const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ userId: id, - targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' */ }), + targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), }) console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id + const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ + userId: id, + date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), + }) + console.log('pendingCreations', pendingCreations^) // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations return [ diff --git a/backend/src/typeorm/repository/PendingCreation.ts b/backend/src/typeorm/repository/PendingCreation.ts new file mode 100644 index 000000000..dbe589e37 --- /dev/null +++ b/backend/src/typeorm/repository/PendingCreation.ts @@ -0,0 +1,5 @@ +import { EntityRepository, Repository } from 'typeorm' +import { PendingCreation } from '@entity/PendingCreation' + +@EntityRepository(LoginUserBackup) +export class PendingCreationRepository extends Repository {} From 725ab91c4901b045226e5479103a4a1f5e89060b Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 12:37:28 +0100 Subject: [PATCH 22/87] Test other author. --- backend/src/typeorm/repository/PendingCreation.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/typeorm/repository/PendingCreation.ts b/backend/src/typeorm/repository/PendingCreation.ts index dbe589e37..95470a4fe 100644 --- a/backend/src/typeorm/repository/PendingCreation.ts +++ b/backend/src/typeorm/repository/PendingCreation.ts @@ -2,4 +2,6 @@ import { EntityRepository, Repository } from 'typeorm' import { PendingCreation } from '@entity/PendingCreation' @EntityRepository(LoginUserBackup) -export class PendingCreationRepository extends Repository {} +export class PendingCreationRepository extends Repository { + // TODO: git commit --author="Hannes Heine " +} \ No newline at end of file From bb5e2361d458dfab791cd29b23ecbac0fe7e3718 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:06:38 +0100 Subject: [PATCH 23/87] Withdrew test commit. --- backend/src/typeorm/repository/PendingCreation.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/typeorm/repository/PendingCreation.ts b/backend/src/typeorm/repository/PendingCreation.ts index 95470a4fe..dbe589e37 100644 --- a/backend/src/typeorm/repository/PendingCreation.ts +++ b/backend/src/typeorm/repository/PendingCreation.ts @@ -2,6 +2,4 @@ import { EntityRepository, Repository } from 'typeorm' import { PendingCreation } from '@entity/PendingCreation' @EntityRepository(LoginUserBackup) -export class PendingCreationRepository extends Repository { - // TODO: git commit --author="Hannes Heine " -} \ No newline at end of file +export class PendingCreationRepository extends Repository {} From 1a0c0907c467869ae6faf4393f3f8c85146870fe Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:09:30 +0100 Subject: [PATCH 24/87] Corrected. --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 8cdd78535..36e31c21e 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -13,7 +13,7 @@ export class AdminResolver { async searchUsers(@Arg('searchText') searchText: string): Promise { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUsers = await loginUserRepository.findBySearchCriteria(searchText) - const users = gloginUsers.map((loginUser) => { + const users = loginUsers.map((loginUser) => { const user = new UserAdmin() user.firstName = loginUser.firstName user.lastName = loginUser.lastName @@ -54,7 +54,7 @@ async function getUserCreations(id: number): Promise { userId: id, date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), }) - console.log('pendingCreations', pendingCreations^) + console.log('pendingCreations', pendingCreations) // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations return [ From 92b2dcf6b60ec446f50f60c08666dcd8149a7ace Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:10:34 +0100 Subject: [PATCH 25/87] Corrected PendingCreationRepository. --- backend/src/typeorm/repository/PendingCreation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/typeorm/repository/PendingCreation.ts b/backend/src/typeorm/repository/PendingCreation.ts index dbe589e37..6985a0526 100644 --- a/backend/src/typeorm/repository/PendingCreation.ts +++ b/backend/src/typeorm/repository/PendingCreation.ts @@ -1,5 +1,5 @@ import { EntityRepository, Repository } from 'typeorm' import { PendingCreation } from '@entity/PendingCreation' -@EntityRepository(LoginUserBackup) +@EntityRepository(PendingCreation) export class PendingCreationRepository extends Repository {} From 13b533b1e264600aee36006c4e1604f74789c005 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:11:49 +0100 Subject: [PATCH 26/87] Corrected PendingCreationRepository. --- backend/src/typeorm/repository/PendingCreation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/typeorm/repository/PendingCreation.ts b/backend/src/typeorm/repository/PendingCreation.ts index 6985a0526..8b49e7ecc 100644 --- a/backend/src/typeorm/repository/PendingCreation.ts +++ b/backend/src/typeorm/repository/PendingCreation.ts @@ -1,5 +1,5 @@ import { EntityRepository, Repository } from 'typeorm' -import { PendingCreation } from '@entity/PendingCreation' +import { LoginPendingTasksAdmin } from '@entity/LoginPendingTasksAdmin' -@EntityRepository(PendingCreation) -export class PendingCreationRepository extends Repository {} +@EntityRepository(LoginPendingTasksAdmin) +export class PendingCreationRepository extends Repository {} From 6a152a8791612a2c08ea16325f75819b2f388df0 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:31:27 +0100 Subject: [PATCH 27/87] Change query to query builder. --- backend/src/graphql/resolver/AdminResolver.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 36e31c21e..089ce870d 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -44,10 +44,14 @@ export class AdminResolver { async function getUserCreations(id: number): Promise { // TODO: NOW()-ActualDays - 2 Monate - const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ - userId: id, - targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), - }) + // const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ + // userId: id, + // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), + // }) + const transactionCreations = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder() + .select(['SUM(login_pending_tasks_admin.amount)']) + .where('login_pending_tasks_admin.userId = :id', { id }) console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ @@ -55,6 +59,12 @@ async function getUserCreations(id: number): Promise { date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), }) console.log('pendingCreations', pendingCreations) + // const createdAmountBeforeLastMonth = transactionCreations.forEach(element => { + // element.targetDate + // }) + // const createdAmountLastMonth = ... + // const createdAmountCurrentMonth = ... + // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations return [ From 76b372fb645dbbd1fd4ecaeae778c0351a1c5472 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:34:08 +0100 Subject: [PATCH 28/87] Change query to query builder. to get many --- backend/src/graphql/resolver/AdminResolver.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 089ce870d..48c6af226 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -52,6 +52,7 @@ async function getUserCreations(id: number): Promise { .createQueryBuilder() .select(['SUM(login_pending_tasks_admin.amount)']) .where('login_pending_tasks_admin.userId = :id', { id }) + .getMany() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ From 7a27bf52bf7343c9395c111f97cf23707b8ba4f2 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:35:31 +0100 Subject: [PATCH 29/87] Change query to query builder withdrew table name. --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 48c6af226..9e296d92f 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -50,8 +50,8 @@ async function getUserCreations(id: number): Promise { // }) const transactionCreations = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder() - .select(['SUM(login_pending_tasks_admin.amount)']) - .where('login_pending_tasks_admin.userId = :id', { id }) + .select(['SUM(amount)']) + .where('userId = :id', { id }) .getMany() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id From db609d1d7833bca80877373d2294e0d1f7eae5d9 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:36:42 +0100 Subject: [PATCH 30/87] Change query to query bui. --- backend/src/graphql/resolver/AdminResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9e296d92f..1cc034366 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -51,7 +51,7 @@ async function getUserCreations(id: number): Promise { const transactionCreations = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder() .select(['SUM(amount)']) - .where('userId = :id', { id }) + .where('login_pending_tasks_admin.userId = :id', { id }) .getMany() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id From cadec27c9a201137c5e8de3d2314e4811fb20719 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:38:30 +0100 Subject: [PATCH 31/87] Reintroduced table name --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 1cc034366..84d5ef7c8 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -49,8 +49,8 @@ async function getUserCreations(id: number): Promise { // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) const transactionCreations = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder() - .select(['SUM(amount)']) + .createQueryBuilder('login_pending_tasks_admin') + .select(['SUM(login_pending_tasks_admin.amount)']) .where('login_pending_tasks_admin.userId = :id', { id }) .getMany() console.log('transactionCreations', transactionCreations) From 00abbb4413b834fa3394c4624abe1decac5ce80f Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:43:01 +0100 Subject: [PATCH 32/87] Add console log of query and id --- backend/src/graphql/resolver/AdminResolver.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 84d5ef7c8..78a684000 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -48,11 +48,12 @@ async function getUserCreations(id: number): Promise { // userId: id, // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) - const transactionCreations = await getCustomRepository(TransactionCreationRepository) + const transactionCreationsQuery = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('login_pending_tasks_admin') - .select(['SUM(login_pending_tasks_admin.amount)']) + .select(['SUM(login_pending_tasks_admin.amount) as summe']) .where('login_pending_tasks_admin.userId = :id', { id }) - .getMany() + console.log('transactionCreationsQuery', transactionCreationsQuery, id) + const transactionCreations = transactionCreationsQuery.getMany() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ From 1112b538ea4d085c5dad73ce5696768b5599c05d Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:45:07 +0100 Subject: [PATCH 33/87] Addawait to get the datas --- backend/src/graphql/resolver/AdminResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 78a684000..da4d9b4fb 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -53,7 +53,7 @@ async function getUserCreations(id: number): Promise { .select(['SUM(login_pending_tasks_admin.amount) as summe']) .where('login_pending_tasks_admin.userId = :id', { id }) console.log('transactionCreationsQuery', transactionCreationsQuery, id) - const transactionCreations = transactionCreationsQuery.getMany() + const transactionCreations = await transactionCreationsQuery.getMany() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ From 16aef73adc9278184db7f4e2319a300acbb0936b Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:49:35 +0100 Subject: [PATCH 34/87] Addawait --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index da4d9b4fb..382f179c0 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -50,10 +50,10 @@ async function getUserCreations(id: number): Promise { // }) const transactionCreationsQuery = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('login_pending_tasks_admin') - .select(['SUM(login_pending_tasks_admin.amount) as summe']) + .select(['SUM(login_pending_tasks_admin.amount)', 'sum']) .where('login_pending_tasks_admin.userId = :id', { id }) console.log('transactionCreationsQuery', transactionCreationsQuery, id) - const transactionCreations = await transactionCreationsQuery.getMany() + const transactionCreations = await transactionCreationsQuery.getRawOne() console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ From 53adaf49ee6e5020eeb9ce25c45fcd2ae3871b9d Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:51:45 +0100 Subject: [PATCH 35/87] Change Query select --- backend/src/graphql/resolver/AdminResolver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 382f179c0..09b89d6cf 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -50,7 +50,7 @@ async function getUserCreations(id: number): Promise { // }) const transactionCreationsQuery = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('login_pending_tasks_admin') - .select(['SUM(login_pending_tasks_admin.amount)', 'sum']) + .select('SUM(login_pending_tasks_admin.amount)', 'sum') .where('login_pending_tasks_admin.userId = :id', { id }) console.log('transactionCreationsQuery', transactionCreationsQuery, id) const transactionCreations = await transactionCreationsQuery.getRawOne() From 7abf1e4c4400452cc3a445c491dea16897b50076 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 13:54:37 +0100 Subject: [PATCH 36/87] Add where date > 2 month --- backend/src/graphql/resolver/AdminResolver.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 09b89d6cf..5c8f60a34 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -52,6 +52,9 @@ async function getUserCreations(id: number): Promise { .createQueryBuilder('login_pending_tasks_admin') .select('SUM(login_pending_tasks_admin.amount)', 'sum') .where('login_pending_tasks_admin.userId = :id', { id }) + .andWhere({ + targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) console.log('transactionCreationsQuery', transactionCreationsQuery, id) const transactionCreations = await transactionCreationsQuery.getRawOne() console.log('transactionCreations', transactionCreations) From e825184b4d8d3b772cdcbdb83499790e4131ff53 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:09:59 +0100 Subject: [PATCH 37/87] Divide the call to get the last --- backend/src/graphql/resolver/AdminResolver.ts | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 5c8f60a34..48c87e14f 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -48,25 +48,36 @@ async function getUserCreations(id: number): Promise { // userId: id, // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) - const transactionCreationsQuery = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder('login_pending_tasks_admin') - .select('SUM(login_pending_tasks_admin.amount)', 'sum') - .where('login_pending_tasks_admin.userId = :id', { id }) - .andWhere({ - targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + const findAllUserTransactionCreations = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + const transactionCreationsBeforeLastMonthQuery = findAllUserTransactionCreations.andWhere({ + targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - console.log('transactionCreationsQuery', transactionCreationsQuery, id) - const transactionCreations = await transactionCreationsQuery.getRawOne() - console.log('transactionCreations', transactionCreations) + const createdAmountBeforeLastMonth = await transactionCreationsBeforeLastMonthQuery.getRawOne() + console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) + + const transactionCreationsLastMonthQuery = await findAllUserTransactionCreations.andWhere({ + targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + const createdAmountLastMonth = await transactionCreationsLastMonthQuery.getRawOne() + console.log('createdAmountLastMonth', createdAmountLastMonth) + + const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ + targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() + console.log('createdAmountMonth', createdAmountMonth) + // const transactionCreationsLastThreeMonth = await transactionCreationsQuery.getRawOne() + // console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ userId: id, date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), }) console.log('pendingCreations', pendingCreations) - // const createdAmountBeforeLastMonth = transactionCreations.forEach(element => { - // element.targetDate - // }) + // const createdAmountLastMonth = ... // const createdAmountCurrentMonth = ... From 735a47779f513582a12613cba7aa3abe07a02950 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:13:22 +0100 Subject: [PATCH 38/87] Prepare complete query --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 48c87e14f..d36816215 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -52,10 +52,10 @@ async function getUserCreations(id: number): Promise { .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) - const transactionCreationsBeforeLastMonthQuery = findAllUserTransactionCreations.andWhere({ + .andWhere({ targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - const createdAmountBeforeLastMonth = await transactionCreationsBeforeLastMonthQuery.getRawOne() + const createdAmountBeforeLastMonth = await findAllUserTransactionCreations.getRawOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) const transactionCreationsLastMonthQuery = await findAllUserTransactionCreations.andWhere({ From 9193eeb6a8a46cefe335e1aa68da26e1602d27dd Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:23:32 +0100 Subject: [PATCH 39/87] Change calls to have query for last three months. --- backend/src/graphql/resolver/AdminResolver.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index d36816215..9944e726c 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -48,27 +48,41 @@ async function getUserCreations(id: number): Promise { // userId: id, // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) - const findAllUserTransactionCreations = await getCustomRepository(TransactionCreationRepository) + const createdAmountBeforeLastMonth = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - const createdAmountBeforeLastMonth = await findAllUserTransactionCreations.getRawOne() + .getRawOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) - - const transactionCreationsLastMonthQuery = await findAllUserTransactionCreations.andWhere({ - targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) - }) - const createdAmountLastMonth = await transactionCreationsLastMonthQuery.getRawOne() + + const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ + targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() console.log('createdAmountLastMonth', createdAmountLastMonth) - const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ + const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() + .getRawOne() console.log('createdAmountMonth', createdAmountMonth) + + // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ + // targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + // }) + // const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() + // console.log('createdAmountMonth', createdAmountMonth) // const transactionCreationsLastThreeMonth = await transactionCreationsQuery.getRawOne() // console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id From 3ec79608650f8fd532c6364a80630309627854b4 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:29:07 +0100 Subject: [PATCH 40/87] Withdrew table name from query builder. --- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9944e726c..2e867369f 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -49,7 +49,7 @@ async function getUserCreations(id: number): Promise { // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) const createdAmountBeforeLastMonth = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder('transaction_creations') + .createQueryBuilder() .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ @@ -57,7 +57,7 @@ async function getUserCreations(id: number): Promise { }) .getRawOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) - + const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') From 6a2a4ee64922ab0545529c9df2359f0eec608d8d Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:37:42 +0100 Subject: [PATCH 41/87] Change where to >= --- backend/src/graphql/resolver/AdminResolver.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 2e867369f..9b49029e4 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -49,33 +49,33 @@ async function getUserCreations(id: number): Promise { // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) const createdAmountBeforeLastMonth = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder() + .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ - targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) .getRawOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) - + const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder('transaction_creations') - .select('SUM(transaction_creations.amount)', 'sum') - .where('transaction_creations.state_user_id = :id', { id }) - .andWhere({ - targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) - }) - .getRawOne() + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() console.log('createdAmountLastMonth', createdAmountLastMonth) const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) - .createQueryBuilder('transaction_creations') - .select('SUM(transaction_creations.amount)', 'sum') - .where('transaction_creations.state_user_id = :id', { id }) - .andWhere({ - targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) - }) - .getRawOne() + .createQueryBuilder('transaction_creations') + .select('SUM(transaction_creations.amount)', 'sum') + .where('transaction_creations.state_user_id = :id', { id }) + .andWhere({ + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() console.log('createdAmountMonth', createdAmountMonth) // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ From 3cd5ab27db6685d37ad4df98f3cefe71db0258c8 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:40:22 +0100 Subject: [PATCH 42/87] Change getRawOne to getOne. --- backend/src/graphql/resolver/AdminResolver.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9b49029e4..8e0d2b3b4 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -55,7 +55,7 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getRawOne() + .getOne() console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) @@ -65,7 +65,7 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getRawOne() + .getOne() console.log('createdAmountLastMonth', createdAmountLastMonth) const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) @@ -75,7 +75,7 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getRawOne() + .getOne() console.log('createdAmountMonth', createdAmountMonth) // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ From 91089c66682c867afe928d0913b5a2c67beff0b6 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 14:46:56 +0100 Subject: [PATCH 43/87] Change the result value to the sum value. --- backend/src/graphql/resolver/AdminResolver.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 8e0d2b3b4..377a1c8a6 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -55,8 +55,8 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getOne() - console.log('createdAmountBeforeLastMonth', createdAmountBeforeLastMonth) + .getRawOne() + console.log('createdAmountBeforeLastMonth.sum', createdAmountBeforeLastMonth.sum) const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('transaction_creations') @@ -65,8 +65,8 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getOne() - console.log('createdAmountLastMonth', createdAmountLastMonth) + .getRawOne() + console.log('createdAmountLastMonth.sum', createdAmountLastMonth.sum) const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) .createQueryBuilder('transaction_creations') @@ -75,8 +75,8 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) - .getOne() - console.log('createdAmountMonth', createdAmountMonth) + .getRawOne() + console.log('createdAmountMonth.sum', createdAmountMonth.sum) // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ // targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) From 7c0f1cfc0fb6c6e6177e2381bd0ede19b8ca8a61 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 16:04:40 +0100 Subject: [PATCH 44/87] Query Builder to get the pending creation amount of this, last and beforeLast Month --- backend/src/graphql/resolver/AdminResolver.ts | 61 ++++++++++++++----- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 377a1c8a6..92dc46ef8 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -18,7 +18,7 @@ export class AdminResolver { user.firstName = loginUser.firstName user.lastName = loginUser.lastName user.email = loginUser.email - user.creation = [] // await getUserCreations(loginUser.id) + user.creation = [10000000, 10000000, 10000000] // await getUserCreations(loginUser.id) return user }) return users @@ -48,7 +48,8 @@ async function getUserCreations(id: number): Promise { // userId: id, // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), // }) - const createdAmountBeforeLastMonth = await getCustomRepository(TransactionCreationRepository) + const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) + const createdAmountBeforeLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) @@ -56,9 +57,9 @@ async function getUserCreations(id: number): Promise { targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) .getRawOne() - console.log('createdAmountBeforeLastMonth.sum', createdAmountBeforeLastMonth.sum) + console.log('createdAmountBeforeLastMonth.sum', Number(createdAmountBeforeLastMonth.sum)) - const createdAmountLastMonth = await getCustomRepository(TransactionCreationRepository) + const createdAmountLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) @@ -66,9 +67,9 @@ async function getUserCreations(id: number): Promise { targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) .getRawOne() - console.log('createdAmountLastMonth.sum', createdAmountLastMonth.sum) + console.log('createdAmountLastMonth.sum', Number(createdAmountLastMonth.sum)) - const createdAmountMonth = await getCustomRepository(TransactionCreationRepository) + const createdAmountMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) @@ -76,7 +77,7 @@ async function getUserCreations(id: number): Promise { targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) }) .getRawOne() - console.log('createdAmountMonth.sum', createdAmountMonth.sum) + console.log('createdAmountMonth.sum', Number(createdAmountMonth.sum)) // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ // targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) @@ -86,21 +87,51 @@ async function getUserCreations(id: number): Promise { // const transactionCreationsLastThreeMonth = await transactionCreationsQuery.getRawOne() // console.log('transactionCreations', transactionCreations) // SELECT * FROM pending_creations WHERE userId = id - const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ - userId: id, - date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), - }) - console.log('pendingCreations', pendingCreations) + const pendingCreationRepository = getCustomRepository(PendingCreationRepository) + const pendingAmountMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + .select('SUM(login_pending_tasks_admin.amount)', 'sum') + .where('login_pending_tasks_admin.userId = :id', { id }) + .andWhere({ + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() + console.log('pendingAmountMounth', Number(pendingAmountMounth.sum)) + + const pendingAmountLastMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + .select('SUM(login_pending_tasks_admin.amount)', 'sum') + .where('login_pending_tasks_admin.userId = :id', { id }) + .andWhere({ + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() + console.log('pendingAmountLastMounth', Number(pendingAmountLastMounth.sum)) + + const pendingAmountBeforeLastMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + .select('SUM(login_pending_tasks_admin.amount)', 'sum') + .where('login_pending_tasks_admin.userId = :id', { id }) + .andWhere({ + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + }) + .getRawOne() + console.log('pendingAmountBeforeLastMounth', Number(pendingAmountBeforeLastMounth.sum)) + // const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ + // userId: id, + // date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), + // }) + // const createdAmountLastMonth = ... // const createdAmountCurrentMonth = ... // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations + const usedCreationBeforeLastMonth = Number(createdAmountBeforeLastMonth.sum) + Number() + const usedCreationLastMonth = Number(createdAmountLastMonth.sum) + Number() + const usedCreationMonth = Number(createdAmountMonth.sum) + Number() return [ - (Math.floor(Math.random() * 50) + 1) * 20, - (Math.floor(Math.random() * 50) + 1) * 20, - (Math.floor(Math.random() * 50) + 1) * 20, + 10000000 - usedCreationBeforeLastMonth, + 10000000 - usedCreationLastMonth, + 10000000 - usedCreationMonth, ] } From e67b724058f0e29b64a06285e1348801e15374bf Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Wed, 24 Nov 2021 16:08:01 +0100 Subject: [PATCH 45/87] Calculate the usedAmount with the pending amounts. --- backend/src/graphql/resolver/AdminResolver.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 92dc46ef8..08b0f2b48 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -125,13 +125,13 @@ async function getUserCreations(id: number): Promise { // COUNT amount from 2 tables // if amount < 3000 => Store in pending_creations - const usedCreationBeforeLastMonth = Number(createdAmountBeforeLastMonth.sum) + Number() - const usedCreationLastMonth = Number(createdAmountLastMonth.sum) + Number() - const usedCreationMonth = Number(createdAmountMonth.sum) + Number() + const usedCreationBeforeLastMonth = Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum) + const usedCreationLastMonth = Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum) + const usedCreationMonth = Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum) return [ - 10000000 - usedCreationBeforeLastMonth, - 10000000 - usedCreationLastMonth, - 10000000 - usedCreationMonth, + ( 10000000 - usedCreationBeforeLastMonth ) / 1000, + ( 10000000 - usedCreationLastMonth ) / 1000, + ( 10000000 - usedCreationMonth ) / 1000, ] } From 1d612c034eeb923ec3a35bc322509d0497b49cb1 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 08:07:48 +0100 Subject: [PATCH 46/87] add users Promis all --- backend/src/graphql/resolver/AdminResolver.ts | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 08b0f2b48..3dcb2a639 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -13,14 +13,14 @@ export class AdminResolver { async searchUsers(@Arg('searchText') searchText: string): Promise { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUsers = await loginUserRepository.findBySearchCriteria(searchText) - const users = loginUsers.map((loginUser) => { + const users = await Promise.all(loginUsers.map(async (loginUser) => { const user = new UserAdmin() user.firstName = loginUser.firstName user.lastName = loginUser.lastName user.email = loginUser.email - user.creation = [10000000, 10000000, 10000000] // await getUserCreations(loginUser.id) + user.creation = await getUserCreations(loginUser.id) return user - }) + })) return users } @@ -44,10 +44,6 @@ export class AdminResolver { async function getUserCreations(id: number): Promise { // TODO: NOW()-ActualDays - 2 Monate - // const transactionCreations = await getCustomRepository(TransactionCreationRepository).find({ - // userId: id, - // targetDate: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), - // }) const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) const createdAmountBeforeLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') @@ -58,7 +54,7 @@ async function getUserCreations(id: number): Promise { }) .getRawOne() console.log('createdAmountBeforeLastMonth.sum', Number(createdAmountBeforeLastMonth.sum)) - + const createdAmountLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') @@ -79,14 +75,6 @@ async function getUserCreations(id: number): Promise { .getRawOne() console.log('createdAmountMonth.sum', Number(createdAmountMonth.sum)) - // const transactionCreationsMonthQuery = await findAllUserTransactionCreations.andWhere({ - // targetDate: Raw((alias) => `${alias} > :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) - // }) - // const createdAmountMonth = await transactionCreationsMonthQuery.getRawOne() - // console.log('createdAmountMonth', createdAmountMonth) - // const transactionCreationsLastThreeMonth = await transactionCreationsQuery.getRawOne() - // console.log('transactionCreations', transactionCreations) - // SELECT * FROM pending_creations WHERE userId = id const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const pendingAmountMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') .select('SUM(login_pending_tasks_admin.amount)', 'sum') @@ -114,27 +102,18 @@ async function getUserCreations(id: number): Promise { }) .getRawOne() console.log('pendingAmountBeforeLastMounth', Number(pendingAmountBeforeLastMounth.sum)) - // const pendingCreations = await getCustomRepository(PendingCreationRepository).find({ - // userId: id, - // date: Raw((alias) => `${alias} > :date`, { date: "2021-09-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }), - // }) - - - // const createdAmountLastMonth = ... - // const createdAmountCurrentMonth = ... // COUNT amount from 2 tables - // if amount < 3000 => Store in pending_creations - const usedCreationBeforeLastMonth = Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum) - const usedCreationLastMonth = Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum) - const usedCreationMonth = Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum) + const usedCreationBeforeLastMonth = (Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum)) / 10000 + const usedCreationLastMonth = (Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000 + const usedCreationMonth = (Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000 return [ - ( 10000000 - usedCreationBeforeLastMonth ) / 1000, - ( 10000000 - usedCreationLastMonth ) / 1000, - ( 10000000 - usedCreationMonth ) / 1000, + 1000 - usedCreationBeforeLastMonth, + 1000 - usedCreationLastMonth, + 1000 - usedCreationMonth, ] } -function isCreationValid(creations: number[], amount: any, creationDate: any) { +function isCreationValid(creations: number[], amount: number, creationDate: any) { return true } From e399ce6e2721ff9a3b1cbda1922801f41da6e037 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 08:55:49 +0100 Subject: [PATCH 47/87] Adding moment package to backend. --- backend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/package.json b/backend/package.json index 375046363..e573a2704 100644 --- a/backend/package.json +++ b/backend/package.json @@ -29,6 +29,7 @@ "jest": "^27.2.4", "jsonwebtoken": "^8.5.1", "module-alias": "^2.2.2", + "moment": "^2.29.1", "mysql2": "^2.3.0", "nodemailer": "^6.6.5", "random-bigint": "^0.0.1", From c801d7c07c880120a4f14aa8bf90dd77421aa034 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 08:56:21 +0100 Subject: [PATCH 48/87] Adding moment package to backend in yarn lock. --- backend/yarn.lock | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/yarn.lock b/backend/yarn.lock index 5b74ba7c3..b46bc183d 100644 --- a/backend/yarn.lock +++ b/backend/yarn.lock @@ -4139,6 +4139,11 @@ module-alias@^2.2.2: resolved "https://registry.yarnpkg.com/module-alias/-/module-alias-2.2.2.tgz#151cdcecc24e25739ff0aa6e51e1c5716974c0e0" integrity sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q== +moment@^2.29.1: + version "2.29.1" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3" + integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" From 72f06ede08dea47c945c9da20ad08d32f7e6879f Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 08:57:40 +0100 Subject: [PATCH 49/87] Change the date calculation so we get the three last month and next month as string and search with this values. --- admin/src/components/CreationFormular.vue | 6 +- backend/src/graphql/resolver/AdminResolver.ts | 77 ++++++++++++++----- 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index d6b637152..09c42378c 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -163,15 +163,15 @@ export default { rangeMax: 1000, currentMonth: { short: this.$moment().format('MMMM'), - long: this.$moment().format('DD/MM/YYYY'), + long: this.$moment().format('YYYY-MM-DD'), }, lastMonth: { short: this.$moment().subtract(1, 'month').format('MMMM'), - long: this.$moment().subtract(1, 'month').format('DD/MM/YYYY'), + long: this.$moment().subtract(1, 'month').format('YYYY-MM') + '-01', }, beforeLastMonth: { short: this.$moment().subtract(2, 'month').format('MMMM'), - long: this.$moment().subtract(2, 'month').format('DD/MM/YYYY'), + long: this.$moment().subtract(2, 'month').format('YYYY-MM') + '-01', }, submitObj: null, isdisabled: true, diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 3dcb2a639..2864c06fd 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -6,6 +6,7 @@ import { TransactionCreationRepository } from '../../typeorm/repository/Transact import { PendingCreationRepository } from '../../typeorm/repository/PendingCreation' import { UserRepository } from '../../typeorm/repository/User' import CreatePendingCreationArgs from '../arg/CreatePendingCreationArgs' +import moment from 'moment' @Resolver() export class AdminResolver { @@ -13,14 +14,16 @@ export class AdminResolver { async searchUsers(@Arg('searchText') searchText: string): Promise { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUsers = await loginUserRepository.findBySearchCriteria(searchText) - const users = await Promise.all(loginUsers.map(async (loginUser) => { - const user = new UserAdmin() - user.firstName = loginUser.firstName - user.lastName = loginUser.lastName - user.email = loginUser.email - user.creation = await getUserCreations(loginUser.id) - return user - })) + const users = await Promise.all( + loginUsers.map(async (loginUser) => { + const user = new UserAdmin() + user.firstName = loginUser.firstName + user.lastName = loginUser.lastName + user.email = loginUser.email + user.creation = await getUserCreations(loginUser.id) + return user + }), + ) return users } @@ -44,13 +47,24 @@ export class AdminResolver { async function getUserCreations(id: number): Promise { // TODO: NOW()-ActualDays - 2 Monate + // const actualDate = new Date() + const dateNextMonth = moment().add(1, 'month').format('YYYY-MM') + '-01' + const dateMonth = moment().format('YYYY-MM') + '-01' + const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + '-01' + const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01' + + console.log('Searching creation amount for: ', dateNextMonth, dateMonth, dateLastMonth, dateBeforeLastMonth) + const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) const createdAmountBeforeLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ - targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: dateBeforeLastMonth, // DATE + enddate: dateLastMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() console.log('createdAmountBeforeLastMonth.sum', Number(createdAmountBeforeLastMonth.sum)) @@ -60,7 +74,10 @@ async function getUserCreations(id: number): Promise { .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ - targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: dateLastMonth, + enddate: dateMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() console.log('createdAmountLastMonth.sum', Number(createdAmountLastMonth.sum)) @@ -70,43 +87,61 @@ async function getUserCreations(id: number): Promise { .select('SUM(transaction_creations.amount)', 'sum') .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ - targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: dateMonth, + enddate: dateNextMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() console.log('createdAmountMonth.sum', Number(createdAmountMonth.sum)) const pendingCreationRepository = getCustomRepository(PendingCreationRepository) - const pendingAmountMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + const pendingAmountMounth = await pendingCreationRepository + .createQueryBuilder('login_pending_tasks_admin') .select('SUM(login_pending_tasks_admin.amount)', 'sum') .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ - date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-11-01", enddate: "2021-12-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: '2021-11-01', + enddate: '2021-12-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() console.log('pendingAmountMounth', Number(pendingAmountMounth.sum)) - const pendingAmountLastMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + const pendingAmountLastMounth = await pendingCreationRepository + .createQueryBuilder('login_pending_tasks_admin') .select('SUM(login_pending_tasks_admin.amount)', 'sum') .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ - date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-10-01", enddate: "2021-11-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: '2021-10-01', + enddate: '2021-11-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() console.log('pendingAmountLastMounth', Number(pendingAmountLastMounth.sum)) - const pendingAmountBeforeLastMounth = await pendingCreationRepository.createQueryBuilder('login_pending_tasks_admin') + const pendingAmountBeforeLastMounth = await pendingCreationRepository + .createQueryBuilder('login_pending_tasks_admin') .select('SUM(login_pending_tasks_admin.amount)', 'sum') .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ - date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: "2021-09-01", enddate: "2021-10-01" /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */ }) + date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { + date: '2021-09-01', + enddate: '2021-10-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + }), }) .getRawOne() - console.log('pendingAmountBeforeLastMounth', Number(pendingAmountBeforeLastMounth.sum)) + console.log('pendingAmountBeforeLastMounth', Number(pendingAmountBeforeLastMounth.sum)) // COUNT amount from 2 tables - const usedCreationBeforeLastMonth = (Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum)) / 10000 - const usedCreationLastMonth = (Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000 - const usedCreationMonth = (Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000 + const usedCreationBeforeLastMonth = + (Number(createdAmountBeforeLastMonth.sum) + Number(pendingAmountBeforeLastMounth.sum)) / 10000 + const usedCreationLastMonth = + (Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000 + const usedCreationMonth = + (Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000 return [ 1000 - usedCreationBeforeLastMonth, 1000 - usedCreationLastMonth, From 1c96161401c7f0153f3d03b9571ca342ad9b14e7 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 09:22:49 +0100 Subject: [PATCH 50/87] Replaced fix dates from pending queries to the calculated dates, withdrew comments. --- backend/src/graphql/resolver/AdminResolver.ts | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 2864c06fd..6a18661d8 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -46,13 +46,10 @@ export class AdminResolver { } async function getUserCreations(id: number): Promise { - // TODO: NOW()-ActualDays - 2 Monate - // const actualDate = new Date() const dateNextMonth = moment().add(1, 'month').format('YYYY-MM') + '-01' const dateMonth = moment().format('YYYY-MM') + '-01' const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + '-01' const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01' - console.log('Searching creation amount for: ', dateNextMonth, dateMonth, dateLastMonth, dateBeforeLastMonth) const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) @@ -62,8 +59,8 @@ async function getUserCreations(id: number): Promise { .where('transaction_creations.state_user_id = :id', { id }) .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { - date: dateBeforeLastMonth, // DATE - enddate: dateLastMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + date: dateBeforeLastMonth, + enddate: dateLastMonth, }), }) .getRawOne() @@ -76,7 +73,7 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: dateLastMonth, - enddate: dateMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + enddate: dateMonth, }), }) .getRawOne() @@ -89,7 +86,7 @@ async function getUserCreations(id: number): Promise { .andWhere({ targetDate: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { date: dateMonth, - enddate: dateNextMonth /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + enddate: dateNextMonth, }), }) .getRawOne() @@ -102,8 +99,8 @@ async function getUserCreations(id: number): Promise { .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { - date: '2021-11-01', - enddate: '2021-12-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + date: dateMonth, + enddate: dateNextMonth, }), }) .getRawOne() @@ -115,8 +112,8 @@ async function getUserCreations(id: number): Promise { .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { - date: '2021-10-01', - enddate: '2021-11-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + date: dateLastMonth, + enddate: dateMonth, }), }) .getRawOne() @@ -128,8 +125,8 @@ async function getUserCreations(id: number): Promise { .where('login_pending_tasks_admin.userId = :id', { id }) .andWhere({ date: Raw((alias) => `${alias} >= :date and ${alias} < :enddate`, { - date: '2021-09-01', - enddate: '2021-10-01' /* TODO: NOW().format("YYYY-MM") + '-01' - 2 Month */, + date: dateBeforeLastMonth, + enddate: dateLastMonth, }), }) .getRawOne() From 13a21b5a29e178ecb5b21d0d5c7dd37cf42db97e Mon Sep 17 00:00:00 2001 From: ogerly Date: Thu, 25 Nov 2021 09:25:20 +0100 Subject: [PATCH 51/87] add disabled radio button when creation 0 --- admin/src/components/CreationFormular.vue | 3 +++ 1 file changed, 3 insertions(+) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 09c42378c..a3dc9b58f 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -24,6 +24,7 @@ @@ -34,6 +35,7 @@ @@ -44,6 +46,7 @@ From ead93b98fdfdd7b36d89750b074acfde8205c900 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 09:54:22 +0100 Subject: [PATCH 52/87] Implemented check if creation is allowed. --- backend/src/graphql/resolver/AdminResolver.ts | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 6a18661d8..b9fc5d8f4 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -40,6 +40,7 @@ export class AdminResolver { if (isCreationValid(creations, amount, creationDate)) { // UserAdmin.creations() // TODO: Write pending creation to DB + } else { } return false } @@ -50,7 +51,13 @@ async function getUserCreations(id: number): Promise { const dateMonth = moment().format('YYYY-MM') + '-01' const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + '-01' const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01' - console.log('Searching creation amount for: ', dateNextMonth, dateMonth, dateLastMonth, dateBeforeLastMonth) + console.log( + 'Searching creation amount for: ', + dateNextMonth, + dateMonth, + dateLastMonth, + dateBeforeLastMonth, + ) const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) const createdAmountBeforeLastMonth = await transactionCreationRepository @@ -139,6 +146,9 @@ async function getUserCreations(id: number): Promise { (Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000 const usedCreationMonth = (Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000 + console.log('1000 - usedCreationBeforeLastMonth', 1000 - usedCreationBeforeLastMonth) + console.log('1000 - usedCreationLastMonth', 1000 - usedCreationLastMonth) + console.log('1000 - usedCreationMonth', 1000 - usedCreationMonth) return [ 1000 - usedCreationBeforeLastMonth, 1000 - usedCreationLastMonth, @@ -147,5 +157,29 @@ async function getUserCreations(id: number): Promise { } function isCreationValid(creations: number[], amount: number, creationDate: any) { + const dateMonth = moment().format('YYYY-MM') + const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + // moment() + const creationDateMonth = moment(creationDate).format('YYYY-MM') + console.log('CHECK: ', creationDateMonth, dateMonth, dateLastMonth, dateBeforeLastMonth) + let openCreation + switch (creationDateMonth) { + case dateMonth: + openCreation = creations[2] + break + case dateLastMonth: + openCreation = creations[1] + break + case dateBeforeLastMonth: + openCreation = creations[0] + break + default: + throw new Error('CreationDate is not in last three months') + } + console.log('creation >= amount', openCreation >= amount, openCreation, amount) + if (openCreation < amount) { + throw new Error(`Open creation (${openCreation}) is less than amount (${amount})`) + } return true } From 03cb7fa5588e254e8afd44fdb990b932487f6fb8 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 10:15:34 +0100 Subject: [PATCH 53/87] Create entry in LoginPendingTaskAdmin table. Save creation in database. --- .../src/graphql/arg/CreatePendingCreationArgs.ts | 3 +++ backend/src/graphql/resolver/AdminResolver.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/backend/src/graphql/arg/CreatePendingCreationArgs.ts b/backend/src/graphql/arg/CreatePendingCreationArgs.ts index 89b1e8c26..a263c9b07 100644 --- a/backend/src/graphql/arg/CreatePendingCreationArgs.ts +++ b/backend/src/graphql/arg/CreatePendingCreationArgs.ts @@ -13,4 +13,7 @@ export default class CreatePendingCreationArgs { @Field(() => Date) creationDate: Date + + @Field(() => Number) + moderator: number } diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index b9fc5d8f4..ad8bd813e 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -29,7 +29,7 @@ export class AdminResolver { @Query(() => Boolean) async createPendingCreation( - @Args() { email, amount, note, creationDate }: CreatePendingCreationArgs, + @Args() { email, amount, note, creationDate, moderator }: CreatePendingCreationArgs, ): Promise { // TODO: Check user validity const userRepository = getCustomRepository(UserRepository) @@ -40,7 +40,16 @@ export class AdminResolver { if (isCreationValid(creations, amount, creationDate)) { // UserAdmin.creations() // TODO: Write pending creation to DB - } else { + const pendingCreationRepository = getCustomRepository(PendingCreationRepository) + const loginPendingTaskAdmin = pendingCreationRepository.create() + loginPendingTaskAdmin.userId = user.id + loginPendingTaskAdmin.amount = BigInt(amount * 10000) + loginPendingTaskAdmin.created = new Date() + loginPendingTaskAdmin.date = new Date(creationDate) + loginPendingTaskAdmin.note = note + loginPendingTaskAdmin.moderator = moderator + + pendingCreationRepository.save(loginPendingTaskAdmin) } return false } From b8e3c9a3764ba5dd3c0c1a7e1405515572c3ee4f Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 10:18:41 +0100 Subject: [PATCH 54/87] change formular store moderation information, change SubmitObject --- admin/src/components/CreationFormular.vue | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index a3dc9b58f..babff9609 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -233,10 +233,12 @@ export default { this.submitObj = [ { item: this.itemsMassCreation, - datum: this.radioSelected, + email: this.item.email, + creationDate: this.radioSelected.long, amount: this.value, - text: this.text, - moderator: this.$store.state.moderator, + note: this.text, + moderator: this.$store.state.moderator.id, + }, ] alert('MehrfachSCHÖPFUNG ABSENDEN FÜR >> ' + i + ' Mitglieder') @@ -252,15 +254,13 @@ export default { // hinweis das eine einzelne schöpfung ausgeführt wird an (Vorname) alert('SUBMIT CREATION => ' + this.type + ' >> für ' + this.item.firstName + '') // erstellen eines Arrays (submitObj) mit allen Daten - this.submitObj = [ - { - item: this.item, - datum: this.radioSelected.long, - amount: this.value, - text: this.text, - moderator: this.$store.state.moderator, - }, - ] + this.submitObj = { + email: this.item.email, + creationDate: this.radioSelected.long, + amount: this.value, + note: this.text, + moderator: this.$store.state.moderator.id, + } if (this.pagetype === 'PageCreationConfirm') { // hinweis das eine ein einzelne Schöpfung abgesendet wird an (email) From 45b61547cc4e50506087d3a69c61ba75c4d613ed Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 10:21:30 +0100 Subject: [PATCH 55/87] change store moderation information --- admin/src/store/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/store/store.js b/admin/src/store/store.js index 754c559c8..c2ed1ca83 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -35,7 +35,7 @@ const store = new Vuex.Store({ ], state: { token: CONFIG.DEBUG_DISABLE_AUTH ? 'validToken' : null, - moderator: 'Dertest Moderator', + moderator: { name: 'Dertest Moderator', id: -1 }, openCreations: 0, }, // Syncronous mutation of the state From 4f61af06aa52e6666fec8bb28fafaadde2e9832e Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 10:22:42 +0100 Subject: [PATCH 56/87] Withdrew console.logs and changed creationDate type from any to Date. --- backend/src/graphql/resolver/AdminResolver.ts | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index ad8bd813e..9358dd0d2 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -31,15 +31,12 @@ export class AdminResolver { async createPendingCreation( @Args() { email, amount, note, creationDate, moderator }: CreatePendingCreationArgs, ): Promise { - // TODO: Check user validity const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) - // TODO: Check user open creation state (Open creation) + const creations = await getUserCreations(user.id) - console.log('creations', creations) + if (isCreationValid(creations, amount, creationDate)) { - // UserAdmin.creations() - // TODO: Write pending creation to DB const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const loginPendingTaskAdmin = pendingCreationRepository.create() loginPendingTaskAdmin.userId = user.id @@ -60,13 +57,6 @@ async function getUserCreations(id: number): Promise { const dateMonth = moment().format('YYYY-MM') + '-01' const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') + '-01' const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') + '-01' - console.log( - 'Searching creation amount for: ', - dateNextMonth, - dateMonth, - dateLastMonth, - dateBeforeLastMonth, - ) const transactionCreationRepository = getCustomRepository(TransactionCreationRepository) const createdAmountBeforeLastMonth = await transactionCreationRepository @@ -80,7 +70,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('createdAmountBeforeLastMonth.sum', Number(createdAmountBeforeLastMonth.sum)) const createdAmountLastMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') @@ -93,7 +82,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('createdAmountLastMonth.sum', Number(createdAmountLastMonth.sum)) const createdAmountMonth = await transactionCreationRepository .createQueryBuilder('transaction_creations') @@ -106,7 +94,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('createdAmountMonth.sum', Number(createdAmountMonth.sum)) const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const pendingAmountMounth = await pendingCreationRepository @@ -120,7 +107,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('pendingAmountMounth', Number(pendingAmountMounth.sum)) const pendingAmountLastMounth = await pendingCreationRepository .createQueryBuilder('login_pending_tasks_admin') @@ -133,7 +119,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('pendingAmountLastMounth', Number(pendingAmountLastMounth.sum)) const pendingAmountBeforeLastMounth = await pendingCreationRepository .createQueryBuilder('login_pending_tasks_admin') @@ -146,7 +131,6 @@ async function getUserCreations(id: number): Promise { }), }) .getRawOne() - console.log('pendingAmountBeforeLastMounth', Number(pendingAmountBeforeLastMounth.sum)) // COUNT amount from 2 tables const usedCreationBeforeLastMonth = @@ -155,9 +139,6 @@ async function getUserCreations(id: number): Promise { (Number(createdAmountLastMonth.sum) + Number(pendingAmountLastMounth.sum)) / 10000 const usedCreationMonth = (Number(createdAmountMonth.sum) + Number(pendingAmountMounth.sum)) / 10000 - console.log('1000 - usedCreationBeforeLastMonth', 1000 - usedCreationBeforeLastMonth) - console.log('1000 - usedCreationLastMonth', 1000 - usedCreationLastMonth) - console.log('1000 - usedCreationMonth', 1000 - usedCreationMonth) return [ 1000 - usedCreationBeforeLastMonth, 1000 - usedCreationLastMonth, @@ -165,13 +146,12 @@ async function getUserCreations(id: number): Promise { ] } -function isCreationValid(creations: number[], amount: number, creationDate: any) { +function isCreationValid(creations: number[], amount: number, creationDate: Date) { const dateMonth = moment().format('YYYY-MM') const dateLastMonth = moment().subtract(1, 'month').format('YYYY-MM') const dateBeforeLastMonth = moment().subtract(2, 'month').format('YYYY-MM') - // moment() const creationDateMonth = moment(creationDate).format('YYYY-MM') - console.log('CHECK: ', creationDateMonth, dateMonth, dateLastMonth, dateBeforeLastMonth) + let openCreation switch (creationDateMonth) { case dateMonth: @@ -186,7 +166,7 @@ function isCreationValid(creations: number[], amount: number, creationDate: any) default: throw new Error('CreationDate is not in last three months') } - console.log('creation >= amount', openCreation >= amount, openCreation, amount) + if (openCreation < amount) { throw new Error(`Open creation (${openCreation}) is less than amount (${amount})`) } From ade3719c33282874f3f3b0ad0ce4dca981c53a51 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 10:55:12 +0100 Subject: [PATCH 57/87] Changed the response to array of openCreations. --- backend/src/graphql/resolver/AdminResolver.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 9358dd0d2..a380390c8 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -27,10 +27,10 @@ export class AdminResolver { return users } - @Query(() => Boolean) + @Query(() => [Number]) async createPendingCreation( @Args() { email, amount, note, creationDate, moderator }: CreatePendingCreationArgs, - ): Promise { + ): Promise { const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) @@ -48,7 +48,7 @@ export class AdminResolver { pendingCreationRepository.save(loginPendingTaskAdmin) } - return false + return await getUserCreations(user.id) } } From 33c50560d681271fa03f396dc6647751a5ce3c71 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 12:06:14 +0100 Subject: [PATCH 58/87] creationDate to string and changed the other parameters to int --- backend/src/graphql/arg/CreatePendingCreationArgs.ts | 10 +++++----- backend/src/graphql/resolver/AdminResolver.ts | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/arg/CreatePendingCreationArgs.ts b/backend/src/graphql/arg/CreatePendingCreationArgs.ts index a263c9b07..ed24ed963 100644 --- a/backend/src/graphql/arg/CreatePendingCreationArgs.ts +++ b/backend/src/graphql/arg/CreatePendingCreationArgs.ts @@ -1,19 +1,19 @@ -import { ArgsType, Field } from 'type-graphql' +import { ArgsType, Field, Int } from 'type-graphql' @ArgsType() export default class CreatePendingCreationArgs { @Field(() => String) email: string - @Field(() => Number) + @Field(() => Int) amount: number @Field(() => String) note: string - @Field(() => Date) - creationDate: Date + @Field(() => String) + creationDate: string - @Field(() => Number) + @Field(() => Int) moderator: number } diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index a380390c8..d36806027 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -35,14 +35,14 @@ export class AdminResolver { const user = await userRepository.findByEmail(email) const creations = await getUserCreations(user.id) - - if (isCreationValid(creations, amount, creationDate)) { + const creationDateObj = new Date(creationDate) + if (isCreationValid(creations, amount, creationDateObj)) { const pendingCreationRepository = getCustomRepository(PendingCreationRepository) const loginPendingTaskAdmin = pendingCreationRepository.create() loginPendingTaskAdmin.userId = user.id loginPendingTaskAdmin.amount = BigInt(amount * 10000) loginPendingTaskAdmin.created = new Date() - loginPendingTaskAdmin.date = new Date(creationDate) + loginPendingTaskAdmin.date = creationDateObj loginPendingTaskAdmin.note = note loginPendingTaskAdmin.moderator = moderator From 9d168f07e7d9a88988182eff83d434484289c6f3 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 13:32:33 +0100 Subject: [PATCH 59/87] Change default id of moderator --- admin/src/store/store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/store/store.js b/admin/src/store/store.js index c2ed1ca83..140a92391 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -35,7 +35,7 @@ const store = new Vuex.Store({ ], state: { token: CONFIG.DEBUG_DISABLE_AUTH ? 'validToken' : null, - moderator: { name: 'Dertest Moderator', id: -1 }, + moderator: { name: 'Dertest Moderator', id: 0 }, openCreations: 0, }, // Syncronous mutation of the state From 90494271036e9464a00d68ff862081db6122b880 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 13:33:22 +0100 Subject: [PATCH 60/87] Added method to update user row creation --- admin/src/components/UserTable.vue | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/admin/src/components/UserTable.vue b/admin/src/components/UserTable.vue index 265c2d12e..f8718f92c 100644 --- a/admin/src/components/UserTable.vue +++ b/admin/src/components/UserTable.vue @@ -68,6 +68,7 @@ :item="row.item" :creationUserData="creationData" @update-creation-data="updateCreationData" + @update-user-data="updateUserData" /> @@ -232,6 +233,9 @@ export default { ...data, } }, + updateUserData(rowItem, newCreation) { + rowItem.creation = newCreation + }, }, } From c43b3491f0645e31992faed4ba72b99ef3832d74 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 13:34:13 +0100 Subject: [PATCH 61/87] Created new query for createPendingCreations --- admin/src/graphql/createPendingCreation.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 admin/src/graphql/createPendingCreation.js diff --git a/admin/src/graphql/createPendingCreation.js b/admin/src/graphql/createPendingCreation.js new file mode 100644 index 000000000..a6618e356 --- /dev/null +++ b/admin/src/graphql/createPendingCreation.js @@ -0,0 +1,13 @@ +import gql from 'graphql-tag' + +export const createPendingCreation = gql` + query ($email: String!, $amount: Int!, $note: String!, $creationDate: String!, $moderator: Int!) { + createPendingCreation( + email: $email + amount: $amount + note: $note + creationDate: $creationDate + moderator: $moderator + ) + } +` From 95bdbfefbe738cce7d8bf72a3b2973bfcf04ee93 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Thu, 25 Nov 2021 13:35:12 +0100 Subject: [PATCH 62/87] Implemented the apollo createPendingCreation and update rowItem.creations --- admin/src/components/CreationFormular.vue | 27 ++++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index babff9609..0cfcee217 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -128,6 +128,7 @@ + From b639da68e77371bb9ad9b7c01f017ea4d8c4bffb Mon Sep 17 00:00:00 2001 From: ogerly Date: Fri, 26 Nov 2021 10:07:16 +0100 Subject: [PATCH 74/87] Add CSS Logo img height: 2rem --- admin/src/components/NavBar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/components/NavBar.vue b/admin/src/components/NavBar.vue index 2a58b6f75..ba6bb60ca 100644 --- a/admin/src/components/NavBar.vue +++ b/admin/src/components/NavBar.vue @@ -66,6 +66,6 @@ export default { From dbdd25293ba8f45d8573bdae2e1b9e98b65bfbd4 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 29 Nov 2021 21:47:49 +0100 Subject: [PATCH 75/87] test new navbar elements, raise coverage to 52% --- .github/workflows/test.yml | 2 +- admin/src/components/NavBar.spec.js | 38 +++++++++++++++++++++++++++++ frontend/src/i18n.test.js | 12 +++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 frontend/src/i18n.test.js diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d58752e7..766f9ba3b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -441,7 +441,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 51 + min_coverage: 52 token: ${{ github.token }} ############################################################################## diff --git a/admin/src/components/NavBar.spec.js b/admin/src/components/NavBar.spec.js index 1d68b16ad..ad3ed54fd 100644 --- a/admin/src/components/NavBar.spec.js +++ b/admin/src/components/NavBar.spec.js @@ -3,11 +3,19 @@ import NavBar from './NavBar.vue' const localVue = global.localVue +const storeDispatchMock = jest.fn() +const routerPushMock = jest.fn() + const mocks = { $store: { state: { openCreations: 1, + token: 'valid-token', }, + dispatch: storeDispatchMock, + }, + $router: { + push: routerPushMock, }, } @@ -27,4 +35,34 @@ describe('NavBar', () => { expect(wrapper.find('.component-nabvar').exists()).toBeTruthy() }) }) + + describe('wallet', () => { + const assignLocationSpy = jest.fn() + beforeEach(async () => { + await wrapper.findAll('a').at(5).trigger('click') + }) + + it.skip('changes widnow location to wallet', () => { + expect(assignLocationSpy).toBeCalledWith('valid-token') + }) + + it('dispatches logout to store', () => { + expect(storeDispatchMock).toBeCalledWith('logout') + }) + }) + + describe('logout', () => { + // const assignLocationSpy = jest.fn() + beforeEach(async () => { + await wrapper.findAll('a').at(6).trigger('click') + }) + + it('redirects to /logout', () => { + expect(routerPushMock).toBeCalledWith('/logout') + }) + + it('dispatches logout to store', () => { + expect(storeDispatchMock).toBeCalledWith('logout') + }) + }) }) diff --git a/frontend/src/i18n.test.js b/frontend/src/i18n.test.js new file mode 100644 index 000000000..7ef417cbd --- /dev/null +++ b/frontend/src/i18n.test.js @@ -0,0 +1,12 @@ +import i18n from './i18n' +import VueI18n from 'vue-i18n' + +jest.mock('vue-i18n') + +console.log(require) + +describe('i18n', () => { + it('does something', () => { + expect(true).toBeTruthy() + }) +}) From 0c74fa2970a8cbf5ba51110d353080ea015b2dd5 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Mon, 29 Nov 2021 21:57:10 +0100 Subject: [PATCH 76/87] remove broken test --- frontend/src/i18n.test.js | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 frontend/src/i18n.test.js diff --git a/frontend/src/i18n.test.js b/frontend/src/i18n.test.js deleted file mode 100644 index 7ef417cbd..000000000 --- a/frontend/src/i18n.test.js +++ /dev/null @@ -1,12 +0,0 @@ -import i18n from './i18n' -import VueI18n from 'vue-i18n' - -jest.mock('vue-i18n') - -console.log(require) - -describe('i18n', () => { - it('does something', () => { - expect(true).toBeTruthy() - }) -}) From 1b485899330b8acfa2523b4c8784167a935280f2 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 08:51:47 +0100 Subject: [PATCH 77/87] Change backend coverage to 39. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 766f9ba3b..66fc1c9f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -491,7 +491,7 @@ jobs: report_name: Coverage Backend type: lcov result_path: ./backend/coverage/lcov.info - min_coverage: 37 + min_coverage: 39 token: ${{ github.token }} ############################################################################## From 84be6ae3692818e6edd1af8a1c4b75c1e0569ecc Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 09:35:33 +0100 Subject: [PATCH 78/87] Remove empty and unused file. --- admin/src/graphql/getUsersQuery.ts | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 admin/src/graphql/getUsersQuery.ts diff --git a/admin/src/graphql/getUsersQuery.ts b/admin/src/graphql/getUsersQuery.ts deleted file mode 100644 index e69de29bb..000000000 From bdad4197a3a7babcf985f7a08597f1b30941bd14 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Tue, 30 Nov 2021 09:41:44 +0100 Subject: [PATCH 79/87] fix logo import Co-authored-by: Moriz Wahl --- admin/src/components/NavBar.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/components/NavBar.vue b/admin/src/components/NavBar.vue index ba6bb60ca..a5ee41697 100644 --- a/admin/src/components/NavBar.vue +++ b/admin/src/components/NavBar.vue @@ -2,7 +2,7 @@
- ... + ... From 718763a884d671bf73ebfecf1551adeea5b17141 Mon Sep 17 00:00:00 2001 From: Hannes Heine Date: Tue, 30 Nov 2021 09:42:09 +0100 Subject: [PATCH 80/87] Update admin/src/components/CreationFormular.vue Co-authored-by: Moriz Wahl --- admin/src/components/CreationFormular.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 49e10e7bb..2a31afc6e 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -54,7 +54,7 @@ - +
From fd54f34855e3a2732eda81ae6a42c8a440cf19e3 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 09:55:27 +0100 Subject: [PATCH 81/87] Remove comment in logout. --- admin/src/components/NavBar.vue | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/admin/src/components/NavBar.vue b/admin/src/components/NavBar.vue index a5ee41697..208a6fa70 100644 --- a/admin/src/components/NavBar.vue +++ b/admin/src/components/NavBar.vue @@ -32,28 +32,8 @@ import CONFIG from '../config' export default { name: 'navbar', - data() { - return { - logo: 'img/brand/green.png', - } - }, methods: { logout() { - // TODO - // this.$emit('logout') - /* this.$apollo - .query({ - query: logout, - }) - .then(() => { - this.$store.dispatch('logout') - this.$router.push('/logout') - }) - .catch(() => { - this.$store.dispatch('logout') - if (this.$router.currentRoute.path !== '/logout') this.$router.push('/logout') - }) - */ this.$store.dispatch('logout') this.$router.push('/logout') }, From e2743b979ef1dd0500284c492e4997a053c0bcec Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 10:08:12 +0100 Subject: [PATCH 82/87] Change note to memo. --- admin/src/components/CreationFormular.vue | 4 ++-- backend/src/graphql/arg/CreatePendingCreationArgs.ts | 2 +- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- database/migrations/0005-admin_tables.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 2a31afc6e..2f7d68c4c 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -237,7 +237,7 @@ export default { email: this.item.email, creationDate: this.radioSelected.long, amount: this.value, - note: this.text, + memo: this.text, moderator: this.$store.state.moderator.id, }, ] @@ -255,7 +255,7 @@ export default { email: this.item.email, creationDate: this.radioSelected.long, amount: Number(this.value), - note: this.text, + memo: this.text, moderator: Number(this.$store.state.moderator.id), } diff --git a/backend/src/graphql/arg/CreatePendingCreationArgs.ts b/backend/src/graphql/arg/CreatePendingCreationArgs.ts index ed24ed963..d2c17abf1 100644 --- a/backend/src/graphql/arg/CreatePendingCreationArgs.ts +++ b/backend/src/graphql/arg/CreatePendingCreationArgs.ts @@ -9,7 +9,7 @@ export default class CreatePendingCreationArgs { amount: number @Field(() => String) - note: string + memo: string @Field(() => String) creationDate: string diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index f08b1a4dc..4c9cb33f8 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -31,7 +31,7 @@ export class AdminResolver { @Query(() => [Number]) async createPendingCreation( - @Args() { email, amount, note, creationDate, moderator }: CreatePendingCreationArgs, + @Args() { email, amount, memo, creationDate, moderator }: CreatePendingCreationArgs, ): Promise { const userRepository = getCustomRepository(UserRepository) const user = await userRepository.findByEmail(email) @@ -45,7 +45,7 @@ export class AdminResolver { loginPendingTaskAdmin.amount = BigInt(amount * 10000) loginPendingTaskAdmin.created = new Date() loginPendingTaskAdmin.date = creationDateObj - loginPendingTaskAdmin.note = note + loginPendingTaskAdmin.memo = memo loginPendingTaskAdmin.moderator = moderator pendingCreationRepository.save(loginPendingTaskAdmin) diff --git a/database/migrations/0005-admin_tables.ts b/database/migrations/0005-admin_tables.ts index 8e1219715..6398b22fc 100644 --- a/database/migrations/0005-admin_tables.ts +++ b/database/migrations/0005-admin_tables.ts @@ -16,7 +16,7 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis \`userId\` int UNSIGNED DEFAULT 0, \`created\` datetime NOT NULL, \`date\` datetime NOT NULL, - \`note\` text DEFAULT NULL, + \`memo\` text DEFAULT NULL, \`amount\` bigint(20) NOT NULL, \`moderator\` int UNSIGNED DEFAULT 0, PRIMARY KEY (\`id\`) From e47a95cd4bd8b652e053125a15b512ca0598fe00 Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 10:31:43 +0100 Subject: [PATCH 83/87] Change note to memo in database. --- database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts index 8e5d57d3a..26b92f43b 100644 --- a/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts +++ b/database/entity/0005-admin_tables/LoginPendingTasksAdmin.ts @@ -15,7 +15,7 @@ export class LoginPendingTasksAdmin extends BaseEntity { date: Date @Column({ length: 256, nullable: true, default: null }) - note: string + memo: string @Column({ type: 'bigint', nullable: false }) amount: BigInt From daeb0ed32c3f0c536a9e5750075ab6119af4ccfc Mon Sep 17 00:00:00 2001 From: elweyn Date: Tue, 30 Nov 2021 14:58:47 +0100 Subject: [PATCH 84/87] Change create method from query to mutation. --- admin/src/components/CreationFormular.vue | 4 ++-- admin/src/graphql/createPendingCreation.js | 10 ++++++++-- backend/src/graphql/resolver/AdminResolver.ts | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 2f7d68c4c..5d29c6fcb 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -270,8 +270,8 @@ export default { }) } else { this.$apollo - .query({ - query: createPendingCreation, + .mutate({ + mutation: createPendingCreation, variables: this.submitObj, }) .then((result) => { diff --git a/admin/src/graphql/createPendingCreation.js b/admin/src/graphql/createPendingCreation.js index a6618e356..72c3249de 100644 --- a/admin/src/graphql/createPendingCreation.js +++ b/admin/src/graphql/createPendingCreation.js @@ -1,11 +1,17 @@ import gql from 'graphql-tag' export const createPendingCreation = gql` - query ($email: String!, $amount: Int!, $note: String!, $creationDate: String!, $moderator: Int!) { + mutation ( + $email: String! + $amount: Int! + $memo: String! + $creationDate: String! + $moderator: Int! + ) { createPendingCreation( email: $email amount: $amount - note: $note + memo: $memo creationDate: $creationDate moderator: $moderator ) diff --git a/backend/src/graphql/resolver/AdminResolver.ts b/backend/src/graphql/resolver/AdminResolver.ts index 4c9cb33f8..f3c9d1516 100644 --- a/backend/src/graphql/resolver/AdminResolver.ts +++ b/backend/src/graphql/resolver/AdminResolver.ts @@ -1,4 +1,4 @@ -import { Resolver, Query, Arg, Args, Authorized } from 'type-graphql' +import { Resolver, Query, Arg, Args, Authorized, Mutation } from 'type-graphql' import { getCustomRepository, Raw } from 'typeorm' import { UserAdmin } from '../model/UserAdmin' import { LoginUserRepository } from '../../typeorm/repository/LoginUser' @@ -29,7 +29,7 @@ export class AdminResolver { return users } - @Query(() => [Number]) + @Mutation(() => [Number]) async createPendingCreation( @Args() { email, amount, memo, creationDate, moderator }: CreatePendingCreationArgs, ): Promise { From 0e592fd353c435b5194857a0b02baae8258ebcc2 Mon Sep 17 00:00:00 2001 From: elweyn Date: Wed, 1 Dec 2021 09:22:08 +0100 Subject: [PATCH 85/87] Added some tests and reduce coverage since we removed comments. --- .github/workflows/test.yml | 2 +- admin/src/main.test.js | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 66fc1c9f5..acff97d0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -441,7 +441,7 @@ jobs: report_name: Coverage Admin Interface type: lcov result_path: ./coverage/lcov.info - min_coverage: 52 + min_coverage: 50 token: ${{ github.token }} ############################################################################## diff --git a/admin/src/main.test.js b/admin/src/main.test.js index c639593d6..bf3df3799 100644 --- a/admin/src/main.test.js +++ b/admin/src/main.test.js @@ -3,12 +3,14 @@ import './main' import CONFIG from './config' import Vue from 'vue' +import VueApollo from 'vue-apollo' import Vuex from 'vuex' import VueI18n from 'vue-i18n' import { BootstrapVue, IconsPlugin } from 'bootstrap-vue' import moment from 'vue-moment' jest.mock('vue') +jest.mock('vue-apollo') jest.mock('vuex') jest.mock('vue-i18n') jest.mock('vue-moment') @@ -55,6 +57,10 @@ describe('main', () => { expect(InMemoryCache).toBeCalled() }) + it('calls the VueApollo', () => { + expect(VueApollo).toBeCalled() + }) + it('calls Vue', () => { expect(Vue).toBeCalled() }) @@ -63,16 +69,16 @@ describe('main', () => { expect(VueI18n).toBeCalled() }) - it.skip('calls BootstrapVue', () => { - expect(BootstrapVue).toBeCalled() + it('calls BootstrapVue', () => { + expect(Vue.use).toBeCalledWith(BootstrapVue) }) - it.skip('calls IconsPlugin', () => { - expect(IconsPlugin).toBeCalled() + it('calls IconsPlugin', () => { + expect(Vue.use).toBeCalledWith(IconsPlugin) }) - it.skip('calls Moment', () => { - expect(moment).toBeCalled() + it('calls Moment', () => { + expect(Vue.use).toBeCalledWith(moment) }) it.skip('creates a store', () => { From 1004718892cea46a415385971099d2924d164c38 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 2 Dec 2021 06:30:41 +0100 Subject: [PATCH 86/87] Added moderator query to the creationFormular so we can send the right moderator id. --- admin/src/components/CreationFormular.vue | 14 ++++++++++++++ admin/src/graphql/verifyLogin.js | 11 +++++++++++ admin/src/store/store.js | 3 +++ backend/src/graphql/model/User.ts | 4 ++++ backend/src/graphql/resolver/UserResolver.ts | 2 ++ 5 files changed, 34 insertions(+) create mode 100644 admin/src/graphql/verifyLogin.js diff --git a/admin/src/components/CreationFormular.vue b/admin/src/components/CreationFormular.vue index 5d29c6fcb..b6a12433e 100644 --- a/admin/src/components/CreationFormular.vue +++ b/admin/src/components/CreationFormular.vue @@ -126,6 +126,7 @@
diff --git a/admin/src/graphql/verifyLogin.js b/admin/src/graphql/verifyLogin.js new file mode 100644 index 000000000..59f5e7eb1 --- /dev/null +++ b/admin/src/graphql/verifyLogin.js @@ -0,0 +1,11 @@ +import gql from 'graphql-tag' + +export const verifyLogin = gql` + query { + verifyLogin { + firstName + lastName + id + } + } +` diff --git a/admin/src/store/store.js b/admin/src/store/store.js index 140a92391..d67537499 100644 --- a/admin/src/store/store.js +++ b/admin/src/store/store.js @@ -18,6 +18,9 @@ export const mutations = { token: (state, token) => { state.token = token }, + moderator: (state, moderator) => { + state.moderator = moderator + }, } export const actions = { diff --git a/backend/src/graphql/model/User.ts b/backend/src/graphql/model/User.ts index cdb46c954..c7b5806ca 100644 --- a/backend/src/graphql/model/User.ts +++ b/backend/src/graphql/model/User.ts @@ -12,6 +12,7 @@ export class User { */ constructor(json?: any) { if (json) { + this.id = json.id this.email = json.email this.firstName = json.first_name this.lastName = json.last_name @@ -24,6 +25,9 @@ export class User { } } + @Field(() => Number) + id: number + @Field(() => String) email: string diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 7f5f7dc43..ce403ac0e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -207,6 +207,7 @@ export class UserResolver { const loginUserRepository = getCustomRepository(LoginUserRepository) const loginUser = await loginUserRepository.findByEmail(userEntity.email) const user = new User() + user.id = userEntity.id user.email = userEntity.email user.firstName = userEntity.firstName user.lastName = userEntity.lastName @@ -276,6 +277,7 @@ export class UserResolver { } const user = new User() + user.id = userEntity.id user.email = email user.firstName = loginUser.firstName user.lastName = loginUser.lastName From 4e1baeae2e50f4d723854e4a87938aafaedf6812 Mon Sep 17 00:00:00 2001 From: elweyn Date: Thu, 2 Dec 2021 07:06:38 +0100 Subject: [PATCH 87/87] Test the apollo query for verifyLogin so we get the moderator before an creation. --- admin/src/components/CreationFormular.spec.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/admin/src/components/CreationFormular.spec.js b/admin/src/components/CreationFormular.spec.js index fcdf97cfa..e1bbff1cc 100644 --- a/admin/src/components/CreationFormular.spec.js +++ b/admin/src/components/CreationFormular.spec.js @@ -3,6 +3,16 @@ import CreationFormular from './CreationFormular.vue' const localVue = global.localVue +const apolloMock = jest.fn().mockResolvedValue({ + data: { + verifyLogin: { + name: 'success', + id: 0, + }, + }, +}) +const stateCommitMock = jest.fn() + const mocks = { $moment: jest.fn(() => { return { @@ -14,6 +24,12 @@ const mocks = { }), } }), + $apollo: { + query: apolloMock, + }, + $store: { + commit: stateCommitMock, + }, } const propsData = { @@ -39,6 +55,23 @@ describe('CreationFormular', () => { expect(wrapper.find('.component-creation-formular').exists()).toBeTruthy() }) + describe('server sends back moderator data', () => { + it('called store commit with mocked data', () => { + expect(stateCommitMock).toBeCalledWith('moderator', { name: 'success', id: 0 }) + }) + }) + + describe('server throws error for moderator data call', () => { + beforeEach(() => { + jest.clearAllMocks() + apolloMock.mockRejectedValue({ message: 'Ouch!' }) + wrapper = Wrapper() + }) + it('has called store commit with fake data', () => { + expect(stateCommitMock).toBeCalledWith('moderator', { id: 0, name: 'Test Moderator' }) + }) + }) + describe('radio buttons to selcet month', () => { it('has three radio buttons', () => { expect(wrapper.findAll('input[type="radio"]').length).toBe(3)