diff --git a/.phase16-state.json b/.phase16-state.json index bf07475..b5312af 100644 --- a/.phase16-state.json +++ b/.phase16-state.json @@ -1,9 +1,10 @@ { "completed_features": [], - "current_feature": "recent-projects-quick-access", + "current_feature": "time-entry-templates", "started_at": "2026-05-23T07:08:48.804883", "attempted_features": [ "pinned-customers", - "smart-suggestions" + "smart-suggestions", + "recent-projects-quick-access" ] } \ No newline at end of file diff --git a/GENERATION_LOG.md b/GENERATION_LOG.md index e32b10b..3e0ee55 100644 --- a/GENERATION_LOG.md +++ b/GENERATION_LOG.md @@ -1939,3 +1939,22 @@ 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. Argument of type 'Promise' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy +- `07:15:09` **INFO** Committed feature recent-projects-quick-access +- `07:15:09` **INFO** Pushed: rc=0 + +## Phase-3 Feature: time-entry-templates (2026-05-23 07:15:09) + +- `07:15:09` **INFO** Description: Wiederverwendbare TimeEntry-Templates (gespeicherte description+project) +- `07:15:09` **INFO** Generating apps/api/src/db/schema.ts (ERWEITERT — füge `timeEntryTemplates` pgTable: id, userId, name (label…) +- `07:15:48` **INFO** wrote 4609 chars in 39.3s (attempt 1) +- `07:15:48` **INFO** Generating apps/api/src/routes/time-entry-templates.ts (Fastify-Plugin /api/time-entry-templates. CRUD GET/POST/PATCH/DELETE. …) +- `07:16:14` **INFO** wrote 2845 chars in 25.2s (attempt 1) +- `07:16:14` **INFO** Running tsc --noEmit on api… +- `07:16:15` **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' is not assignable to parameter of type 'FastifyPluginCallback<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, 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' is not assignable to parameter of type 'FastifyPluginAsync<{ limits: { fileSize: number; }; }, RawServerDefault, FastifyTypeProvider, FastifyBaseLogger>'. + Type 'Promise' provides no match for the signature '(instance: FastifyInstance, FastifyBaseLogger, FastifyTy diff --git a/apps/api/src/db/schema.ts b/apps/api/src/db/schema.ts index 70c32dd..5200351 100644 --- a/apps/api/src/db/schema.ts +++ b/apps/api/src/db/schema.ts @@ -51,6 +51,16 @@ export const timeEntries = pgTable("time_entries", { createdAt: timestamp("created_at").notNull().defaultNow() }) +export const timeEntryTemplates = pgTable("time_entry_templates", { + id: uuid("id").primaryKey().defaultRandom(), + userId: uuid("user_id").references(() => users.id, { onDelete: "cascade" }), + name: text("name").notNull(), + description: text("description"), + projectId: uuid("project_id").references(() => projects.id, { onDelete: "set null" }), + defaultDurationMinutes: integer("default_duration_minutes"), + createdAt: timestamp("created_at").notNull().defaultNow() +}) + export const appSettings = pgTable("app_settings", { id: uuid("id").primaryKey().defaultRandom(), workspaceName: text("workspace_name").notNull().default("EmberClone"), @@ -102,12 +112,4 @@ export const savedViews = pgTable("saved_views", { entityType: text("entity_type").notNull(), config: text("config").notNull(), createdAt: timestamp("created_at").notNull().defaultNow() -}) -export const passwordResetTokens = pgTable("password_reset_tokens", { - id: uuid("id").primaryKey().defaultRandom(), - userId: uuid("user_id").notNull().references(() => users.id, { onDelete: "cascade" }), - tokenHash: text("token_hash").notNull(), - expiresAt: timestamp("expires_at").notNull(), - usedAt: timestamp("used_at"), - createdAt: timestamp("created_at").notNull().defaultNow(), -}) +}) \ No newline at end of file diff --git a/apps/api/src/routes/time-entry-templates.ts b/apps/api/src/routes/time-entry-templates.ts new file mode 100644 index 0000000..5c6e167 --- /dev/null +++ b/apps/api/src/routes/time-entry-templates.ts @@ -0,0 +1,106 @@ +import { FastifyInstance } from "fastify" +import { db } from "../db" +import { timeEntryTemplates } from "../db/schema" +import { eq, and, desc } from "drizzle-orm" +import { z } from "zod" + +const TemplateSchema = z.object({ + name: z.string().min(1), + description: z.string().optional(), + durationMinutes: z.number().int().positive() +}) + +const TemplateUpdateSchema = TemplateSchema.partial() + +export default async function timeEntryTemplateRoutes(fastify: FastifyInstance) { + fastify.addHook("preHandler", async (request, reply) => { + try { + await request.jwtVerify() + } catch (err) { + return reply.code(401).send({ message: "Unauthorized" }) + } + }) + + fastify.get("/", async (request, reply) => { + const user = request.user as any + const userId = user?.id + + const results = await db + .select() + .from(timeEntryTemplates) + .where(eq(timeEntryTemplates.userId, userId)) + .orderBy(timeEntryTemplates.name) + + return results + }) + + fastify.get("/:id", async (request, reply) => { + const { id } = request.params as { id: string } + const user = request.user as any + const userId = user?.id + + const [template] = await db + .select() + .from(timeEntryTemplates) + .where(and(eq(timeEntryTemplates.id, id), eq(timeEntryTemplates.userId, userId))) + .limit(1) + + if (!template) { + return reply.code(404).send({ message: "Template not found" }) + } + + return template + }) + + fastify.post("/", async (request, reply) => { + const user = request.user as any + const userId = user?.id + const body = TemplateSchema.parse(request.body) + + const [template] = await db + .insert(timeEntryTemplates) + .values({ + ...body, + userId: userId + }) + .returning() + + return reply.code(201).send(template) + }) + + fastify.patch("/:id", async (request, reply) => { + const { id } = request.params as { id: string } + const user = request.user as any + const userId = user?.id + const body = TemplateUpdateSchema.parse(request.body) + + const [template] = await db + .update(timeEntryTemplates) + .set(body) + .where(and(eq(timeEntryTemplates.id, id), eq(timeEntryTemplates.userId, userId))) + .returning() + + if (!template) { + return reply.code(404).send({ message: "Template not found" }) + } + + return template + }) + + fastify.delete("/:id", async (request, reply) => { + const { id } = request.params as { id: string } + const user = request.user as any + const userId = user?.id + + const [template] = await db + .delete(timeEntryTemplates) + .where(and(eq(timeEntryTemplates.id, id), eq(timeEntryTemplates.userId, userId))) + .returning() + + if (!template) { + return reply.code(404).send({ message: "Template not found" }) + } + + return reply.code(204).send() + }) +} \ No newline at end of file