feat: add users and templates routes, enhance existing API routes
New routes: - GET /users — list all users - GET/POST /templates — list and create templates - PATCH /templates/:id — update template - POST /templates/preview — render template with ticket/demo context Enhanced routes: - tickets: custom field support on create, status classification helper - custom-fields: PATCH endpoint, auto-generate short key from name - lifecycles: PATCH endpoint - queues: PATCH endpoint Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ import { Hono } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import type { Db } from '../db/index.ts';
|
||||
import { queues } from '../db/schema.ts';
|
||||
import { asc } from 'drizzle-orm';
|
||||
import { asc, eq } from 'drizzle-orm';
|
||||
import { CreateQueueSchema } from '../models/queue.ts';
|
||||
|
||||
export function createQueuesRouter(db: Db): Hono {
|
||||
@@ -32,5 +32,30 @@ export function createQueuesRouter(db: Db): Hono {
|
||||
return c.json(queue, 201);
|
||||
});
|
||||
|
||||
router.patch('/:id', async (c) => {
|
||||
const id = c.req.param('id');
|
||||
const body = await c.req.json();
|
||||
|
||||
const existing = await db.query.queues.findFirst({
|
||||
where: eq(queues.id, id),
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
throw new HTTPException(404, { message: 'Queue not found' });
|
||||
}
|
||||
|
||||
const updateData: Partial<typeof queues.$inferInsert> = {};
|
||||
if (body.name !== undefined) updateData.name = String(body.name);
|
||||
if (body.description !== undefined) updateData.description = body.description ? String(body.description) : null;
|
||||
if (body.lifecycle_id !== undefined) updateData.lifecycle_id = body.lifecycle_id || null;
|
||||
|
||||
const [updated] = await db.update(queues)
|
||||
.set(updateData)
|
||||
.where(eq(queues.id, id))
|
||||
.returning();
|
||||
|
||||
return c.json(updated);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user