Files
adam-acs/app/controllers/commands_controller.ts
T
kevin.lhereec b00c0c94a8
Build & Deploy / build (push) Successful in 40s
Build & Deploy / docker (push) Successful in 1m4s
Build & Deploy / deploy (push) Successful in 26s
feat: suppression des commandes PENDING depuis /commands
- Ajout de destroy() dans CommandsController (DELETE /commands/:id)
- Routes DELETE /commands/:id dans les groupes /api/v1 et /internal
- Bouton supprimer dans Commands.vue visible uniquement sur les commandes PENDING
- Utilise fetchWithCsrf pour la protection CSRF
2026-07-17 10:31:56 +02:00

40 lines
1.3 KiB
TypeScript

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<string, any>,
mode: payload.mode as any,
priority: payload.priority,
})
return response.status(201).json(command)
}
async destroy({ params, response }: HttpContext) {
const deleted = await this.commandService.deleteCommand(params.id)
if (!deleted) {
return response.status(404).json({ error: 'Command not found' })
}
return response.status(204).send('')
}
}