team join with link and member admin

This commit is contained in:
Michael Dausmann
2023-04-09 00:41:46 +10:00
parent b4b20e4260
commit 4d288c7468
15 changed files with 238 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
import { router, adminProcedure } from '../trpc'
import { router, adminProcedure, publicProcedure } from '../trpc'
import { ACCOUNT_ACCESS } from '@prisma/client';
import { z } from 'zod';
import AccountService from '~~/lib/services/account.service';
@@ -15,11 +15,21 @@ export const accountRouter = router({
account,
}
}),
changeAccountPlan: adminProcedure
.input(z.object({ account_id: z.number(), plan_id: z.number() }))
rotateJoinPassword: adminProcedure
.input(z.object({ account_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const account = await accountService.changeAccountPlan(input.account_id, input.plan_id);
const account = await accountService.rotateJoinPassword(input.account_id);
return {
account,
}
}),
getAccountByJoinPassword: publicProcedure
.input(z.object({ join_password: z.string() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const account = await accountService.getAccountByJoinPassword(input.join_password);
return {
account,
@@ -29,7 +39,25 @@ export const accountRouter = router({
.input(z.object({ account_id: z.number(), user_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount| null = (ctx.dbUser?.id)?await accountService.joinUserToAccount(input.user_id, input.account_id):null;
const membership: MembershipWithAccount| null = (ctx.dbUser?.id)?await accountService.joinUserToAccount(input.user_id, input.account_id, false):null;
return {
membership,
}
}),
joinUserToAccountPending: publicProcedure
.input(z.object({ account_id: z.number(), user_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount| null = (ctx.dbUser?.id)?await accountService.joinUserToAccount(input.user_id, input.account_id, true):null;
return {
membership,
}
}),
acceptPendingMembership: adminProcedure
.input(z.object({ account_id: z.number(), membership_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount| null = (ctx.dbUser?.id)?await accountService.acceptPendingMembership(input.account_id, input.membership_id):null;
return {
membership,
}
@@ -48,7 +76,7 @@ export const accountRouter = router({
.input(z.object({ account_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership = await accountService.claimOwnershipOfAccount(ctx.dbUser.id, input.account_id);
const membership = await accountService.claimOwnershipOfAccount(ctx.dbUser!.id, input.account_id); // adminProcedure errors if ctx.dbUser is null so bang is ok here
return {
membership,

View File

@@ -1,7 +1,7 @@
import { protectedProcedure, router } from '../trpc'
import { publicProcedure, router } from '../trpc'
export const authRouter = router({
getDBUser: protectedProcedure
getDBUser: publicProcedure
.query(({ ctx }) => {
return {
dbUser: ctx.dbUser,