From a2cfd0ceafc628935398f235a0e35ccd1da30762 Mon Sep 17 00:00:00 2001 From: Nikolai R Kristiansen Date: Wed, 2 Feb 2022 23:06:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Start=20log=20view=20with=20orders?= =?UTF-8?q?=20&=20transactions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/Routes.tsx | 2 + frontend/src/features/log/Log.module.css | 5 ++ frontend/src/features/log/Log.tsx | 73 +++++++++++++++++++ frontend/src/features/log/orderList.graphql | 28 +++++++ .../src/features/log/transactionList.graphql | 16 ++++ frontend/src/types.ts | 35 +++++++++ main/api/schema.py | 4 +- schema.graphql | 7 ++ 8 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 frontend/src/features/log/Log.module.css create mode 100644 frontend/src/features/log/Log.tsx create mode 100644 frontend/src/features/log/orderList.graphql create mode 100644 frontend/src/features/log/transactionList.graphql diff --git a/frontend/src/Routes.tsx b/frontend/src/Routes.tsx index d458eff..d63b928 100644 --- a/frontend/src/Routes.tsx +++ b/frontend/src/Routes.tsx @@ -2,11 +2,13 @@ import React from "react"; import { Route, Switch } from "react-router-dom"; import { Deposit } from "./features/deposit/Deposit"; +import { Log } from "./features/log/Log"; import { Register } from "./features/register/Register"; export const Routes: React.FC = () => ( + ); diff --git a/frontend/src/features/log/Log.module.css b/frontend/src/features/log/Log.module.css new file mode 100644 index 0000000..318891a --- /dev/null +++ b/frontend/src/features/log/Log.module.css @@ -0,0 +1,5 @@ +.log { + display: grid; + grid-template-columns: repeat(2, 1fr); + gap: 1rem; +} diff --git a/frontend/src/features/log/Log.tsx b/frontend/src/features/log/Log.tsx new file mode 100644 index 0000000..c53f254 --- /dev/null +++ b/frontend/src/features/log/Log.tsx @@ -0,0 +1,73 @@ +import { useQuery } from "@apollo/client"; +import React from "react"; + +import { Order, OrderLine, OrderListDocument, Transaction, TransactionListDocument } from "../../types"; +import styles from "./Log.module.css"; + +export const Log = () => { + const { data: ordersData, loading: ordersLoading } = useQuery(OrderListDocument); + const { data: transactionsData, loading: transactionsLoading } = useQuery(TransactionListDocument); + const loading = ordersLoading || transactionsLoading; + + if (loading) return
Loading...
; + + const { orderList: orders } = ordersData; + const { transactionList: transactions } = transactionsData; + + return ( +
+
+

Ordre

+ + + + + + + + + + + {orders.map((order: Order) => ( + + + + + + + ))} + +
NårHvemHvaSum
{order.created}{order.isExternal ? "Ekstern" : `${order.customer?.firstName} ${order.customer?.lastName}`} + {(order.orderlines ?? []).map((line: OrderLine) => ( +
+ {line.amount}x {line.product.name} +
+ ))} +
{order.orderSum}
+
+
+

Transaksjoner

+ + + + + + + + + + {transactions.map((trans: Transaction) => ( + + + + + + ))} + +
NårHvemInnskudd
{trans.created} + {trans.user.firstName} {trans.user.lastName} + {trans.amount}
+
+
+ ); +}; diff --git a/frontend/src/features/log/orderList.graphql b/frontend/src/features/log/orderList.graphql new file mode 100644 index 0000000..fecc953 --- /dev/null +++ b/frontend/src/features/log/orderList.graphql @@ -0,0 +1,28 @@ +query orderList($limit: Int = 10, $offset: Int = 0) { + orderList(pagination: {limit: $limit, offset: $offset}) { + id + isExternal + created + orderSum + customer { + id + firstName + lastName + profile { + id + balance + } + } + orderlines { + id + amount + unitPrice + product { + id + name + salePriceExt + salePriceInt + } + } + } +} diff --git a/frontend/src/features/log/transactionList.graphql b/frontend/src/features/log/transactionList.graphql new file mode 100644 index 0000000..178f85e --- /dev/null +++ b/frontend/src/features/log/transactionList.graphql @@ -0,0 +1,16 @@ +query transactionList($limit: Int = 10, $offset: Int = 0) { + transactionList(pagination: {limit: $limit, offset: $offset}) { + id + created + amount + user { + id + firstName + lastName + profile { + id + balance + } + } + } +} \ No newline at end of file diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 387898b..72505fc 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -81,6 +81,11 @@ export type MutationCreateOrderArgs = { orderLines: Array; }; +export type OffsetPaginationInput = { + limit?: Scalars['Int']; + offset?: Scalars['Int']; +}; + export type Order = { __typename?: 'Order'; created: Scalars['DateTime']; @@ -124,6 +129,8 @@ export type Query = { allOrders: Array; allProducts: Array; allUsers: Array; + orderList: Array; + transactionList: Array; }; @@ -131,6 +138,16 @@ export type QueryAllProductsArgs = { filters?: Maybe; }; + +export type QueryOrderListArgs = { + pagination?: Maybe; +}; + + +export type QueryTransactionListArgs = { + pagination?: Maybe; +}; + export type Transaction = { __typename?: 'Transaction'; amount: Scalars['Float']; @@ -163,6 +180,22 @@ export type CreateDepositMutationVariables = Exact<{ export type CreateDepositMutation = { __typename?: 'Mutation', createDeposit: { __typename?: 'AboveMaxSaldo', error: boolean, message: string, maxSaldo: number, above: number } | { __typename?: 'CreateDepositSuccess', transaction: { __typename?: 'Transaction', id: string, amount: number, user: { __typename?: 'User', id: string, firstName: string, lastName: string, profile?: { __typename?: 'UserProfile', id: string, balance: number } | null | undefined } } } | { __typename?: 'FormErrors', error: boolean, message: string, fields: Array<{ __typename?: 'FieldError', field: string, message: string }> } }; +export type OrderListQueryVariables = Exact<{ + limit?: Maybe; + offset?: Maybe; +}>; + + +export type OrderListQuery = { __typename?: 'Query', orderList: Array<{ __typename?: 'Order', id: string, isExternal: boolean, created: any, orderSum: number, customer?: { __typename?: 'User', id: string, firstName: string, lastName: string, profile?: { __typename?: 'UserProfile', id: string, balance: number } | null | undefined } | null | undefined, orderlines?: Array<{ __typename?: 'OrderLine', id: string, amount: number, unitPrice: number, product: { __typename?: 'Product', id: string, name: string, salePriceExt: number, salePriceInt: number } }> | null | undefined }> }; + +export type TransactionListQueryVariables = Exact<{ + limit?: Maybe; + offset?: Maybe; +}>; + + +export type TransactionListQuery = { __typename?: 'Query', transactionList: Array<{ __typename?: 'Transaction', id: string, created: any, amount: number, user: { __typename?: 'User', id: string, firstName: string, lastName: string, profile?: { __typename?: 'UserProfile', id: string, balance: number } | null | undefined } }> }; + export type AllProductsQueryVariables = Exact<{ active: Scalars['Boolean']; }>; @@ -186,6 +219,8 @@ export type CreateOrderMutation = { __typename?: 'Mutation', createOrder: { __ty export const CreateDepositDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateDeposit"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"userId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"amount"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createDeposit"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"userId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"userId"}}},{"kind":"Argument","name":{"kind":"Name","value":"amount"},"value":{"kind":"Variable","name":{"kind":"Name","value":"amount"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CreateDepositSuccess"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transaction"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"profile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}}]}}]}}]}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AboveMaxSaldo"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"maxSaldo"}},{"kind":"Field","name":{"kind":"Name","value":"above"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"FormErrors"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const OrderListDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"orderList"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"limit"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}},"defaultValue":{"kind":"IntValue","value":"10"}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"offset"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}},"defaultValue":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"orderList"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pagination"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"limit"},"value":{"kind":"Variable","name":{"kind":"Name","value":"limit"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"offset"},"value":{"kind":"Variable","name":{"kind":"Name","value":"offset"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isExternal"}},{"kind":"Field","name":{"kind":"Name","value":"created"}},{"kind":"Field","name":{"kind":"Name","value":"orderSum"}},{"kind":"Field","name":{"kind":"Name","value":"customer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"profile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"orderlines"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"unitPrice"}},{"kind":"Field","name":{"kind":"Name","value":"product"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceExt"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceInt"}}]}}]}}]}}]}}]} as unknown as DocumentNode; +export const TransactionListDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"transactionList"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"limit"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}},"defaultValue":{"kind":"IntValue","value":"10"}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"offset"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"Int"}},"defaultValue":{"kind":"IntValue","value":"0"}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"transactionList"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"pagination"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"limit"},"value":{"kind":"Variable","name":{"kind":"Name","value":"limit"}}},{"kind":"ObjectField","name":{"kind":"Name","value":"offset"},"value":{"kind":"Variable","name":{"kind":"Name","value":"offset"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"created"}},{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"user"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"profile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const AllProductsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"allProducts"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"active"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allProducts"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"filters"},"value":{"kind":"ObjectValue","fields":[{"kind":"ObjectField","name":{"kind":"Name","value":"active"},"value":{"kind":"Variable","name":{"kind":"Name","value":"active"}}}]}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"imageUrl"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceExt"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceInt"}}]}}]}}]} as unknown as DocumentNode; export const AllUsersDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"allUsers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"allUsers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"profile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}},{"kind":"Field","name":{"kind":"Name","value":"image"}},{"kind":"Field","name":{"kind":"Name","value":"lastPurchaseDate"}}]}}]}}]}}]} as unknown as DocumentNode; export const CreateOrderDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateOrder"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"customerId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"ID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"orderLines"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"OrderLineInput"}}}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"isExternal"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"Boolean"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createOrder"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"customerId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"customerId"}}},{"kind":"Argument","name":{"kind":"Name","value":"orderLines"},"value":{"kind":"Variable","name":{"kind":"Name","value":"orderLines"}}},{"kind":"Argument","name":{"kind":"Name","value":"isExternal"},"value":{"kind":"Variable","name":{"kind":"Name","value":"isExternal"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"CreateOrderSuccess"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"order"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isExternal"}},{"kind":"Field","name":{"kind":"Name","value":"customer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"profile"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"balance"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"orderlines"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"unitPrice"}},{"kind":"Field","name":{"kind":"Name","value":"product"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceExt"}},{"kind":"Field","name":{"kind":"Name","value":"salePriceInt"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"orderSum"}}]}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"InsufficientFunds"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"amountLacking"}}]}},{"kind":"InlineFragment","typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"FormErrors"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"error"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"fields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"field"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]}}]} as unknown as DocumentNode; \ No newline at end of file diff --git a/main/api/schema.py b/main/api/schema.py index b25b750..c6de3dd 100644 --- a/main/api/schema.py +++ b/main/api/schema.py @@ -2,7 +2,7 @@ import strawberry import strawberry_django from main.api import mutations -from main.api.types import Order, Product, User +from main.api.types import Order, Product, User, Transaction @strawberry.type @@ -10,6 +10,8 @@ class Query: all_products: list[Product] = strawberry_django.field() all_users: list[User] = strawberry_django.field() all_orders: list[Order] = strawberry_django.field() + order_list: list[Order] = strawberry_django.field(pagination=True) + transaction_list: list[Transaction] = strawberry_django.field(pagination=True) @strawberry.type diff --git a/schema.graphql b/schema.graphql index d53172f..305c0e0 100644 --- a/schema.graphql +++ b/schema.graphql @@ -48,6 +48,11 @@ type Mutation { createDeposit(userId: ID!, amount: Int!): CreateDepositResponse! } +input OffsetPaginationInput { + offset: Int! = 0 + limit: Int! = -1 +} + type Order { id: ID! customer: User @@ -87,6 +92,8 @@ type Query { allProducts(filters: ProductFilter): [Product!]! allUsers: [User!]! allOrders: [Order!]! + orderList(pagination: OffsetPaginationInput): [Order!]! + transactionList(pagination: OffsetPaginationInput): [Transaction!]! } type Transaction {