feat(project-templates): Wiederverwendbare Project-Templates (admin) [tsc:fail]

This commit is contained in:
Dennis (via Claude+Gemma) 2026-05-23 06:16:21 +02:00
parent 42f57beb08
commit 087ee2c83a
5 changed files with 274 additions and 2 deletions

View File

@ -1,8 +1,9 @@
{ {
"completed_features": [], "completed_features": [],
"current_feature": "customer-tags", "current_feature": "project-templates",
"started_at": "2026-05-23T06:10:51.530595", "started_at": "2026-05-23T06:10:51.530595",
"attempted_features": [ "attempted_features": [
"markdown-notes-time-entry" "markdown-notes-time-entry",
"customer-tags"
] ]
} }

View File

@ -1189,3 +1189,24 @@ src/index.ts(27,25): error TS2769: No overload matches this call.
Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error. Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTy Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTy
- `06:14:38` **INFO** Committed feature customer-tags
- `06:14:38` **INFO** Pushed: rc=0
## Phase-3 Feature: project-templates (2026-05-23 06:14:38)
- `06:14:38` **INFO** Description: Wiederverwendbare Project-Templates (admin)
- `06:14:38` **INFO** Generating apps/api/src/db/schema.ts (ERWEITERT — füge `projectTemplates` Tabelle: id (uuid pk), name (text)…)
- `06:15:07` **INFO** wrote 3376 chars in 28.9s (attempt 1)
- `06:15:07` **INFO** Generating apps/api/src/routes/project-templates.ts (Fastify-Plugin /api/project-templates. CRUD, admin-only via preHandler…)
- `06:15:29` **INFO** wrote 2492 chars in 22.0s (attempt 1)
- `06:15:29` **INFO** Generating apps/web/src/pages/ProjectTemplates.tsx (ProjectTemplates-Page (admin-only). Liste + Create-Form (name, default…)
- `06:16:19` **INFO** wrote 6105 chars in 50.4s (attempt 1)
- `06:16:19` **INFO** Running tsc --noEmit on api…
- `06:16:21` **WARN** tsc errors:
src/index.ts(27,25): error TS2769: No overload matches this call.
Overload 1 of 3, '(plugin: FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProvider>, opts: { ...; }, done: (err?: Error | undefined) => void): void'.
Overload 2 of 3, '(plugin: FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
Argument of type 'Promise<FastifyMultipartPlugin>' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'.
Type 'Promise<FastifyMultipartPlugin>' provides no match for the signature '(instance: FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTy

View File

@ -31,6 +31,14 @@ export const projects = pgTable("projects", {
createdAt: timestamp("created_at").notNull().defaultNow() createdAt: timestamp("created_at").notNull().defaultNow()
}) })
export const projectTemplates = pgTable("project_templates", {
id: uuid("id").primaryKey().defaultRandom(),
name: text("name").notNull(),
defaultBillable: boolean("default_billable").notNull().default(true),
estimatedHours: integer("estimated_hours"),
createdAt: timestamp("created_at").notNull().defaultNow()
})
export const timeEntries = pgTable("time_entries", { export const timeEntries = pgTable("time_entries", {
id: uuid("id").primaryKey().defaultRandom(), id: uuid("id").primaryKey().defaultRandom(),
userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }), userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }),

View File

@ -0,0 +1,98 @@
import { FastifyInstance } from "fastify"
import { db } from "../db"
import { projectTemplates } from "../db/schema"
import { eq } from "drizzle-orm"
import { z } from "zod"
const ProjectTemplateSchema = z.object({
name: z.string().min(1),
description: z.string().optional(),
})
const ProjectTemplateUpdateSchema = ProjectTemplateSchema.partial()
export default async function projectTemplateRoutes(fastify: FastifyInstance) {
fastify.addHook("preHandler", async (request, reply) => {
try {
await request.jwtVerify()
} catch (err) {
return reply.code(401).send({ message: "Unauthorized" })
}
const user = request.user as any
if (user?.role !== "admin") {
return reply.code(403).send({ message: "Admin privileges required" })
}
})
fastify.get("/", async (request, reply) => {
const results = await db
.select()
.from(projectTemplates)
.orderBy(projectTemplates.name)
return results
})
fastify.get("/:id", async (request, reply) => {
const { id } = request.params as { id: string }
const [template] = await db
.select()
.from(projectTemplates)
.where(eq(projectTemplates.id, id))
.limit(1)
if (!template) {
return reply.code(404).send({ message: "Project template not found" })
}
return template
})
fastify.post("/", async (request, reply) => {
const body = ProjectTemplateSchema.parse(request.body)
const [template] = await db
.insert(projectTemplates)
.values({
name: body.name,
description: body.description,
})
.returning()
return reply.code(201).send(template)
})
fastify.patch("/:id", async (request, reply) => {
const { id } = request.params as { id: string }
const body = ProjectTemplateUpdateSchema.parse(request.body)
const [template] = await db
.update(projectTemplates)
.set(body)
.where(eq(projectTemplates.id, id))
.returning()
if (!template) {
return reply.code(404).send({ message: "Project template not found" })
}
return template
})
fastify.delete("/:id", async (request, reply) => {
const { id } = request.params as { id: string }
const [template] = await db
.delete(projectTemplates)
.where(eq(projectTemplates.id, id))
.returning()
if (!template) {
return reply.code(404).send({ message: "Project template not found" })
}
return reply.code(204).send()
})
}

View File

@ -0,0 +1,144 @@
import { useState } from "react"
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"
import { api } from "../lib/api"
export default function ProjectTemplates() {
const queryClient = useQueryClient()
const [name, setName] = useState("")
const [defaultBillable, setDefaultBillable] = useState(true)
const [estimatedHours, setEstimatedHours] = useState<string>("")
const { data: templates, isLoading, isError } = useQuery({
queryKey: ["projectTemplates"],
queryFn: () => api.listProjectTemplates()
})
const createMutation = useMutation({
mutationFn: (payload: { name: string; defaultBillable: boolean; estimatedHours: number }) =>
api.createProjectTemplate(payload),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["projectTemplates"] })
setName("")
setDefaultBillable(true)
setEstimatedHours("")
}
})
const deleteMutation = useMutation({
mutationFn: (id: string) => api.deleteProjectTemplate(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["projectTemplates"] })
}
})
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault()
if (!name.trim()) return
createMutation.mutate({
name,
defaultBillable,
estimatedHours: parseFloat(estimatedHours) || 0
})
}
if (isLoading) return <div className="p-6 text-gray-500">Loading templates...</div>
if (isError) return <div className="p-6 text-red-500">Error loading templates.</div>
return (
<div className="p-6 max-w-6xl mx-auto space-y-8">
<header>
<h1 className="text-2xl font-bold text-gray-900">Project Templates</h1>
<p className="text-gray-500">Define standard project configurations for quick setup</p>
</header>
<section className="bg-white p-6 rounded-lg border border-gray-200 shadow-sm">
<h2 className="text-lg font-semibold mb-4">Create New Template</h2>
<form onSubmit={handleSubmit} className="grid grid-cols-1 md:grid-cols-4 gap-4 items-end">
<div className="md:col-span-1">
<label className="block text-sm font-medium text-gray-700 mb-1">Template Name</label>
<input
type="text"
required
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 outline-none"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder="e.g. Standard Web Project"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Est. Hours</label>
<input
type="number"
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 outline-none"
value={estimatedHours}
onChange={(e) => setEstimatedHours(e.target.value)}
placeholder="0"
/>
</div>
<div className="flex items-center h-10">
<input
type="checkbox"
id="billable"
className="w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"
checked={defaultBillable}
onChange={(e) => setDefaultBillable(e.target.checked)}
/>
<label htmlFor="billable" className="ml-2 text-sm font-medium text-gray-700">
Default Billable
</label>
</div>
<button
type="submit"
disabled={createMutation.isPending}
className="bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700 transition-colors disabled:bg-blue-300 font-medium text-sm"
>
{createMutation.isPending ? "Saving..." : "Create Template"}
</button>
</form>
</section>
<section className="bg-white rounded-lg border border-gray-200 shadow-sm overflow-hidden">
<table className="w-full text-left border-collapse">
<thead className="bg-gray-50 border-b border-gray-200">
<tr>
<th className="px-6 py-3 text-xs font-semibold text-gray-500 uppercase tracking-wider">Name</th>
<th className="px-6 py-3 text-xs font-semibold text-gray-500 uppercase tracking-wider">Est. Hours</th>
<th className="px-6 py-3 text-xs font-semibold text-gray-500 uppercase tracking-wider">Billable</th>
<th className="px-6 py-3 text-xs font-semibold text-gray-500 uppercase tracking-wider text-right">Actions</th>
</tr>
</thead>
<tbody className="divide-y divide-gray-200">
{templates?.length === 0 && (
<tr>
<td colSpan={4} className="px-6 py-8 text-center text-gray-500">No templates found.</td>
</tr>
)}
{templates?.map((t) => (
<tr key={t.id} className="hover:bg-gray-50 transition-colors">
<td className="px-6 py-4 text-sm font-medium text-gray-900">{t.name}</td>
<td className="px-6 py-4 text-sm text-gray-600">{t.estimatedHours}h</td>
<td className="px-6 py-4 text-sm text-gray-600">
{t.defaultBillable ? (
<span className="px-2 py-1 text-xs font-medium bg-green-100 text-green-700 rounded-full">Yes</span>
) : (
<span className="px-2 py-1 text-xs font-medium bg-gray-100 text-gray-600 rounded-full">No</span>
)}
</td>
<td className="px-6 py-4 text-right">
<button
onClick={() => {
if (confirm("Delete this template?")) deleteMutation.mutate(t.id)
}}
className="text-red-600 hover:text-red-800 text-sm font-medium"
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</section>
</div>
)
}