feat(accounts): add accounts and shared accounts call

This commit is contained in:
2021-11-04 02:04:59 +01:00
parent e3f2e12df4
commit a169862311
5 changed files with 53 additions and 20 deletions

View File

@@ -2,6 +2,9 @@
"name": "noscomptes",
"version": "0.1.0",
"private": true,
"engines": {
"node" : "16.13.0"
},
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",

View File

@@ -9,7 +9,7 @@
<script>
import router from '@/router/router'
import {logWithGoogle} from '@/config/noscomptes'
import {logWithGoogle, getAccounts, getSharedAccounts} from '@/config/noscomptes'
export default {
name: 'login_signup_social',
mounted () {
@@ -19,16 +19,25 @@ export default {
this.$gAuth
.signIn()
.then(GoogleUser => {
logWithGoogle(GoogleUser.getAuthResponse().id_token)
// on success do something
console.log('GoogleUser', GoogleUser)
return logWithGoogle(GoogleUser.getAuthResponse().id_token).then(data => {
let userInfoMapped = {
nosComptesId: data.id,
googleId: GoogleUser.wa,
firstName: GoogleUser.mt.Re,
email: GoogleUser.mt.Xt,
oauth_token: GoogleUser.Zb.access_token,
email: data.email,
oauth_token: GoogleUser.getAuthResponse().id_token,
}
this.$store.commit('setLoginUser', userInfoMapped)
return userInfoMapped
})})
.then(userInfo => {
getAccounts(userInfo.oauth_token, userInfo.nosComptesId).then(data => {
this.$store.commit('userAccounts', data)
})
getSharedAccounts(userInfo.oauth_token, userInfo.nosComptesId).then(data => {
this.$store.commit('userSharedAccounts', data)
})
router.push('/')
})
.catch(error => {

View File

@@ -4,12 +4,29 @@ export const logWithGoogle = (oauthToken) => {
const headers = {
"Authorization": "Bearer "+oauthToken
};
return Vue.axios.post("http://localhost:8081/users", "{}",{headers})
return Vue.axios.get("http://localhost:8081/users",{headers}).then(response => {return response.data})
}
export const getUserInformation = (oauthToken) => {
export const getAccounts = (oauthToken, userId) => {
const headers = {
"Authorization": "Bearer "+oauthToken
};
return Vue.axios.get("http://localhost:8081/configuration", {headers})
return Vue.axios.get("http://localhost:8081/users/"+userId+"/accountsgc", {headers}).then(response => {console.log(response);return response.data})
}
export const getSharedAccounts = (oauthToken, userId) => {
const headers = {
"Authorization": "Bearer "+oauthToken
};
return Vue.axios.get("http://localhost:8081/users/"+userId+"/sharedaccounts", {headers}).then(response => {console.log(response);return response.data})
}
export const createAccount = (oauthToken, userId, account) => {
const headers = {
"Authorization": "Bearer " + oauthToken
};
return Vue.axios.post("http://localhost:8081/configuration", account, {headers}).then(response => {
console.log(response);
return response.data
})
}

5
src/dto/Account.js Normal file
View File

@@ -0,0 +1,5 @@
class Account {
constructor(name) {
this.name = name
}
}

View File

@@ -17,7 +17,6 @@ export default new Vuex.Store({
setStore('user', user)
},
deleteLoginUser(state) {
console.log("delete user")
state.loggedUser = undefined
removeItem('user')
}