36 lines
1.0 KiB
JavaScript
36 lines
1.0 KiB
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
const db = require('../db');
|
|
const camelotToMusicKey = require('../../shared/camelot-to-musickey');
|
|
|
|
// POST /api/tracks/correct
|
|
// Save user corrections for key and bpm to PostgreSQL
|
|
router.post('/correct', async (req, res) => {
|
|
const { artist, title, camelotKey, bpm } = req.body;
|
|
|
|
if (!artist || !title || !camelotKey || !bpm) {
|
|
return res.status(400).json({ error: 'Missing required fields (artist, title, camelotKey, bpm)' });
|
|
}
|
|
|
|
try {
|
|
const musicKey = camelotToMusicKey[camelotKey] || '';
|
|
const updated = await db.correctTrack({
|
|
artist: artist.trim(),
|
|
title: title.trim(),
|
|
camelot_key: camelotKey.trim(),
|
|
bpm: parseInt(bpm, 10),
|
|
music_key: musicKey
|
|
});
|
|
|
|
res.json({
|
|
status: 'success',
|
|
data: updated
|
|
});
|
|
} catch (err) {
|
|
console.error('[Tracks] Error correcting track:', err.message);
|
|
res.status(500).json({ error: 'Failed to save correction to database' });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|