We have changed our licensing terms. Please visit this blog post to view details.

Other projects

Idm 6.41 — Serial Number

/** * 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;

while (attempts < maxAttempts) serial = buildSerial( prefix ); try const result = await pool.query( `INSERT INTO serial_numbers (serial) VALUES ($1) RETURNING id, serial`, [serial] ); return res.status(201).json(result.rows[0]); catch (err) // 23505 = unique_violation in Postgres if (err.code === '23505') attempts++; continue; // try a new random value console.error(err); return res.status(500).json( error: 'DB error' ); res.status(409).json( error: 'Could not generate unique serial after several tries' ); ); Serial Number Idm 6.41

/** * 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`; /** * POST /serials * Body: prefix

Stay Updated

Get the latest news, updates and what's coming next! Sign up for our Newsletter here.

Thank You! You are signed up.

There was an error while trying to send your request. Please try again.

ApexCharts.js will use the information you provide on this form to be in touch with you and to provide updates and marketing.