api partially wired up

main
Elijah Lucian 3 years ago
parent c66e815810
commit 51dc7ef3a2
  1. 20191
      frontend/package-lock.json
  2. 2
      frontend/src/App.tsx
  3. 2
      frontend/src/api/data/users.ts
  4. 52
      frontend/src/api/index.ts
  5. 12
      frontend/src/index.css
  6. 33
      frontend/src/types/index.ts

File diff suppressed because it is too large Load Diff

@ -8,7 +8,7 @@ import { users } from './api/data/users'
import './scss/app.scss'
const App = () => {
const api = new Api({ mock: true, users })
const api = new Api({ mock: true, users, baseURL: '/api' })
return (
<BrowserRouter>

@ -4,7 +4,7 @@ import { User } from '../../types'
const userRecords: User[] = [
{
id: '42',
username: 'TestUser42',
name: 'TestUser42',
email: 'testuser@email.com',
},
]

@ -1,22 +1,25 @@
import Axios, { AxiosInstance } from 'axios'
import { User } from '../types'
import { Stack, Transaction, User, uuid } from '../types'
import { JWT, setJWT, wipeJWT } from '../utils/jwt'
import { DataBuddy } from '@dank-inc/data-buddy'
import { users } from './data/users'
export type ApiParams = {
baseURL?: string
mock?: boolean
users: DataBuddy<User>
}
export interface Api {
mock?: boolean
users: DataBuddy<User>
accounts: DataBuddy<Account>
stacks: DataBuddy<Stack>
Transactions: DataBuddy<Transaction>
axios: AxiosInstance
}
export class Api {
constructor({ mock, users, baseURL }: ApiParams) {
constructor({ mock, baseURL }: ApiParams) {
this.mock = mock
this.users = users
this.axios = Axios.create({ baseURL })
@ -44,14 +47,53 @@ export class Api {
wipeJWT()
}
getUser = async (id: string) => {
getUser = async (id: uuid) => {
if (this.mock) return this.users.getOne(id)
const { data } = await this.axios.get<User>(`users/${id}`)
return data
}
getAccounts = async () => {
this.axios.get('accounts')
}
getAccount = async (id: uuid) => {
this.axios.get(`accounts/${id}`)
}
updateAccount = async (id: uuid, body: Partial<Account>) => {
const { data } = await this.axios.patch<Account>(`accounts/${id}`, body)
return data
}
createAccount = async () => {}
deleteAccount = async () => {}
getStacks = async () => {
this.axios.get('stacks')
}
updateStack = async (id: uuid, body: Partial<Stack>) => {
const { data } = await this.axios.patch<Stack>(`stacks/${id}`, body)
return data
}
createStack = async () => {}
deleteStack = async () => {}
getTransactions = async () => {
const { data } = await this.axios.get('transactions')
return data
}
updateTransaction = async (id: uuid, body: Partial<Transaction>) => {
const { data } = await this.axios.patch<Transaction>(
`transactions/${id}`,
body,
)
return data
}
createTransaction = async (body: Omit<Transaction, 'id'>) => {
const { data } = await this.axios.post<Transaction>('transactions', body)
return data
}
deleteTransaction = async () => {}
}
export const logOut = async () => {
wipeJWT()
// axios -> delete session?
}

@ -1,15 +1,11 @@
@import '~antd/dist/antd.dark.css';
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

@ -1,5 +1,34 @@
export type uuid = string
export type User = {
id: string
username: string
id: uuid
name: string
email: string
// password: string
}
export type Account = {
id: uuid
users?: uuid[]
name: string
details: string
income: string
expenses: string
}
export type Stack = {
id: uuid
account: uuid //'38485982-87f3-4a11-a963-2202983809e3'
name: string // 'House Fund'
details: string //'buy furniture'
amount: number // '200.00'
transactions: Transaction[]
}
export type Transaction = {
id: uuid
stack: uuid // '0058cece-3ff3-4ee1-b71d-075a0bc73bc0'
details: string // 'by ghetto couch off Kijiji'
amount: number // '30.44'
created_at: string // '2021-04-15T00:02:45.096071Z'
}

Loading…
Cancel
Save