Mobile friendly, lint correction, typescript error clear

This commit is contained in:
Marcelo
2026-01-16 22:39:16 +00:00
parent 0f88207f3f
commit c183dda383
58 changed files with 7199 additions and 2714 deletions

View File

@@ -3,6 +3,7 @@ import type { NextRequest } from "next/server";
import { Prisma } from "@prisma/client";
import { prisma } from "@/lib/prisma";
import { requireSession } from "@/lib/auth/requireSession";
import { toJsonValue } from "@/lib/prismaJson";
import {
DEFAULT_ALERTS,
DEFAULT_DEFAULTS,
@@ -18,7 +19,7 @@ import {
import { publishSettingsUpdate } from "@/lib/mqtt";
import { z } from "zod";
function isPlainObject(value: any): value is Record<string, any> {
function isPlainObject(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
@@ -34,9 +35,9 @@ const machineSettingsSchema = z
})
.passthrough();
function pickAllowedOverrides(raw: any) {
function pickAllowedOverrides(raw: unknown) {
if (!isPlainObject(raw)) return {};
const out: Record<string, any> = {};
const out: Record<string, unknown> = {};
for (const key of ["shiftSchedule", "thresholds", "alerts", "defaults"]) {
if (raw[key] !== undefined) out[key] = raw[key];
}
@@ -337,24 +338,26 @@ export async function PUT(
select: { overridesJson: true },
});
let nextOverrides: any = null;
let nextOverrides: Record<string, unknown> | null = null;
if (patch === null) {
nextOverrides = null;
} else {
const merged = applyOverridePatch(existing?.overridesJson ?? {}, patch);
nextOverrides = Object.keys(merged).length ? merged : null;
}
const nextOverridesJson =
nextOverrides === null ? Prisma.DbNull : toJsonValue(nextOverrides);
const saved = await tx.machineSettings.upsert({
where: { machineId },
update: {
overridesJson: nextOverrides,
overridesJson: nextOverridesJson,
updatedBy: session.userId,
},
create: {
machineId,
orgId: session.orgId,
overridesJson: nextOverrides,
overridesJson: nextOverridesJson,
updatedBy: session.userId,
},
});

View File

@@ -1,5 +1,4 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { Prisma } from "@prisma/client";
import { prisma } from "@/lib/prisma";
import { requireSession } from "@/lib/auth/requireSession";
@@ -19,7 +18,15 @@ import {
import { publishSettingsUpdate } from "@/lib/mqtt";
import { z } from "zod";
function isPlainObject(value: any): value is Record<string, any> {
type ValidShift = {
name: string;
startTime: string;
endTime: string;
sortOrder: number;
enabled: boolean;
};
function isPlainObject(value: unknown): value is Record<string, unknown> {
return !!value && typeof value === "object" && !Array.isArray(value);
}
@@ -191,7 +198,7 @@ export async function PUT(req: Request) {
return NextResponse.json({ ok: false, error: defaultsValidation.error }, { status: 400 });
}
let shiftRows: any[] | null = null;
let shiftRows: ValidShift[] | null = null;
if (shiftSchedule?.shifts !== undefined) {
const shiftResult = validateShiftSchedule(shiftSchedule.shifts);
if (!shiftResult.ok) {
@@ -291,15 +298,15 @@ export async function PUT(req: Request) {
return { settings: refreshed, shifts: refreshedShifts };
});
if ((updated as any)?.error === "VERSION_MISMATCH") {
if ("error" in updated && updated.error === "VERSION_MISMATCH") {
return NextResponse.json(
{ ok: false, error: "Version mismatch", currentVersion: (updated as any).currentVersion },
{ ok: false, error: "Version mismatch", currentVersion: updated.currentVersion },
{ status: 409 }
);
}
if ((updated as any)?.error) {
return NextResponse.json({ ok: false, error: (updated as any).error }, { status: 400 });
if ("error" in updated) {
return NextResponse.json({ ok: false, error: updated.error }, { status: 400 });
}
const payload = buildSettingsPayload(updated.settings, updated.shifts ?? []);