TypeScript/Bun project scaffold
- Stack: Bun, Hono, Drizzle ORM, Zod, Handlebars, Pino - Models: ticket, queue, transaction, scrip, template, custom_field, user, lifecycle - Scrip engine: prepare/commit two-phase dispatch, template rendering, mock actions - Lifecycle validator: state machine transition validation with wildcard support - Routes: health, tickets (full CRUD + preview + transactions), queues, scrips, custom-fields, lifecycles - Middleware: Pino logging, error handler - Database: Drizzle ORM schema + initial migration (10 tables) - Type-check: passes (tsc --noEmit, zero errors)
This commit is contained in:
38
src/routes/lifecycles.ts
Normal file
38
src/routes/lifecycles.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { Hono } from 'hono';
|
||||
import { HTTPException } from 'hono/http-exception';
|
||||
import type { Db } from '../db/index.ts';
|
||||
import { lifecycles } from '../db/schema.ts';
|
||||
import { asc } from 'drizzle-orm';
|
||||
|
||||
export function createLifecyclesRouter(db: Db): Hono {
|
||||
const router = new Hono();
|
||||
|
||||
router.get('/', async (c) => {
|
||||
const result = await db.query.lifecycles.findMany({
|
||||
orderBy: asc(lifecycles.name),
|
||||
});
|
||||
return c.json(result);
|
||||
});
|
||||
|
||||
router.post('/', async (c) => {
|
||||
const body = await c.req.json();
|
||||
const { name, definition } = body;
|
||||
|
||||
if (!name || !definition) {
|
||||
throw new HTTPException(400, { message: 'name and definition are required' });
|
||||
}
|
||||
|
||||
const [lifecycle] = await db.insert(lifecycles).values({
|
||||
name,
|
||||
definition,
|
||||
}).returning();
|
||||
|
||||
if (!lifecycle) {
|
||||
throw new HTTPException(500, { message: 'Failed to create lifecycle' });
|
||||
}
|
||||
|
||||
return c.json(lifecycle, 201);
|
||||
});
|
||||
|
||||
return router;
|
||||
}
|
||||
Reference in New Issue
Block a user