mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-19 06:21:35 +01:00
Lint and update
This commit is contained in:
@@ -1,23 +1,22 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import FormationStoreValidator from "App/Validators/formation/FormationStoreValidator";
|
||||
import FormationUpdateValidator from "App/Validators/formation/FormationUpdateValidator";
|
||||
import Formation from "App/Models/Formation";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormationStoreValidator from 'App/Validators/formation/FormationStoreValidator'
|
||||
import FormationUpdateValidator from 'App/Validators/formation/FormationUpdateValidator'
|
||||
import Formation from 'App/Models/Formation'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class FormationsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const formations = await Formation
|
||||
.query()
|
||||
.orderBy('begin_date', 'desc')
|
||||
.preload('title')
|
||||
.preload('description')
|
||||
return response.status(200).send({
|
||||
formations: formations
|
||||
formations,
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormationStoreValidator)
|
||||
const formation = await Formation.create(data)
|
||||
|
||||
@@ -25,44 +24,41 @@ export default class FormationsController {
|
||||
await formation.related('description').associate(await getTranslation(data.description))
|
||||
|
||||
return response.status(200).send({
|
||||
formation: formation
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
formation.load('title')
|
||||
formation.load('description')
|
||||
return response.status(200).send({
|
||||
formation
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormationUpdateValidator)
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
|
||||
if (data.title) {
|
||||
if (data.title)
|
||||
await formation.related('title').associate(await getTranslation(data.title))
|
||||
}
|
||||
|
||||
if (data.description) {
|
||||
if (data.description)
|
||||
await formation.related('description').associate(await getTranslation(data.description))
|
||||
}
|
||||
|
||||
await formation.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
formation
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
await formation.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Formation successfully deleted!'
|
||||
message: 'Formation successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user