dumb refactor but sunk cost is to great keep pushing

This commit is contained in:
2025-08-03 22:53:52 +02:00
parent 2816842b5d
commit e74b30e04c
35 changed files with 621 additions and 1287 deletions

View File

@@ -1,12 +1,19 @@
import type { inferRouterOutputs } from "@trpc/server";
import { router } from "../trpc";
import { CvRouter } from "./cv";
import type { inferReactQueryProcedureOptions } from "@trpc/react-query";
import { ProjectRouter } from "./project";
import { trpcCrudRouterFromDrizzleEntity } from "../lib";
import type { inferRouterMeta } from "@trpc/server/unstable-core-do-not-import";
const { router : project } = trpcCrudRouterFromDrizzleEntity('project')
const { router : techStack } = trpcCrudRouterFromDrizzleEntity('techStack')
const { router : category } = trpcCrudRouterFromDrizzleEntity('cvCategory')
const { router : entry } = trpcCrudRouterFromDrizzleEntity('cvEntry')
const root = {}
export const trpcRouter = router({
cv: CvRouter,
project: ProjectRouter
project: project,
techStack: techStack,
category: category,
entry: entry
})
export type TrpcRouter = typeof trpcRouter

View File

@@ -1,75 +0,0 @@
import { db } from "~/server/db";
import { publicProcedure, router } from "~/server/trpc";
import { cvCategory, cvEntry } from "~/server/db/schema";
import { eq } from "drizzle-orm";
import { isAdmin } from "~/app/actions";
import * as Schemas from "~/lib/schema/cv/category"
import { TRPCError, type inferRouterOutputs } from "@trpc/server";
import { z } from "zod";
export const CategoryRouter = router({
list: publicProcedure.query(async () => {
const categories = await db.query.cvCategory.findMany({
orderBy: (model, { desc }) => desc(model.name),
with: {
cvEntry: true
}
});
return categories;
}),
get: publicProcedure.input(Schemas.getSchema).query(async (opts) => {
const { input } = opts
const categories = await db.query.cvCategory.findMany({
with: {
cvEntry: true
},
where: eq(cvCategory.id, input.id),
limit: 1
})
if (categories[0] !== undefined) {
return categories[0]
} else {
return null
}
}),
delete: publicProcedure.input(z.string()).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
db.delete(cvCategory).where(eq(cvCategory.id,input)).execute()
}),
create: publicProcedure.input(Schemas.insertSchema).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
const category = await db.insert(cvCategory).values(input).returning().execute()
return category
}),
update: publicProcedure
.input(Schemas.updateRouteSchema)
.mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
const category = await db.update(cvCategory)
.set(input.update)
.returning()
.where(eq(cvCategory.id, input.by.id))
return category
})
})
export type CategoryRouterOutputs = inferRouterOutputs<typeof CategoryRouter>

View File

@@ -1,74 +0,0 @@
import { db } from "~/server/db";
import { publicProcedure, router } from "~/server/trpc";
import { cvEntry } from "~/server/db/schema";
import { eq } from "drizzle-orm";
import { isAdmin } from "~/app/actions";
import * as Schemas from "~/lib/schema/cv/entry"
import { TRPCError, type inferRouterOutputs } from "@trpc/server";
import { z } from "zod";
export const EntryRouter = router({
list: publicProcedure.query(async () => {
const entries = await db.query.cvEntry.findMany({
orderBy: (model, { desc }) => desc(model.toTime),
with: {
category: true
}
});
return entries;
}),
get: publicProcedure.input(Schemas.getSchema).query(async (opts) => {
const { input } = opts
const entries = await db.query.cvEntry.findMany({
with: {
category: true
},
where: eq(cvEntry.id, input.id),
limit: 1
})
if (entries[0] !== undefined) {
return entries[0]
} else {
return null
}
}),
delete: publicProcedure.input(z.string()).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
db.delete(cvEntry).where(eq(cvEntry.id,input)).execute()
}),
create: publicProcedure.input(Schemas.insertSchema).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
return await db.insert(cvEntry).values(input).returning().execute()
}),
update: publicProcedure
.input(Schemas.updateRouteSchema)
.mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
const entry = await db.update(cvEntry)
.set(input.update)
.returning()
.where(eq(cvEntry.id, input.by.id))
return entry
})
})
export type EntryRouterOutputs = inferRouterOutputs<typeof EntryRouter>

View File

@@ -1,12 +0,0 @@
import { router } from "~/server/trpc"
import { CategoryRouter } from "./category"
import { EntryRouter } from "./entry"
import { trpcCrudRouterFromDrizzleEntity } from "~/server/lib"
import * as schema from '~/server/db/schema'
const { router : categoryv2 } = trpcCrudRouterFromDrizzleEntity('cvCategory')
const { router : entryv2 } = trpcCrudRouterFromDrizzleEntity('cvEntry')
export const CvRouter = router({
category: categoryv2,
entry:entryv2
})

View File

@@ -1,75 +0,0 @@
import { publicProcedure, router } from "~/server/trpc"
import { db } from "~/server/db";
import * as Schemas from '~/lib/schema/project/project'
import { eq } from "drizzle-orm";
import { project } from "~/server/db/schema";
import { isAdmin } from "~/app/actions";
import z from "zod";
import { StackRouter } from "./techStack";
import { TRPCError, type inferRouterOutputs} from "@trpc/server";
import { trpcCrudRouterFromDrizzleEntity } from "~/server/lib";
const { router : project } = trpcCrudRouterFromDrizzleEntity('project')
const { router : techStack } = trpcCrudRouterFromDrizzleEntity('techStack')
export const ProjectRouter = router({
list: publicProcedure.query(async () => {
return await db.query.project.findMany({
orderBy: (model, {desc}) => desc(model.title),
with: {
techStack: true
}
});
}),
get: publicProcedure.input(Schemas.getSchema).query(async (opts) => {
const {input} = opts;
const projects = await db.query.project.findMany({
with: {
techStack: true
},
where: eq(project.id,input.id),
limit: 1
});
if (projects[0] !== undefined) {
return projects[0]
} else {
return null
}
}),
delete: publicProcedure.input(z.string()).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
db.delete(project).where(eq(project.id,input)).execute()
}),
create: publicProcedure.input(Schemas.insertSchema).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
return await db.insert(project).values(input).returning().execute();
}),
update: publicProcedure
.input(Schemas.updateRouteSchema)
.mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
return await db.update(project)
.set(input.update)
.returning()
.where(eq(project.id,input.by.id));
}),
stack: StackRouter,
})
export type ProjectRouterOutputs = inferRouterOutputs<typeof ProjectRouter>

View File

@@ -1,62 +0,0 @@
import { publicProcedure, router } from "~/server/trpc"
import { db } from "~/server/db";
import * as Schemas from '~/lib/schema/project/techStack'
import { eq } from "drizzle-orm";
import { techStack } from "~/server/db/schema";
import { isAdmin } from "~/app/actions";
import { TRPCError, type inferRouterOutputs} from "@trpc/server";
import z from "zod";
export const StackRouter = router({
list: publicProcedure.query(async () => {
return await db.query.techStack.findMany();
}),
get: publicProcedure.input(Schemas.getSchema).query(async (opts) => {
const {input} = opts;
const techStacks = await db.query.techStack.findMany({
where: eq(techStack.id,input.id),
limit: 1
});
if (techStacks[0] !== undefined) {
return techStacks[0]
} else {
return null
}
}),
delete: publicProcedure.input(z.string()).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
db.delete(techStack).where(eq(techStack.id,input)).execute()
}),
create: publicProcedure.input(Schemas.insertSchema).mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
return await db.insert(techStack).values(input).returning().execute();
}),
update: publicProcedure
.input(Schemas.updateRouteSchema)
.mutation(async (opts) => {
let admin = await isAdmin()
if (!admin) {
throw new TRPCError(
{ message: "Access denied", code: "FORBIDDEN", }
)
}
const { input } = opts;
return await db.update(techStack)
.set(input.update)
.returning()
.where(eq(techStack.id,input.by.id))
})
})
export type StackRouterOutputs = inferRouterOutputs<typeof StackRouter>