This commit is contained in:
gs committed 2026-09-25 22:08:37 +08:00
1 parent 01f9f2c514
commit dc23ea53ed
25 files changed
+3116 -176

No files matched your search

+30 -6
View File
@@ -71,18 +71,27 @@ router.post('/', async (req, res) => {
// PUT /api/babies/:babyId - Update baby profile
router.put('/:babyId', async (req, res) => {
const { babyId } = req.params;
const { name, gender, birthDate, themeColor } = req.body;
const { name, gender, birthDate, themeColor, defaultConfig } = req.body;
if (!name || !birthDate) {
return res.status(400).json({ success: false, error: '姓名与出生日期必填' });
}
const color = themeColor || '#3B82F6';
try {
await pool.query(`
UPDATE \`baby_profile\`
SET \`name\` = ?, \`gender\` = ?, \`birth_date\` = ?, \`theme_color\` = ?
WHERE \`baby_id\` = ?
`, [name, gender || 'boy', birthDate, color, babyId]);
const configJson = defaultConfig ? (typeof defaultConfig === 'string' ? defaultConfig : JSON.stringify(defaultConfig)) : null;
if (configJson !== null) {
await pool.query(`
UPDATE \`baby_profile\`
SET \`name\` = ?, \`gender\` = ?, \`birth_date\` = ?, \`theme_color\` = ?, \`default_config\` = ?
WHERE \`baby_id\` = ?
`, [name, gender || 'boy', birthDate, color, configJson, babyId]);
} else {
await pool.query(`
UPDATE \`baby_profile\`
SET \`name\` = ?, \`gender\` = ?, \`birth_date\` = ?, \`theme_color\` = ?
WHERE \`baby_id\` = ?
`, [name, gender || 'boy', birthDate, color, babyId]);
}
const [updated] = await pool.query('SELECT * FROM `baby_profile` WHERE `baby_id` = ?', [babyId]);
res.json({ success: true, data: updated[0] });
@@ -92,6 +101,21 @@ router.put('/:babyId', async (req, res) => {
}
});
// PUT /api/babies/:babyId/defaults - Update default config for baby
router.put('/:babyId/defaults', async (req, res) => {
const { babyId } = req.params;
const { defaultConfig } = req.body;
try {
const configJson = typeof defaultConfig === 'string' ? defaultConfig : JSON.stringify(defaultConfig || {});
await pool.query('UPDATE `baby_profile` SET `default_config` = ? WHERE `baby_id` = ?', [configJson, babyId]);
const [updated] = await pool.query('SELECT * FROM `baby_profile` WHERE `baby_id` = ?', [babyId]);
res.json({ success: true, message: '宝宝默认行为配置已更新', data: updated[0] });
} catch (err) {
console.error('Error updating baby defaults:', err);
res.status(500).json({ success: false, error: err.message });
}
});
// POST /api/babies/:babyId/default - Set as default baby
router.post('/:babyId/default', async (req, res) => {
const { babyId } = req.params;