project router
This commit is contained in:
11
src/lib/schema/project/project.ts
Normal file
11
src/lib/schema/project/project.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { project } from "~/server/db/schema"
|
||||||
|
import { createInsertSchema, createUpdateSchema, createSelectSchema} from 'drizzle-zod'
|
||||||
|
import { z } from "zod";
|
||||||
|
export const selectSchema = createSelectSchema(project);
|
||||||
|
export const insertSchema = createInsertSchema(project);
|
||||||
|
export const updateSchema = createUpdateSchema(project);
|
||||||
|
export const getSchema = selectSchema.pick({id: true});
|
||||||
|
export const updateRouteSchema = z.object({
|
||||||
|
by: selectSchema.pick({id:true}),
|
||||||
|
update: updateSchema
|
||||||
|
})
|
||||||
11
src/lib/schema/project/techStack.ts
Normal file
11
src/lib/schema/project/techStack.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import { techStack } from "~/server/db/schema"
|
||||||
|
import { createInsertSchema, createUpdateSchema, createSelectSchema} from 'drizzle-zod'
|
||||||
|
import { z } from "zod";
|
||||||
|
export const selectSchema = createSelectSchema(techStack);
|
||||||
|
export const insertSchema = createInsertSchema(techStack);
|
||||||
|
export const updateSchema = createUpdateSchema(techStack);
|
||||||
|
export const getSchema = selectSchema.pick({id: true});
|
||||||
|
export const updateRouteSchema = z.object({
|
||||||
|
by: selectSchema.pick({id:true}),
|
||||||
|
update: updateSchema
|
||||||
|
})
|
||||||
@@ -54,6 +54,7 @@ export const cvEntryRelations = relations(cvEntry, ({one}) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const sourceTypeEnum = pgEnum('source_type',['open','closed'])
|
export const sourceTypeEnum = pgEnum('source_type',['open','closed'])
|
||||||
|
export const releaseStatus = pgEnum('release_status',['released','unreleased'])
|
||||||
export const stackItemEnum = pgEnum('stack_item',['drizzle','postgres','nextjs','react','servercomponents','php','laravel','reactnative','expo','mysql','nginx','protobuf','grpc'])
|
export const stackItemEnum = pgEnum('stack_item',['drizzle','postgres','nextjs','react','servercomponents','php','laravel','reactnative','expo','mysql','nginx','protobuf','grpc'])
|
||||||
|
|
||||||
export const project = createTable(
|
export const project = createTable(
|
||||||
@@ -62,10 +63,18 @@ export const project = createTable(
|
|||||||
id: d.uuid().primaryKey().notNull(),
|
id: d.uuid().primaryKey().notNull(),
|
||||||
title: d.varchar({length: 50}).notNull(),
|
title: d.varchar({length: 50}).notNull(),
|
||||||
sourceType: sourceTypeEnum(),
|
sourceType: sourceTypeEnum(),
|
||||||
|
releaseStatus: releaseStatus(),
|
||||||
|
stackId: d.uuid(),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
export const projectRelations = relations(project, ({one}) => ({
|
||||||
|
techStack: one(techStack, {
|
||||||
|
fields: [project.stackId],
|
||||||
|
references: [techStack.id],
|
||||||
|
})
|
||||||
|
}))
|
||||||
|
|
||||||
export const techStack = createTable(
|
export const techStack = createTable(
|
||||||
"tech_stack",
|
"tech_stack",
|
||||||
(d) => ({
|
(d) => ({
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import type { inferRouterOutputs } from "@trpc/server";
|
|||||||
import { router } from "../trpc";
|
import { router } from "../trpc";
|
||||||
import { CvRouter } from "./cv";
|
import { CvRouter } from "./cv";
|
||||||
import type { inferReactQueryProcedureOptions } from "@trpc/react-query";
|
import type { inferReactQueryProcedureOptions } from "@trpc/react-query";
|
||||||
|
import { ProjectRouter } from "./project";
|
||||||
|
|
||||||
export const trpcRouter = router({
|
export const trpcRouter = router({
|
||||||
cv: CvRouter
|
cv: CvRouter,
|
||||||
|
project: ProjectRouter
|
||||||
})
|
})
|
||||||
|
|
||||||
export type TrpcRouter = typeof trpcRouter
|
export type TrpcRouter = typeof trpcRouter
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ export const EntryRouter = router({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
const { input } = opts;
|
const { input } = opts;
|
||||||
const entry = await db.insert(cvEntry).values(input).returning().execute()
|
return await db.insert(cvEntry).values(input).returning().execute()
|
||||||
return entry
|
|
||||||
}),
|
}),
|
||||||
update: publicProcedure
|
update: publicProcedure
|
||||||
.input(Schemas.updateRouteSchema)
|
.input(Schemas.updateRouteSchema)
|
||||||
|
|||||||
72
src/server/routers/project/index.ts
Normal file
72
src/server/routers/project/index.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
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";
|
||||||
|
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>
|
||||||
62
src/server/routers/project/techStack.ts
Normal file
62
src/server/routers/project/techStack.ts
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
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>
|
||||||
Reference in New Issue
Block a user