parameterise admin functions and move to store actions

This commit is contained in:
Michael Dausmann
2023-02-21 20:37:32 +11:00
parent fbe2436231
commit f2b3a2617d
4 changed files with 48 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import { Membership, Note, User } from ".prisma/client"
import { ACCOUNT_ACCESS, Note } from ".prisma/client"
import { defineStore } from "pinia"
import { FullDBUser, MembershipWithAccount } from "~~/lib/services/user.account.service"
@@ -49,6 +49,30 @@ export const useAppStore = defineStore('app', {
if(account.value?.account){
this.activeMembership.account = account.value.account;
}
},
async joinUserToAccount(account_id: number){
if(!this.activeMembership) { return; }
const { $client } = useNuxtApp();
const { data: membership } = await $client.userAccount.joinUserToAccount.useQuery({account_id});
if(membership.value?.membership){
this.activeMembership = membership.value.membership;
}
},
async changeUserAccessWithinAccount(user_id: number,account_id: number, access: ACCOUNT_ACCESS){
if(!this.activeMembership) { return; }
const { $client } = useNuxtApp();
const { data: membership } = await $client.userAccount.changeUserAccessWithinAccount.useQuery({user_id, account_id, access});
if(membership.value?.membership){
this.activeMembership = membership.value.membership;
}
},
async claimOwnershipOfAccount(account_id: number){
if(!this.activeMembership) { return; }
const { $client } = useNuxtApp();
const { data: membership } = await $client.userAccount.claimOwnershipOfAccount.useQuery({account_id});
if(membership.value?.membership){
this.activeMembership = membership.value.membership;
}
}
}
});