enable update account name from account page
This commit is contained in:
@@ -18,7 +18,7 @@ Please don't hitch your wagon to this star just yet... I'm coding this in the op
|
|||||||
- [x] User roles and permissions (admin, regular user, etc. roles defined in the [Prisma Schema](/prisma/schema.prisma))
|
- [x] User roles and permissions (admin, regular user, etc. roles defined in the [Prisma Schema](/prisma/schema.prisma))
|
||||||
- [x] User Email captured on initial login
|
- [x] User Email captured on initial login
|
||||||
- [x] Initial plan and plan period controled via config to allow either a trial plan or a 'No Plan' for initial users
|
- [x] Initial plan and plan period controled via config to allow either a trial plan or a 'No Plan' for initial users
|
||||||
- [ ] Edit Account Name from Account Page
|
- [x] Edit Account Name from Account Page
|
||||||
|
|
||||||
### Schema and DB Management
|
### Schema and DB Management
|
||||||
- [x] Prisma based Schema Management
|
- [x] Prisma based Schema Management
|
||||||
|
|||||||
@@ -151,6 +151,15 @@ export default class UserAccountService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async changeAccountName(account_id: number, new_name: string) {
|
||||||
|
return prisma_client.account.update({
|
||||||
|
where: { id: account_id},
|
||||||
|
data: {
|
||||||
|
name: new_name,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async changeAccountPlan(account_id: number, plan_id: number) {
|
async changeAccountPlan(account_id: number, plan_id: number) {
|
||||||
const plan = await prisma_client.plan.findFirstOrThrow({ where: {id: plan_id}});
|
const plan = await prisma_client.plan.findFirstOrThrow({ where: {id: plan_id}});
|
||||||
return prisma_client.account.update({
|
return prisma_client.account.update({
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
import { ACCOUNT_ACCESS } from '@prisma/client';
|
||||||
|
|
||||||
const store = useAppStore();
|
const store = useAppStore();
|
||||||
const { activeMembership } = storeToRefs(store);
|
const { activeMembership } = storeToRefs(store);
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
|
const newAccountName = ref("");
|
||||||
|
|
||||||
function formatDate(date: Date | undefined){
|
function formatDate(date: Date | undefined){
|
||||||
if(!date){ return ""; }
|
if(!date){ return ""; }
|
||||||
@@ -12,7 +15,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<h3>Account</h3>
|
<h3>Account</h3>
|
||||||
<p>Name: {{ activeMembership?.account.name }}</p>
|
<p>Name: {{ activeMembership?.account.name }} <span v-if="activeMembership && (activeMembership.access === ACCOUNT_ACCESS.OWNER || activeMembership.access !== ACCOUNT_ACCESS.ADMIN)"><input v-model="newAccountName" placeholder="Enter New Name"/><button @click.prevent="store.changeAccountName(newAccountName)">Change Name</button></span></p>
|
||||||
<p>Current Period Ends: {{ formatDate(activeMembership?.account.current_period_ends) }}</p>
|
<p>Current Period Ends: {{ formatDate(activeMembership?.account.current_period_ends) }}</p>
|
||||||
<p>Permitted Features: {{ activeMembership?.account.features }}</p>
|
<p>Permitted Features: {{ activeMembership?.account.features }}</p>
|
||||||
<p>Maximum Notes: {{ activeMembership?.account.max_notes }}</p>
|
<p>Maximum Notes: {{ activeMembership?.account.max_notes }}</p>
|
||||||
|
|||||||
@@ -10,6 +10,16 @@ export const userAccountRouter = router({
|
|||||||
dbUser: ctx.dbUser,
|
dbUser: ctx.dbUser,
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
changeAccountName: adminProcedure
|
||||||
|
.input(z.object({ account_id: z.number(), new_name: z.string() }))
|
||||||
|
.query(async ({ ctx, input }) => {
|
||||||
|
const uaService = new UserAccountService();
|
||||||
|
const account = await uaService.changeAccountName(input.account_id, input.new_name);
|
||||||
|
|
||||||
|
return {
|
||||||
|
account,
|
||||||
|
}
|
||||||
|
}),
|
||||||
changeAccountPlan: adminProcedure
|
changeAccountPlan: adminProcedure
|
||||||
.input(z.object({ account_id: z.number(), plan_id: z.number() }))
|
.input(z.object({ account_id: z.number(), plan_id: z.number() }))
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
|
|||||||
@@ -45,6 +45,14 @@ export const useAppStore = defineStore('app', {
|
|||||||
await this.fetchNotesForCurrentUser();
|
await this.fetchNotesForCurrentUser();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async changeAccountName(new_name: string){
|
||||||
|
if(!this.activeMembership) { return; }
|
||||||
|
const { $client } = useNuxtApp();
|
||||||
|
const { data: account } = await $client.userAccount.changeAccountName.useQuery({account_id: this.activeMembership.account_id, new_name});
|
||||||
|
if(account.value?.account){
|
||||||
|
this.activeMembership.account = account.value.account;
|
||||||
|
}
|
||||||
|
},
|
||||||
async changeAccountPlan(plan_id: number){
|
async changeAccountPlan(plan_id: number){
|
||||||
if(!this.activeMembership) { return; }
|
if(!this.activeMembership) { return; }
|
||||||
const { $client } = useNuxtApp();
|
const { $client } = useNuxtApp();
|
||||||
|
|||||||
Reference in New Issue
Block a user