api partially wired up
This commit is contained in:
@@ -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?
|
||||
}
|
||||
|
Reference in New Issue
Block a user