(Feat-Fix): Fixed the check-in, check-out system, added a contractor payment system.

This commit is contained in:
2025-12-21 08:54:47 +00:00
parent 8fcbfe2a47
commit 04e25527e8
7 changed files with 705 additions and 83 deletions

View File

@@ -138,34 +138,34 @@ router.post(
return;
}
// Verify employee exists
let employeeQuery = "SELECT * FROM users WHERE id = ? AND role = ?";
const employeeParams: unknown[] = [employeeId, "Employee"];
// Verify user exists and is Employee or Contractor
let userQuery = "SELECT * FROM users WHERE id = ? AND role IN ('Employee', 'Contractor')";
const userParams: unknown[] = [employeeId];
if (currentUser.role === "Supervisor") {
employeeQuery += " AND department_id = ?";
employeeParams.push(currentUser.departmentId);
userQuery += " AND department_id = ?";
userParams.push(currentUser.departmentId);
}
const employees = await db.query<User[]>(employeeQuery, employeeParams);
const users = await db.query<User[]>(userQuery, userParams);
if (employees.length === 0) {
if (users.length === 0) {
ctx.response.status = 403;
ctx.response.body = {
error: "Employee not found or not in your department",
error: "User not found, not an Employee/Contractor, or not in your department",
};
return;
}
// Check if already checked in today
const existing = await db.query<Attendance[]>(
"SELECT * FROM attendance WHERE employee_id = ? AND work_date = ? AND status = ?",
[employeeId, workDate, "CheckedIn"],
// Check if there's an active check-in (not yet checked out) for today
const activeCheckIn = await db.query<Attendance[]>(
"SELECT * FROM attendance WHERE employee_id = ? AND work_date = ? AND status = 'CheckedIn'",
[employeeId, workDate],
);
if (existing.length > 0) {
if (activeCheckIn.length > 0) {
ctx.response.status = 400;
ctx.response.body = { error: "Employee already checked in today" };
ctx.response.body = { error: "User has an active check-in. Please check out first before checking in again." };
return;
}