联动部门更改
This commit is contained in:
@@ -198,6 +198,14 @@ async function update(req, res) {
|
||||
params.push(id)
|
||||
await pool.query(`UPDATE employees SET ${sets.join(', ')} WHERE id = ?`, params)
|
||||
|
||||
// 部门联动:员工部门变更时同步更新关联用户的部门
|
||||
if (req.body.department !== undefined) {
|
||||
const [[dept]] = await pool.query('SELECT id FROM departments WHERE description = ?', [req.body.department])
|
||||
if (dept) {
|
||||
await pool.query('UPDATE users SET department_id = ? WHERE employee_id = ?', [dept.id, id])
|
||||
}
|
||||
}
|
||||
|
||||
const [rows] = await pool.query('SELECT * FROM employees WHERE id = ?', [id])
|
||||
res.json({ code: 0, message: 'ok', data: rows[0] })
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user