Files
tessera/src/routes/queues.ts
Gjermund Høsøien Wiggen 4e285f8c4d feat: queues have default team, tickets inherit it
- team_id on queues table (optional, can be overridden per-ticket)
- Ticket creation auto-sets team_id from the queue's default
- Queue admin form has team selector (scrip flow node 03)
- Queue API (POST/PATCH) accepts team_id

No enforcement — just a helpful default. Teams and queues
are loosely coupled, not hierarchically locked.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-09 14:47:20 +02:00

64 lines
1.9 KiB
TypeScript

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, eq } from 'drizzle-orm';
import { CreateQueueSchema } from '../models/queue.ts';
export function createQueuesRouter(db: Db): Hono {
const router = new Hono();
router.get('/', async (c) => {
const result = await db.query.queues.findMany({
orderBy: asc(queues.name),
});
return c.json(result);
});
router.post('/', async (c) => {
const body = await c.req.json();
const parsed = CreateQueueSchema.parse(body);
const [queue] = await db.insert(queues).values({
name: parsed.name,
description: parsed.description ?? null,
lifecycle_id: parsed.lifecycle_id ?? null,
team_id: parsed.team_id ?? null,
}).returning();
if (!queue) {
throw new HTTPException(500, { message: 'Failed to create queue' });
}
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;
if (body.team_id !== undefined) updateData.team_id = body.team_id || null;
const [updated] = await db.update(queues)
.set(updateData)
.where(eq(queues.id, id))
.returning();
return c.json(updated);
});
return router;
}