screentinker/server/routes/provisioning.js
ScreenTinker 1594a9d4a4 Initial open source release
ScreenTinker - open source digital signage management software.
MIT License, all features included, no license gates.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 12:14:53 -05:00

24 lines
844 B
JavaScript

const express = require('express');
const router = express.Router();
const { db } = require('../db/database');
// Provision (pair) a device by entering its pairing code
router.post('/', (req, res) => {
const { pairing_code } = req.body;
if (!pairing_code) return res.status(400).json({ error: 'pairing_code required' });
const device = db.prepare('SELECT * FROM devices WHERE pairing_code = ?').get(pairing_code);
if (!device) return res.status(404).json({ error: 'No device found with that pairing code' });
// Clear pairing code and set online
db.prepare(`
UPDATE devices SET pairing_code = NULL, status = 'online', updated_at = strftime('%s','now')
WHERE id = ?
`).run(device.id);
const updated = db.prepare('SELECT * FROM devices WHERE id = ?').get(device.id);
res.json(updated);
});
module.exports = router;