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 {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
import Information from "App/Models/Information";
|
import Information from "App/Models/Information";
|
||||||
import InformationUpdateValidator from "App/Validators/information/InformationUpdateValidator";
|
import InformationUpdateValidator from "App/Validators/information/InformationUpdateValidator";
|
||||||
|
import getTranslation from "App/Tasks/getTranslation";
|
||||||
|
|
||||||
export default class InformationsController {
|
export default class InformationsController {
|
||||||
|
|
||||||
public async index ( { response }: HttpContextContract ) {
|
public async index ( { response }: HttpContextContract ) {
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
informations: await Information.first()
|
informations: await Information
|
||||||
|
.query()
|
||||||
|
.preload('translation')
|
||||||
|
.first()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async update ( { response, request }: HttpContextContract ) {
|
public async update ( { response, request }: HttpContextContract ) {
|
||||||
const information = await Information.firstOrFail()
|
const information = await Information.firstOrFail()
|
||||||
const data = await request.validate(InformationUpdateValidator)
|
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()
|
await information.merge(data).save()
|
||||||
|
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
|
|||||||
@@ -15,9 +15,6 @@ export default class Information extends BaseModel {
|
|||||||
@column()
|
@column()
|
||||||
public translationId: number
|
public translationId: number
|
||||||
|
|
||||||
@column()
|
|
||||||
public hiringColor: string
|
|
||||||
|
|
||||||
@column.dateTime({ autoCreate: true })
|
@column.dateTime({ autoCreate: true })
|
||||||
public createdAt: DateTime
|
public createdAt: DateTime
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
|||||||
export default class InformationUpdateValidator {
|
export default class InformationUpdateValidator {
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
age: schema.number.optional(),
|
age: schema.number.optional(),
|
||||||
hiring_status: schema.string.optional(),
|
code: schema.string.optional(),
|
||||||
hiring_color: schema.string.optional()
|
hiring_color: schema.string.optional()
|
||||||
})
|
})
|
||||||
public messages = {
|
public messages = {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ export default class Informations extends BaseSchema {
|
|||||||
this.schema.createTable(this.tableName, (table) => {
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
table.increments('id')
|
table.increments('id')
|
||||||
table.integer('age').notNullable()
|
table.integer('age').notNullable()
|
||||||
table.string('hiring_color').notNullable()
|
|
||||||
table
|
table
|
||||||
.integer('translation_id')
|
.integer('translation_id')
|
||||||
.unsigned()
|
.unsigned()
|
||||||
|
|||||||
Reference in New Issue
Block a user