mirror of
https://github.com/kjanat/livedash-node.git
synced 2026-01-16 20:12:08 +01:00
feat: complete development environment setup and code quality improvements
- Set up pre-commit hooks with husky and lint-staged for automated code quality - Improved TypeScript type safety by replacing 'any' types with proper generics - Fixed markdown linting violations (MD030 spacing) across all documentation - Fixed compound adjective hyphenation in technical documentation - Fixed invalid JSON union syntax in API documentation examples - Automated code formatting and linting on commit - Enhanced error handling with better type constraints - Configured biome and markdownlint for consistent code style - All changes verified with successful production build
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { getSchedulerIntegration } from "@/lib/services/schedulers/ServerSchedulerIntegration";
|
||||
import { createAdminHandler } from "@/lib/api";
|
||||
import { z } from "zod";
|
||||
import { createAdminHandler } from "@/lib/api";
|
||||
import { getSchedulerIntegration } from "@/lib/services/schedulers/ServerSchedulerIntegration";
|
||||
|
||||
/**
|
||||
* Get all schedulers with their status and metrics
|
||||
@ -21,72 +21,79 @@ export const GET = createAdminHandler(async (_context) => {
|
||||
};
|
||||
});
|
||||
|
||||
const PostInputSchema = z.object({
|
||||
action: z.enum(["start", "stop", "trigger", "startAll", "stopAll"]),
|
||||
schedulerId: z.string().optional(),
|
||||
}).refine(
|
||||
(data) => {
|
||||
// schedulerId is required for individual scheduler actions
|
||||
const actionsRequiringSchedulerId = ["start", "stop", "trigger"];
|
||||
if (actionsRequiringSchedulerId.includes(data.action)) {
|
||||
return data.schedulerId !== undefined && data.schedulerId.length > 0;
|
||||
const PostInputSchema = z
|
||||
.object({
|
||||
action: z.enum(["start", "stop", "trigger", "startAll", "stopAll"]),
|
||||
schedulerId: z.string().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
// schedulerId is required for individual scheduler actions
|
||||
const actionsRequiringSchedulerId = ["start", "stop", "trigger"];
|
||||
if (actionsRequiringSchedulerId.includes(data.action)) {
|
||||
return data.schedulerId !== undefined && data.schedulerId.length > 0;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: "schedulerId is required for start, stop, and trigger actions",
|
||||
path: ["schedulerId"],
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: "schedulerId is required for start, stop, and trigger actions",
|
||||
path: ["schedulerId"],
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
/**
|
||||
* Control scheduler operations (start/stop/trigger)
|
||||
* Requires admin authentication
|
||||
*/
|
||||
export const POST = createAdminHandler(async (_context, validatedData) => {
|
||||
const { action, schedulerId } = validatedData;
|
||||
export const POST = createAdminHandler(
|
||||
async (_context, validatedData) => {
|
||||
const { action, schedulerId } = validatedData as z.infer<
|
||||
typeof PostInputSchema
|
||||
>;
|
||||
|
||||
const integration = getSchedulerIntegration();
|
||||
const integration = getSchedulerIntegration();
|
||||
|
||||
switch (action) {
|
||||
case "start":
|
||||
if (schedulerId) {
|
||||
await integration.startScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
switch (action) {
|
||||
case "start":
|
||||
if (schedulerId) {
|
||||
await integration.startScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
|
||||
case "stop":
|
||||
if (schedulerId) {
|
||||
await integration.stopScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
case "stop":
|
||||
if (schedulerId) {
|
||||
await integration.stopScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
|
||||
case "trigger":
|
||||
if (schedulerId) {
|
||||
await integration.triggerScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
case "trigger":
|
||||
if (schedulerId) {
|
||||
await integration.triggerScheduler(schedulerId);
|
||||
}
|
||||
break;
|
||||
|
||||
case "startAll":
|
||||
await integration.getManager().startAll();
|
||||
break;
|
||||
case "startAll":
|
||||
await integration.getManager().startAll();
|
||||
break;
|
||||
|
||||
case "stopAll":
|
||||
await integration.getManager().stopAll();
|
||||
break;
|
||||
case "stopAll":
|
||||
await integration.getManager().stopAll();
|
||||
break;
|
||||
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
error: `Unknown action: ${action}`,
|
||||
};
|
||||
default:
|
||||
return {
|
||||
success: false,
|
||||
error: `Unknown action: ${action}`,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Action '${action}' completed successfully`,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
},
|
||||
{
|
||||
validateInput: PostInputSchema,
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `Action '${action}' completed successfully`,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}, {
|
||||
validateInput: PostInputSchema,
|
||||
});
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user