membership functions - split and compose router functions - schema changes

This commit is contained in:
Michael Dausmann
2023-02-08 23:14:46 +11:00
parent 087526eb50
commit de976ab43b
10 changed files with 282 additions and 71 deletions

View File

@@ -0,0 +1,38 @@
import UserAccountService from '~~/lib/services/user.account.service';
import { protectedProcedure, router } from '../trpc'
import { ACCOUNT_ACCESS } from '@prisma/client';
export const userAccountRouter = router({
changeAccountPlan: protectedProcedure
.query(async ({ ctx }) => {
const uaService = new UserAccountService(ctx.prisma);
const account = await uaService.changeAccountPlan(ctx.dbUser.memberships[0].account_id, 2); // todo - plan should be an in put param
return {
account,
}
}),
joinUserToAccount: protectedProcedure
.query(async ({ ctx }) => {
const uaService = new UserAccountService(ctx.prisma);
const membership = await uaService.joinUserToAccount(ctx.dbUser.id, 5); // todo - account should be an input param
return {
membership,
}
}),
changeUserAccessWithinAccount: protectedProcedure // TODO - should be protectedAdmin (i.e. ctx.dbUser.id should be admin within the session account)
.query(async ({ ctx }) => {
const uaService = new UserAccountService(ctx.prisma);
const membership = await uaService.changeUserAccessWithinAccount(3, 5, ACCOUNT_ACCESS.ADMIN); // todo - member and access should be an input param (from UI) account should be the session account
return {
membership,
}
}),
claimOwnershipOfAccount: protectedProcedure // TODO - should be protectedAdmin (i.e. ctx.dbUser.id should be admin within the session account)
.query(async ({ ctx }) => {
const uaService = new UserAccountService(ctx.prisma);
const membership = await uaService.claimOwnershipOfAccount(3, 5); // todo - member should be an input param (from UI) account should be the session account
return {
membership,
}
}),
})