service refactor to namespaces
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { H3Event, getQuery } from 'h3';
|
||||
import { defineProtectedEventHandler } from '../defineProtectedEventHandler';
|
||||
import NotesService from '~/lib/services/notes.service';
|
||||
import { NotesService } from '~/lib/services/notes.service';
|
||||
|
||||
// Example API Route with query params ... /api/note?note_id=41
|
||||
export default defineProtectedEventHandler(async (event: H3Event) => {
|
||||
@@ -14,8 +14,7 @@ export default defineProtectedEventHandler(async (event: H3Event) => {
|
||||
}
|
||||
}
|
||||
|
||||
const notesService = new NotesService();
|
||||
const note = await notesService.getNoteById(+note_id);
|
||||
const note = await NotesService.getNoteById(+note_id);
|
||||
|
||||
return {
|
||||
note
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { defineEventHandler, parseCookies, setCookie, getCookie } from 'h3';
|
||||
import { serverSupabaseUser } from '#supabase/server';
|
||||
import AuthService from '~/lib/services/auth.service';
|
||||
import { AuthService } from '~/lib/services/auth.service';
|
||||
|
||||
import { User } from '@supabase/supabase-js';
|
||||
import { FullDBUser } from '~~/lib/services/service.types';
|
||||
@@ -27,11 +27,10 @@ export default defineEventHandler(async event => {
|
||||
if (user) {
|
||||
event.context.user = user;
|
||||
|
||||
const authService = new AuthService();
|
||||
let dbUser = await authService.getFullUserBySupabaseId(user.id);
|
||||
let dbUser = await AuthService.getFullUserBySupabaseId(user.id);
|
||||
|
||||
if (!dbUser && user) {
|
||||
dbUser = await authService.createUser(
|
||||
dbUser = await AuthService.createUser(
|
||||
user.id,
|
||||
user.user_metadata.full_name
|
||||
? user.user_metadata.full_name
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ACCOUNT_ACCESS } from '~~/prisma/account-access-enum';
|
||||
import Stripe from 'stripe';
|
||||
import AccountService from '~~/lib/services/account.service';
|
||||
import { AccountService } from '~~/lib/services/account.service';
|
||||
import { AccountWithMembers } from '~~/lib/services/service.types';
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
@@ -14,8 +14,7 @@ export default defineEventHandler(async event => {
|
||||
`session.post.ts recieved price_id:${price_id}, account_id:${account_id}`
|
||||
);
|
||||
|
||||
const accountService = new AccountService();
|
||||
const account: AccountWithMembers = await accountService.getAccountById(
|
||||
const account: AccountWithMembers = await AccountService.getAccountById(
|
||||
account_id
|
||||
);
|
||||
let customer_id: string;
|
||||
@@ -32,7 +31,7 @@ export default defineEventHandler(async event => {
|
||||
email: owner?.user.email
|
||||
});
|
||||
customer_id = customer.id;
|
||||
accountService.updateAccountStipeCustomerId(account_id, customer.id);
|
||||
AccountService.updateAccountStipeCustomerId(account_id, customer.id);
|
||||
} else {
|
||||
customer_id = account.stripe_customer_id;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Stripe from 'stripe';
|
||||
import AccountService from '~~/lib/services/account.service';
|
||||
import { AccountService } from '~~/lib/services/account.service';
|
||||
|
||||
const config = useRuntimeConfig();
|
||||
const stripe = new Stripe(config.stripeSecretKey, { apiVersion: '2022-11-15' });
|
||||
@@ -56,8 +56,6 @@ export default defineEventHandler(async event => {
|
||||
});
|
||||
}
|
||||
|
||||
const accountService = new AccountService();
|
||||
|
||||
let current_period_ends: Date = new Date(
|
||||
subscription.current_period_end * 1000
|
||||
);
|
||||
@@ -68,7 +66,7 @@ export default defineEventHandler(async event => {
|
||||
console.log(
|
||||
`updating stripe sub details subscription.current_period_end:${subscription.current_period_end}, subscription.id:${subscription.id}, stripe_product_id:${stripe_product_id}`
|
||||
);
|
||||
accountService.updateStripeSubscriptionDetailsForAccount(
|
||||
AccountService.updateStripeSubscriptionDetailsForAccount(
|
||||
subscription.customer.toString(),
|
||||
subscription.id,
|
||||
current_period_ends,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import NotesService from '~~/lib/services/notes.service';
|
||||
import { NotesService } from '~~/lib/services/notes.service';
|
||||
import {
|
||||
accountHasSpecialFeature,
|
||||
adminProcedure,
|
||||
@@ -11,9 +11,8 @@ import { z } from 'zod';
|
||||
|
||||
export const notesRouter = router({
|
||||
getForActiveAccount: memberProcedure.query(async ({ ctx, input }) => {
|
||||
const notesService = new NotesService();
|
||||
const notes = ctx.activeAccountId
|
||||
? await notesService.getNotesForAccountId(ctx.activeAccountId)
|
||||
? await NotesService.getNotesForAccountId(ctx.activeAccountId)
|
||||
: [];
|
||||
return {
|
||||
notes
|
||||
@@ -22,8 +21,7 @@ export const notesRouter = router({
|
||||
getById: publicProcedure
|
||||
.input(z.object({ note_id: z.number() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const notesService = new NotesService();
|
||||
const note = await notesService.getNoteById(input.note_id);
|
||||
const note = await NotesService.getNoteById(input.note_id);
|
||||
return {
|
||||
note
|
||||
};
|
||||
@@ -31,9 +29,8 @@ export const notesRouter = router({
|
||||
createNote: readWriteProcedure
|
||||
.input(z.object({ note_text: z.string() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const notesService = new NotesService();
|
||||
const note = ctx.activeAccountId
|
||||
? await notesService.createNote(ctx.activeAccountId, input.note_text)
|
||||
? await NotesService.createNote(ctx.activeAccountId, input.note_text)
|
||||
: null;
|
||||
return {
|
||||
note
|
||||
@@ -42,9 +39,8 @@ export const notesRouter = router({
|
||||
deleteNote: adminProcedure
|
||||
.input(z.object({ note_id: z.number() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const notesService = new NotesService();
|
||||
const note = ctx.activeAccountId
|
||||
? await notesService.deleteNote(input.note_id)
|
||||
? await NotesService.deleteNote(input.note_id)
|
||||
: null;
|
||||
return {
|
||||
note
|
||||
@@ -54,9 +50,8 @@ export const notesRouter = router({
|
||||
.use(accountHasSpecialFeature)
|
||||
.input(z.object({ user_prompt: z.string() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const notesService = new NotesService();
|
||||
const noteText = ctx.activeAccountId
|
||||
? await notesService.generateAINoteFromPrompt(
|
||||
? await NotesService.generateAINoteFromPrompt(
|
||||
input.user_prompt,
|
||||
ctx.activeAccountId
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user