feat: 完善员工门店软删除与密码管理

This commit is contained in:
湛兮
2026-05-26 18:01:52 +08:00
parent 6b31ea7bbf
commit e8f05513fd
19 changed files with 597 additions and 73 deletions
+63 -2
View File
@@ -22,8 +22,10 @@ interface EmployeeLoginRow extends RowDataPacket {
username: string;
password_hash: string;
display_name: string;
status: "ACTIVE" | "INACTIVE";
store_id: number;
store_name: string;
store_status: "ACTIVE" | "INACTIVE";
}
interface EmployeeRoleRow extends RowDataPacket {
@@ -67,6 +69,22 @@ export const authRepository = {
return rows[0] ? toSuperAdmin(rows[0]) : null;
},
async findByUsername(
username: string,
): Promise<SuperAdminWithPassword | null> {
const [rows] = await pool.execute<SuperAdminRow[]>(
`
SELECT id, username, password_hash, display_name, status, last_login_at, created_at, updated_at
FROM super_admins
WHERE username = ?
LIMIT 1
`,
[username],
);
return rows[0] ? toSuperAdmin(rows[0]) : null;
},
async findActiveById(id: number): Promise<SuperAdminWithPassword | null> {
const [rows] = await pool.execute<SuperAdminRow[]>(
`
@@ -102,8 +120,10 @@ export const authRepository = {
e.phone AS username,
e.password_hash,
e.name AS display_name,
e.status,
e.store_id,
s.name AS store_name
s.name AS store_name,
s.status AS store_status
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
WHERE e.phone = ?
@@ -127,6 +147,41 @@ export const authRepository = {
);
},
async findEmployeeByPhoneForLogin(
phone: string,
): Promise<EmployeeLoginAccount | null> {
const [rows] = await pool.execute<EmployeeLoginRow[]>(
`
SELECT
e.id,
e.phone AS username,
e.password_hash,
e.name AS display_name,
e.status,
e.store_id,
s.name AS store_name,
s.status AS store_status
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
WHERE e.phone = ?
AND e.deleted_at IS NULL
AND s.deleted_at IS NULL
LIMIT 1
`,
[phone],
);
if (!rows[0]) {
return null;
}
const rolesByEmployeeId = await this.findRolesByEmployeeIds([rows[0].id]);
return toEmployeeLoginAccount(
rows[0],
rolesByEmployeeId.get(rows[0].id) ?? [],
);
},
async findActiveEmployeeById(
id: number,
): Promise<EmployeeLoginAccount | null> {
@@ -137,8 +192,10 @@ export const authRepository = {
e.phone AS username,
e.password_hash,
e.name AS display_name,
e.status,
e.store_id,
s.name AS store_name
s.name AS store_name,
s.status AS store_status
FROM employees e
INNER JOIN stores s ON s.id = e.store_id
WHERE e.id = ?
@@ -189,6 +246,8 @@ export const authRepository = {
FROM employee_roles er
INNER JOIN roles r ON r.id = er.role_id
WHERE er.employee_id IN (${placeholders})
AND er.deleted_at IS NULL
AND r.deleted_at IS NULL
ORDER BY r.id ASC
`,
employeeIds,
@@ -217,8 +276,10 @@ function toEmployeeLoginAccount(
username: row.username,
passwordHash: row.password_hash,
displayName: row.display_name,
status: row.status,
storeId: row.store_id,
storeName: row.store_name,
storeStatus: row.store_status,
roles,
};
}