mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Rename profile to information
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
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.first()
|
||||
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({
|
||||
|
||||
@@ -15,9 +15,6 @@ export default class Information extends BaseModel {
|
||||
@column()
|
||||
public translationId: number
|
||||
|
||||
@column()
|
||||
public hiringColor: string
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
public createdAt: DateTime
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
export default class InformationUpdateValidator {
|
||||
public schema = schema.create({
|
||||
age: schema.number.optional(),
|
||||
hiring_status: schema.string.optional(),
|
||||
code: schema.string.optional(),
|
||||
hiring_color: schema.string.optional()
|
||||
})
|
||||
public messages = {
|
||||
|
||||
@@ -7,7 +7,6 @@ export default class Informations extends BaseSchema {
|
||||
this.schema.createTable(this.tableName, (table) => {
|
||||
table.increments('id')
|
||||
table.integer('age').notNullable()
|
||||
table.string('hiring_color').notNullable()
|
||||
table
|
||||
.integer('translation_id')
|
||||
.unsigned()
|
||||
|
||||
Reference in New Issue
Block a user