initialise user and dbUser objects within getContext so they load per request
This commit is contained in:
@@ -102,6 +102,8 @@ npx prisma generate
|
|||||||
- team invitation thingy (not required, admins can add new members to team)
|
- team invitation thingy (not required, admins can add new members to team)
|
||||||
- actions which mutate the current user account should update the context... (done)
|
- actions which mutate the current user account should update the context... (done)
|
||||||
- integration with stripe including web hooks.
|
- integration with stripe including web hooks.
|
||||||
|
-- add email to user record... capture from login same as user name
|
||||||
|
-- add a pricing page....should be the default redirect from signup if the user has no active plan.. not sure whether to use a 'blank' plan or make plan nullable
|
||||||
|
|
||||||
# Admin Functions Scenario (shitty test)
|
# Admin Functions Scenario (shitty test)
|
||||||
Pre-condition
|
Pre-condition
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import UserAccountService, { FullDBUser } from '~~/lib/services/user.account.ser
|
|||||||
|
|
||||||
let prisma: PrismaClient | undefined
|
let prisma: PrismaClient | undefined
|
||||||
let supabase: SupabaseClient | undefined
|
let supabase: SupabaseClient | undefined
|
||||||
let user: User | null;
|
|
||||||
let dbUser: FullDBUser | null
|
|
||||||
|
|
||||||
export async function createContext(event: H3Event){
|
export async function createContext(event: H3Event){
|
||||||
|
let user: User | null = null;
|
||||||
|
let dbUser: FullDBUser | null = null;
|
||||||
|
|
||||||
if (!supabase) {
|
if (!supabase) {
|
||||||
supabase = serverSupabaseClient(event)
|
supabase = serverSupabaseClient(event)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,6 @@ export const userAccountRouter = router({
|
|||||||
const uaService = new UserAccountService(ctx.prisma);
|
const uaService = new UserAccountService(ctx.prisma);
|
||||||
const account = await uaService.changeAccountPlan(input.account_id, input.plan_id);
|
const account = await uaService.changeAccountPlan(input.account_id, input.plan_id);
|
||||||
|
|
||||||
if(account){
|
|
||||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.account_id !== account.id ? m : { ...m, account });
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
}
|
}
|
||||||
@@ -39,10 +35,6 @@ export const userAccountRouter = router({
|
|||||||
const uaService = new UserAccountService(ctx.prisma);
|
const uaService = new UserAccountService(ctx.prisma);
|
||||||
const membership = await uaService.changeUserAccessWithinAccount(input.user_id, input.account_id, input.access);
|
const membership = await uaService.changeUserAccessWithinAccount(input.user_id, input.account_id, input.access);
|
||||||
|
|
||||||
if(membership && ctx.dbUser?.id == input.user_id){
|
|
||||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.id !== membership.id ? m : membership);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
membership,
|
membership,
|
||||||
}
|
}
|
||||||
@@ -53,10 +45,6 @@ export const userAccountRouter = router({
|
|||||||
const uaService = new UserAccountService(ctx.prisma);
|
const uaService = new UserAccountService(ctx.prisma);
|
||||||
const membership = await uaService.claimOwnershipOfAccount(ctx.dbUser.id, input.account_id);
|
const membership = await uaService.claimOwnershipOfAccount(ctx.dbUser.id, input.account_id);
|
||||||
|
|
||||||
if(membership && ctx.dbUser){
|
|
||||||
ctx.dbUser.memberships = ctx.dbUser.memberships.map(m => m.id !== membership.id ? m : membership);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
membership,
|
membership,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user