🐱😒💋

This commit is contained in:
Elijah Lucian
2021-04-14 21:24:00 -06:00
parent 486955a861
commit c73bcf8a57
18 changed files with 7121 additions and 5539 deletions

View File

@@ -0,0 +1,49 @@
import { DataBuddy } from '@dank-inc/data-buddy'
import { Account, Stack, Transaction, User } from '../../types'
export const users = new DataBuddy<User>([
{
id: 'mock-user',
name: 'TestUser42',
email: 'testuser@email.com',
},
])
export const accounts = new DataBuddy<Account>([
{
id: 'home',
name: 'Home Expenses',
details: 'ya',
users: ['42'],
income: 1000,
expenses: 500,
},
])
export const stacks = new DataBuddy<Stack>([
{
id: 'ccrap',
name: 'crap',
account: 'asdf',
amount: 200,
details: 'for all my crap!',
transactions: [],
},
{
id: 'shit',
name: 'shit',
account: 'home',
amount: 500,
details: 'for all my shit!',
transactions: [],
},
{
id: 'poo',
name: 'poo',
account: 'home',
amount: 800,
details: 'for all my poo!',
transactions: [],
},
])
export const transactions = new DataBuddy<Transaction>([])

View File

@@ -1,14 +0,0 @@
import { DataBuddy } from '@dank-inc/data-buddy'
import { Account, Stack, Transaction, User } from '../../types'
export const users = new DataBuddy<User>([
{
id: '42',
name: 'TestUser42',
email: 'testuser@email.com',
},
])
export const accounts = new DataBuddy<Account>([])
export const stacks = new DataBuddy<Stack>([])
export const transactions = new DataBuddy<Transaction>([])

View File

@@ -2,7 +2,7 @@ import Axios, { AxiosInstance } from 'axios'
import { Account, Password, 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'
import { users, accounts, stacks, transactions } from './data'
export type ApiParams = {
baseURL?: string
@@ -14,7 +14,7 @@ export interface Api {
users: DataBuddy<User>
accounts: DataBuddy<Account>
stacks: DataBuddy<Stack>
Transactions: DataBuddy<Transaction>
transactions: DataBuddy<Transaction>
axios: AxiosInstance
}
@@ -22,19 +22,25 @@ export class Api {
constructor({ mock, baseURL }: ApiParams) {
this.mock = mock
this.users = users
this.accounts = accounts
this.stacks = stacks
this.transactions = transactions
this.axios = Axios.create({ baseURL })
}
login = async (username: string, password: string): Promise<JWT> => {
if (this.mock)
return {
id: 'mock-id',
login = async (name: string, password: string): Promise<JWT> => {
if (this.mock) {
const jwt = {
id: 'mock-user',
token: 'token-token-token',
exp: +new Date(),
}
setJWT(jwt)
return jwt
}
const { data } = await this.axios.post<JWT>(`/api/dj-rest-auth/login/`, {
username,
name,
password,
})
@@ -65,11 +71,13 @@ export class Api {
}
getAccounts = async () => {
if (this.mock) return this.accounts.get()
const { data } = await this.axios.get<Account[]>('accounts')
return data
}
getAccount = async (id: uuid) => {
if (this.mock) return this.accounts.getOne(id)
const data = await this.axios.get<Account>(`accounts/${id}`)
return data
}
@@ -84,20 +92,25 @@ export class Api {
deleteAccount = async () => {}
getStacks = async (): Promise<Stack[]> => {
if (this.mock) return this.stacks.get()
const { data } = await this.axios.get('stacks')
return data
}
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 () => {
if (this.mock) return this.transactions.get()
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}`,
@@ -105,6 +118,7 @@ export class Api {
)
return data
}
createTransaction = async (body: Omit<Transaction, 'id'>) => {
const { data } = await this.axios.post<Transaction>('transactions', body)
return data