Files
performance-evaluation-system/backend/update-accounts.ts
2026-04-11 11:51:54 +08:00

35 lines
1.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import * as dotenv from 'dotenv';
dotenv.config();
import pool from './src/config/database';
import bcrypt from 'bcryptjs';
async function run() {
const hash = await bcrypt.hash('123456', 10);
// 删除 mgr002
await pool.query('DELETE FROM user WHERE username = ?', ['mgr002']);
console.log('删除 mgr002');
// 更新 gm001 → lister / 李总 / 总经理
await pool.query(
'UPDATE user SET username = ?, name = ?, password = ? WHERE username = ?',
['lister', '李总', hash, 'gm001']
);
console.log('更新 gm001 → lister');
// 更新 mgr001 → xinxin / 孙薪薪 / 管理层
await pool.query(
'UPDATE user SET username = ?, name = ?, password = ? WHERE username = ?',
['xinxin', '孙薪薪', hash, 'mgr001']
);
console.log('更新 mgr001 → xinxin');
const [rows] = await pool.query<any[]>('SELECT user_id, username, name, role, department, position FROM user ORDER BY role');
console.log('\n当前账号');
console.table(rows);
await pool.end();
}
run().catch(console.error);