mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
34 lines
996 B
TypeScript
34 lines
996 B
TypeScript
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
|
import Information from "App/Models/Information";
|
|
import InformationUpdateValidator from "App/Validators/information/InformationUpdateValidator";
|
|
import getTranslation from "App/Tasks/getTranslation";
|
|
|
|
export default class InformationsController {
|
|
|
|
public async index ( { response }: HttpContextContract ) {
|
|
return response.status(200).send({
|
|
informations: await Information
|
|
.query()
|
|
.preload('translation')
|
|
.first()
|
|
})
|
|
}
|
|
|
|
public async update ( { response, request }: HttpContextContract ) {
|
|
const information = await Information.firstOrFail()
|
|
const data = await request.validate(InformationUpdateValidator)
|
|
|
|
if (data.code) {
|
|
const translation = await getTranslation(data.code)
|
|
await information.related('translation').associate(translation)
|
|
}
|
|
|
|
await information.merge(data).save()
|
|
|
|
return response.status(200).send({
|
|
information
|
|
})
|
|
}
|
|
|
|
}
|