feat: 增加员工端工作台后端能力

This commit is contained in:
湛兮
2026-06-02 12:23:00 +08:00
parent 667dc411fc
commit 98cea63203
33 changed files with 3021 additions and 18 deletions
+22 -3
View File
@@ -26,6 +26,7 @@ interface EmployeeLoginRow extends RowDataPacket {
store_id: number;
store_name: string;
store_status: "ACTIVE" | "INACTIVE";
must_change_password: 0 | 1 | null;
}
interface EmployeeRoleRow extends RowDataPacket {
@@ -123,9 +124,11 @@ export const authRepository = {
e.status,
e.store_id,
s.name AS store_name,
s.status AS store_status
s.status AS store_status,
eps.must_change_password
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
LEFT JOIN employee_password_states eps ON eps.employee_id = e.id
WHERE e.phone = ?
AND e.status = 'ACTIVE'
AND e.deleted_at IS NULL
@@ -160,9 +163,11 @@ export const authRepository = {
e.status,
e.store_id,
s.name AS store_name,
s.status AS store_status
s.status AS store_status,
eps.must_change_password
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
LEFT JOIN employee_password_states eps ON eps.employee_id = e.id
WHERE e.phone = ?
AND e.deleted_at IS NULL
AND s.deleted_at IS NULL
@@ -195,9 +200,11 @@ export const authRepository = {
e.status,
e.store_id,
s.name AS store_name,
s.status AS store_status
s.status AS store_status,
eps.must_change_password
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
LEFT JOIN employee_password_states eps ON eps.employee_id = e.id
WHERE e.id = ?
AND e.status = 'ACTIVE'
AND e.deleted_at IS NULL
@@ -230,6 +237,17 @@ export const authRepository = {
);
},
async updateEmployeePasswordHash(id: number, passwordHash: string): Promise<void> {
await pool.execute(
`
UPDATE employees
SET password_hash = ?
WHERE id = ? AND deleted_at IS NULL
`,
[passwordHash, id],
);
},
async findRolesByEmployeeIds(
employeeIds: number[],
): Promise<Map<number, EmployeeLoginAccount["roles"]>> {
@@ -280,6 +298,7 @@ function toEmployeeLoginAccount(
storeId: row.store_id,
storeName: row.store_name,
storeStatus: row.store_status,
mustChangePassword: row.must_change_password === 1,
roles,
};
}