prettier fixes #16

This commit is contained in:
Michael Dausmann
2023-10-24 21:18:03 +11:00
parent dc9d64ebf5
commit a7f8c37f99
56 changed files with 1706 additions and 935 deletions

View File

@@ -1,6 +1,6 @@
import { ACCOUNT_ACCESS } from '~~/prisma/account-access-enum';
import { defineStore } from "pinia"
import { FullDBUser, MembershipWithUser } from "~~/lib/services/service.types";
import { defineStore } from 'pinia';
import { FullDBUser, MembershipWithUser } from '~~/lib/services/service.types';
/*
This store manages User and Account state including the ActiveAccount
@@ -23,9 +23,9 @@ so that other routers can use them to filter results to the active user and acco
account account acccount*
*/
interface State {
dbUser: FullDBUser | null,
activeAccountId: number | null,
activeAccountMembers: MembershipWithUser[]
dbUser: FullDBUser | null;
activeAccountId: number | null;
activeAccountMembers: MembershipWithUser[];
}
export const useAccountStore = defineStore('account', {
@@ -33,117 +33,155 @@ export const useAccountStore = defineStore('account', {
return {
dbUser: null,
activeAccountId: null,
activeAccountMembers: [],
}
activeAccountMembers: []
};
},
getters: {
activeMembership: (state) => state.dbUser?.memberships.find(m => m.account_id === state.activeAccountId)
activeMembership: state =>
state.dbUser?.memberships.find(
m => m.account_id === state.activeAccountId
)
},
actions: {
async init(){
async init() {
const { $client } = useNuxtApp();
if(!this.dbUser){
if (!this.dbUser) {
const { dbUser } = await $client.auth.getDBUser.query();
if(dbUser){
if (dbUser) {
this.dbUser = dbUser;
}
}
if(!this.activeAccountId){
const { activeAccountId } = await $client.account.getActiveAccountId.query();
if(activeAccountId){
if (!this.activeAccountId) {
const { activeAccountId } =
await $client.account.getActiveAccountId.query();
if (activeAccountId) {
this.activeAccountId = activeAccountId;
}
}
},
signout(){
signout() {
this.dbUser = null;
this.activeAccountId = null;
this.activeAccountMembers = [];
},
async getActiveAccountMembers(){
if(this.activeMembership && (this.activeMembership.access === ACCOUNT_ACCESS.ADMIN || this.activeMembership.access === ACCOUNT_ACCESS.OWNER)){
async getActiveAccountMembers() {
if (
this.activeMembership &&
(this.activeMembership.access === ACCOUNT_ACCESS.ADMIN ||
this.activeMembership.access === ACCOUNT_ACCESS.OWNER)
) {
const { $client } = useNuxtApp();
const { data: memberships } = await $client.account.getAccountMembers.useQuery();
if(memberships.value?.memberships){
const { data: memberships } =
await $client.account.getAccountMembers.useQuery();
if (memberships.value?.memberships) {
this.activeAccountMembers = memberships.value?.memberships;
}
}
},
async changeActiveAccount(account_id: number){
async changeActiveAccount(account_id: number) {
const { $client } = useNuxtApp();
await $client.account.changeActiveAccount.mutate({account_id}); // sets active account on context for other routers and sets the preference in a cookie
this.activeAccountId = account_id; // because this is used as a trigger to some other components, NEEDS TO BE AFTER THE MUTATE CALL
await $client.account.changeActiveAccount.mutate({ account_id }); // sets active account on context for other routers and sets the preference in a cookie
this.activeAccountId = account_id; // because this is used as a trigger to some other components, NEEDS TO BE AFTER THE MUTATE CALL
await this.getActiveAccountMembers(); // these relate to the active account and need to ber re-fetched
},
async changeAccountName(new_name: string){
if(!this.activeMembership){ return; }
async changeAccountName(new_name: string) {
if (!this.activeMembership) {
return;
}
const { $client } = useNuxtApp();
const { account } = await $client.account.changeAccountName.mutate({ new_name });
if(account){
const { account } = await $client.account.changeAccountName.mutate({
new_name
});
if (account) {
this.activeMembership.account.name = account.name;
}
},
async acceptPendingMembership(membership_id: number){
async acceptPendingMembership(membership_id: number) {
const { $client } = useNuxtApp();
const { data: membership } = await $client.account.acceptPendingMembership.useQuery({ membership_id });
if(membership.value && membership.value.membership?.pending === false){
for(const m of this.activeAccountMembers){
if(m.id === membership_id){
const { data: membership } =
await $client.account.acceptPendingMembership.useQuery({
membership_id
});
if (membership.value && membership.value.membership?.pending === false) {
for (const m of this.activeAccountMembers) {
if (m.id === membership_id) {
m.pending = false;
}
}
}
},
async rejectPendingMembership(membership_id: number){
async rejectPendingMembership(membership_id: number) {
const { $client } = useNuxtApp();
const { data: membership } = await $client.account.rejectPendingMembership.useQuery({ membership_id });
if(membership.value){
this.activeAccountMembers = this.activeAccountMembers.filter(m => m.id !== membership_id);
const { data: membership } =
await $client.account.rejectPendingMembership.useQuery({
membership_id
});
if (membership.value) {
this.activeAccountMembers = this.activeAccountMembers.filter(
m => m.id !== membership_id
);
}
},
async deleteMembership(membership_id: number){
async deleteMembership(membership_id: number) {
const { $client } = useNuxtApp();
const { data: membership } = await $client.account.deleteMembership.useQuery({ membership_id });
if(membership.value){
this.activeAccountMembers = this.activeAccountMembers.filter(m => m.id !== membership_id);
const { data: membership } =
await $client.account.deleteMembership.useQuery({ membership_id });
if (membership.value) {
this.activeAccountMembers = this.activeAccountMembers.filter(
m => m.id !== membership_id
);
}
},
async rotateJoinPassword(){
async rotateJoinPassword() {
const { $client } = useNuxtApp();
const { account } = await $client.account.rotateJoinPassword.mutate();
if(account && this.activeMembership){
if (account && this.activeMembership) {
this.activeMembership.account = account;
}
},
async joinUserToAccountPending(account_id: number){
if(!this.dbUser) { return; }
async joinUserToAccountPending(account_id: number) {
if (!this.dbUser) {
return;
}
const { $client } = useNuxtApp();
const { membership } = await $client.account.joinUserToAccountPending.mutate({account_id, user_id: this.dbUser.id});
if(membership && this.activeMembership){
const { membership } =
await $client.account.joinUserToAccountPending.mutate({
account_id,
user_id: this.dbUser.id
});
if (membership && this.activeMembership) {
this.dbUser?.memberships.push(membership);
}
},
async changeUserAccessWithinAccount(user_id: number, access: ACCOUNT_ACCESS){
async changeUserAccessWithinAccount(
user_id: number,
access: ACCOUNT_ACCESS
) {
const { $client } = useNuxtApp();
const { membership } = await $client.account.changeUserAccessWithinAccount.mutate({ user_id, access });
if(membership){
for(const m of this.activeAccountMembers){
if(m.id === membership.id){
const { membership } =
await $client.account.changeUserAccessWithinAccount.mutate({
user_id,
access
});
if (membership) {
for (const m of this.activeAccountMembers) {
if (m.id === membership.id) {
m.access = membership.access;
}
}
}
},
async claimOwnershipOfAccount(){
async claimOwnershipOfAccount() {
const { $client } = useNuxtApp();
const { memberships } = await $client.account.claimOwnershipOfAccount.mutate();
if(memberships){
const { memberships } =
await $client.account.claimOwnershipOfAccount.mutate();
if (memberships) {
this.activeAccountMembers = memberships;
this.activeMembership!.access = ACCOUNT_ACCESS.OWNER
this.activeMembership!.access = ACCOUNT_ACCESS.OWNER;
}
}
}

View File

@@ -1,6 +1,6 @@
import { Note } from ".prisma/client"
import { defineStore, storeToRefs } from "pinia"
import { Ref } from "vue";
import { Note } from '.prisma/client';
import { defineStore, storeToRefs } from 'pinia';
import { Ref } from 'vue';
/*
Note) the Notes Store needs to be a 'Setup Store' (https://pinia.vuejs.org/core-concepts/#setup-stores)
@@ -9,7 +9,7 @@ If the UI does not need to dynamically respond to a change in the active Account
then an Options store can be used.
*/
export const useNotesStore = defineStore('notes', () => {
const accountStore = useAccountStore()
const accountStore = useAccountStore();
const { activeAccountId } = storeToRefs(accountStore);
let _notes: Ref<Note[]> = ref([]);
@@ -17,37 +17,45 @@ export const useNotesStore = defineStore('notes', () => {
async function fetchNotesForCurrentUser() {
const { $client } = useNuxtApp();
const { notes } = await $client.notes.getForActiveAccount.query();
if(notes){
if (notes) {
_notes.value = notes;
}
}
}
async function createNote(note_text: string) {
const { $client } = useNuxtApp();
const { note } = await $client.notes.createNote.mutate({note_text});
if(note){
const { note } = await $client.notes.createNote.mutate({ note_text });
if (note) {
_notes.value.push(note);
}
}
async function deleteNote(note_id: number) {
const { $client } = useNuxtApp();
const { note } = await $client.notes.deleteNote.mutate({note_id});
if(note){
const { note } = await $client.notes.deleteNote.mutate({ note_id });
if (note) {
_notes.value = _notes.value.filter(n => n.id !== note.id);
}
}
async function generateAINoteFromPrompt(user_prompt: string) {
const { $client } = useNuxtApp();
const { noteText } = await $client.notes.generateAINoteFromPrompt.query({user_prompt});
return noteText?noteText:'';
const { noteText } = await $client.notes.generateAINoteFromPrompt.query({
user_prompt
});
return noteText ? noteText : '';
}
// if the active account changes, fetch notes again (i.e dynamic.. probabl overkill)
watch(activeAccountId, async (val, oldVal)=> {
await fetchNotesForCurrentUser()
watch(activeAccountId, async (val, oldVal) => {
await fetchNotesForCurrentUser();
});
return { notes: _notes, fetchNotesForCurrentUser, createNote, deleteNote, generateAINoteFromPrompt}
return {
notes: _notes,
fetchNotesForCurrentUser,
createNote,
deleteNote,
generateAINoteFromPrompt
};
});

View File

@@ -1,45 +1,51 @@
import { defineStore } from "pinia"
import { defineStore } from 'pinia';
/*
This store manages User and Account state including the ActiveAccount
It is used in the Account administration page and the header due to it's account switching features.
*/
export interface Notification{
export interface Notification {
message: string;
type: NotificationType;
notifyTime: number;
}
export enum NotificationType{
export enum NotificationType {
Info,
Success,
Warning,
Error,
Error
}
interface State {
notifications: Notification[],
notificationsArchive: Notification[],
notifications: Notification[];
notificationsArchive: Notification[];
}
export const useNotifyStore = defineStore('notify', {
state: (): State => {
return {
notifications: [],
notificationsArchive: [],
}
notificationsArchive: []
};
},
actions: {
notify(messageOrError: unknown, type:NotificationType){
let message: string = "";
notify(messageOrError: unknown, type: NotificationType) {
let message: string = '';
if (messageOrError instanceof Error) message = messageOrError.message;
if (typeof messageOrError === "string") message = messageOrError;
const notification: Notification = {message, type, notifyTime: Date.now()};
if (typeof messageOrError === 'string') message = messageOrError;
const notification: Notification = {
message,
type,
notifyTime: Date.now()
};
this.notifications.push(notification);
setTimeout(this.removeNotification.bind(this), 5000, notification);
},
removeNotification(notification: Notification){
this.notifications = this.notifications.filter(n => n.notifyTime != notification.notifyTime);
},
removeNotification(notification: Notification) {
this.notifications = this.notifications.filter(
n => n.notifyTime != notification.notifyTime
);
}
}
});