fix: remove as-any casts, type Dashboard data properly
- Route handlers: add exhaustive return after error checks so TypeScript narrows the union and result properties are accessible without casts - attendance.service: use Prisma.attendanceGetPayload for included relations - projects.service: remove unnecessary cast on orders relation - Dashboard.tsx: replace Record<string,any> with proper DashData interface Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import { attendance_leave_type } from "@prisma/client";
|
||||
import { attendance_leave_type, Prisma } from "@prisma/client";
|
||||
import prisma from "../config/database";
|
||||
import { getBusinessDaysInMonth } from "../utils/czech-holidays";
|
||||
|
||||
type AttendanceWithRelations = Prisma.attendanceGetPayload<{
|
||||
include: {
|
||||
users: { select: { id: true; first_name: true; last_name: true } };
|
||||
attendance_project_logs: true;
|
||||
};
|
||||
}>;
|
||||
|
||||
const VALID_LEAVE_TYPES = [
|
||||
"work",
|
||||
"vacation",
|
||||
@@ -717,13 +724,13 @@ export async function getPrintData(
|
||||
const fundHours = getBusinessDaysInMonth(yr, mo - 1) * 8;
|
||||
|
||||
// Load project names for enrichment
|
||||
const typedRecords = records as AttendanceWithRelations[];
|
||||
|
||||
const projectIds = [
|
||||
...new Set(
|
||||
records
|
||||
typedRecords
|
||||
.flatMap(
|
||||
(r) =>
|
||||
(r as any).attendance_project_logs?.map((l: any) => l.project_id) ||
|
||||
[],
|
||||
(r) => r.attendance_project_logs?.map((l) => l.project_id) || [],
|
||||
)
|
||||
.filter(Boolean),
|
||||
),
|
||||
@@ -743,10 +750,10 @@ export async function getPrintData(
|
||||
|
||||
// Group records by user and calculate totals
|
||||
const userTotals: Record<string, Record<string, unknown>> = {};
|
||||
for (const rec of records) {
|
||||
for (const rec of typedRecords) {
|
||||
const uid = String(rec.user_id);
|
||||
if (!userTotals[uid]) {
|
||||
const u = (rec as any).users;
|
||||
const u = rec.users;
|
||||
userTotals[uid] = {
|
||||
name: u ? `${u.first_name} ${u.last_name}`.trim() : `User #${uid}`,
|
||||
minutes: 0,
|
||||
@@ -765,7 +772,7 @@ export async function getPrintData(
|
||||
|
||||
// Build record with project_logs for frontend
|
||||
const projectLogs =
|
||||
(rec as any).attendance_project_logs?.map((log: any) => ({
|
||||
rec.attendance_project_logs?.map((log) => ({
|
||||
project_id: log.project_id,
|
||||
project_name: projectMap[log.project_id] || null,
|
||||
hours: log.hours,
|
||||
|
||||
@@ -58,7 +58,7 @@ export async function listProjects(params: ListProjectsParams) {
|
||||
responsible_user_name: p.users
|
||||
? `${p.users.first_name} ${p.users.last_name}`.trim()
|
||||
: null,
|
||||
order_number: (p.orders as any)?.order_number || null,
|
||||
order_number: p.orders?.order_number || null,
|
||||
}));
|
||||
|
||||
return { data: enriched, total, page, limit };
|
||||
|
||||
Reference in New Issue
Block a user