mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-24 00:40:25 +01:00
Add maintenance mode and update announce
This commit is contained in:
42
app/Controllers/Http/MaintenancesController.ts
Normal file
42
app/Controllers/Http/MaintenancesController.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import getTranslation from "App/Tasks/getTranslation";
|
||||
import Maintenance from "App/Models/Maintenance";
|
||||
import MaintenanceUpdateValidator from "App/Validators/maintenance/MaintenanceUpdateValidator";
|
||||
|
||||
export default class MaintenancesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
const maintenance = await Maintenance
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
.preload('reason')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
maintenance: maintenance
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
const maintenance = await Maintenance.findOrFail(params.id)
|
||||
maintenance.load('reason')
|
||||
return response.status(200).send({
|
||||
maintenance
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(MaintenanceUpdateValidator)
|
||||
const maintenance = await Maintenance.findOrFail(params.id)
|
||||
|
||||
if (data.reason) {
|
||||
await maintenance.related('reason').associate(await getTranslation(data.reason))
|
||||
}
|
||||
|
||||
await maintenance.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
maintenance
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user