sweet! can now update transactions

This commit is contained in:
Annika
2022-07-12 11:48:40 -06:00
parent 6455c02d5e
commit ef06dd057a
6 changed files with 78 additions and 16 deletions
+17 -14
View File
@@ -19,35 +19,38 @@
<input type="text" v-model="transaction.comment" :placeholder="transaction.comment" class="text-slate-50 bg-stone-800 w-48 hover:bg-green-300 hover:text-stone-900">
</div>
<div>
<button class="text-slate-50 bg-stone-800 w-16 hover:bg-green-300 hover:text-stone-900">
<button class="text-slate-50 bg-stone-800 w-16 hover:bg-green-300 hover:text-stone-900" @click="update">
Save
</button>
{{transaction}}
</div>
</div>
</template>
<script>
// import { logger } from '../utils/Logger'
import { transactionsService } from '../services/TransactionsService'
export default {
// TODO there's probably something wrong with this...
props: {
transaction: {
date: String || '2022-07-11',
amount: Number || 0,
payee: String || '',
category: String || '', //should be enum
comment: String || ''
type: Object,
required: true
}
},
setup(){
setup(props){
return {
// transaction: {
// date: '2022-07-11',
// amount: 0,
// payee: '',
// category: '',
// comment: ''
// }
async update() {
console.log(props.transaction)
// send off request to update transaction
try {
await transactionsService.update(props.transaction)
} catch (error) {
console.log(error)
}
}
}
}
}
+1
View File
@@ -16,6 +16,7 @@ const routes = [
name: 'Transactions',
component: loadPage('TransactionsPage'),
beforeEnter: authGuard // this is important to keep the request from firing before the auth token is issued.
// if not need to be logged-in use authSettled
},
{
path: '/account',
+1 -1
View File
@@ -26,7 +26,7 @@ AuthService.on(AuthService.AUTH_EVENTS.AUTHENTICATED, async function() {
AppState.user = AuthService.user
await accountService.getAccount()
socketService.authenticate(AuthService.bearer)
// NOTE if there is something you want to do once the user is authenticated, place that here
// NOTE if there is something you want to do once the user is authenticated, place that here (!!!)
})
async function refreshAuthToken(config) {
@@ -17,6 +17,14 @@ class TransactionsService {
// logger.log('transactions: ' + res.data)
AppState.transactions = res.data
}
// TODO test this
async update(transaction) {
console.log(transaction._id)
const res = await api.put('api/transactions/' + transaction._id, transaction)
console.log('transactionUpdate: ' + res.data)
// AppState.transactions.find((t) => t._id == transactionId) = res.data
}
}
export const transactionsService = new TransactionsService()