import type { HttpContext } from '@adonisjs/core/http' import CommandService from '#services/command_service' import { createCommandValidator } from '#validators/command' export default class CommandsController { private commandService = new CommandService() async index({ response }: HttpContext) { const commands = await this.commandService.getCommands() return response.json(commands) } async show({ params, response }: HttpContext) { const commands = await this.commandService.getCommandsByDevice(params.id) return response.json(commands) } async store({ request, response }: HttpContext) { const payload = await request.validateUsing(createCommandValidator) const command = await this.commandService.createCommand({ deviceIdentifier: payload.deviceIdentifier, action: payload.action as any, parameters: payload.parameters as Record, mode: payload.mode as any, priority: payload.priority, }) return response.status(201).json(command) } }