/** * GET /serials/:id */ app.get('/serials/:id', async (req, res) => const id = req.params; const result = await pool.query('SELECT id, serial, created_at FROM serial_numbers WHERE id = $1', [ id, ]); if (result.rowCount === 0) return res.status(404).json( error: 'Serial not found' ); res.json(result.rows[0]); );
/* ---- start server ---- */ const PORT = process.env.PORT ?? 3000; app.listen(PORT, () => console.log(`🚀 Serial IDM 6.41 API listening on $PORT`)); Serial Number Idm 6.41
/** * POST /serials * Body: prefix?: string * Returns: id, serial */ app.post('/serials', async (req, res) => const prefix = req.body; let serial; let attempts = 0; const maxAttempts = 5; /** * GET /serials/:id */ app
/** * Utility: builds a serial like "PRD-2024-ABCD-1234" */ function buildSerial( prefix = 'PRD', year = new Date().getFullYear() ) const random = crypto.randomBytes(2).toString('hex').toUpperCase(); // 4 chars const seq = Math.floor(Math.random() * 10000) .toString() .padStart(4, '0'); return `$prefix-$year-$random-$seq`; /** * GET /serials/:id */ app.get('/serials/:id'
const pool = new Pool( connectionString: process.env.DATABASE_URL, // e.g., postgres://user:pw@host/db );
const app = express(); app.use(express.json());