service refactor to namespaces

This commit is contained in:
Michael Dausmann
2024-02-17 10:49:23 +11:00
parent d8f20d9896
commit 23c248a08b
10 changed files with 80 additions and 90 deletions

View File

@@ -8,7 +8,7 @@ import {
} from '../trpc';
import { ACCOUNT_ACCESS } from '~~/prisma/account-access-enum';
import { z } from 'zod';
import AccountService from '~~/lib/services/account.service';
import { AccountService } from '~~/lib/services/account.service';
import { MembershipWithAccount } from '~~/lib/services/service.types';
/*
@@ -48,8 +48,7 @@ export const accountRouter = router({
changeAccountName: adminProcedure
.input(z.object({ new_name: z.string() }))
.mutation(async ({ ctx, input }) => {
const accountService = new AccountService();
const account = await accountService.changeAccountName(
const account = await AccountService.changeAccountName(
ctx.activeAccountId!,
input.new_name
);
@@ -58,8 +57,7 @@ export const accountRouter = router({
};
}),
rotateJoinPassword: adminProcedure.mutation(async ({ ctx }) => {
const accountService = new AccountService();
const account = await accountService.rotateJoinPassword(
const account = await AccountService.rotateJoinPassword(
ctx.activeAccountId!
);
return {
@@ -69,8 +67,7 @@ export const accountRouter = router({
getAccountByJoinPassword: publicProcedure
.input(z.object({ join_password: z.string() }))
.query(async ({ input }) => {
const accountService = new AccountService();
const account = await accountService.getAccountByJoinPassword(
const account = await AccountService.getAccountByJoinPassword(
input.join_password
);
return {
@@ -80,9 +77,8 @@ export const accountRouter = router({
joinUserToAccountPending: publicProcedure // this uses a passed account id rather than using the active account because user is usually active on their personal or some other account when they attempt to join a new account
.input(z.object({ account_id: z.number(), user_id: z.number() }))
.mutation(async ({ input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount =
await accountService.joinUserToAccount(
await AccountService.joinUserToAccount(
input.user_id,
input.account_id,
true
@@ -94,9 +90,8 @@ export const accountRouter = router({
acceptPendingMembership: adminProcedure
.input(z.object({ membership_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount =
await accountService.acceptPendingMembership(
await AccountService.acceptPendingMembership(
ctx.activeAccountId!,
input.membership_id
);
@@ -107,9 +102,8 @@ export const accountRouter = router({
rejectPendingMembership: adminProcedure
.input(z.object({ membership_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount =
await accountService.deleteMembership(
await AccountService.deleteMembership(
ctx.activeAccountId!,
input.membership_id
);
@@ -120,9 +114,8 @@ export const accountRouter = router({
deleteMembership: ownerProcedure
.input(z.object({ membership_id: z.number() }))
.query(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership: MembershipWithAccount =
await accountService.deleteMembership(
await AccountService.deleteMembership(
ctx.activeAccountId!,
input.membership_id
);
@@ -143,8 +136,7 @@ export const accountRouter = router({
})
)
.mutation(async ({ ctx, input }) => {
const accountService = new AccountService();
const membership = await accountService.changeUserAccessWithinAccount(
const membership = await AccountService.changeUserAccessWithinAccount(
input.user_id,
ctx.activeAccountId!,
input.access
@@ -154,8 +146,7 @@ export const accountRouter = router({
};
}),
claimOwnershipOfAccount: adminProcedure.mutation(async ({ ctx }) => {
const accountService = new AccountService();
const memberships = await accountService.claimOwnershipOfAccount(
const memberships = await AccountService.claimOwnershipOfAccount(
ctx.dbUser!.id,
ctx.activeAccountId!
);
@@ -164,8 +155,7 @@ export const accountRouter = router({
};
}),
getAccountMembers: adminProcedure.query(async ({ ctx }) => {
const accountService = new AccountService();
const memberships = await accountService.getAccountMembers(
const memberships = await AccountService.getAccountMembers(
ctx.activeAccountId!
);
return {