mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Update translation into message in Announce Model
This commit is contained in:
@@ -1 +1,2 @@
|
||||
node_modules
|
||||
.env
|
||||
|
||||
@@ -11,8 +11,8 @@ export default class AnnouncesController {
|
||||
const announce = await Announce
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
.preload('translation')
|
||||
.preload('file')
|
||||
.preload('message')
|
||||
.preload('cover')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
announce: announce
|
||||
@@ -24,10 +24,10 @@ export default class AnnouncesController {
|
||||
const announce = await Announce.create(data)
|
||||
|
||||
const translation = await getTranslation(data.code)
|
||||
await announce.related('translation').associate(translation)
|
||||
await announce.related('message').associate(translation)
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover) await announce.related('file').associate(cover)
|
||||
if (cover) await announce.related('cover').associate(cover)
|
||||
|
||||
return response.status(200).send({
|
||||
announce: announce
|
||||
@@ -36,8 +36,8 @@ export default class AnnouncesController {
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
const announce = await Announce.findOrFail(params.id)
|
||||
announce.load('translation')
|
||||
announce.load('file')
|
||||
announce.load('message')
|
||||
announce.load('cover')
|
||||
return response.status(200).send({
|
||||
announce
|
||||
})
|
||||
@@ -49,11 +49,11 @@ export default class AnnouncesController {
|
||||
|
||||
if (data.code) {
|
||||
const translation = await getTranslation(data.code)
|
||||
await announce.related('translation').associate(translation)
|
||||
await announce.related('message').associate(translation)
|
||||
}
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover) await announce.related('file').associate(cover)
|
||||
if (cover) await announce.related('cover').associate(cover)
|
||||
await announce.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
|
||||
@@ -14,16 +14,16 @@ export default class Announce extends BaseModel {
|
||||
public hoverColor: string
|
||||
|
||||
@belongsTo(() => Translation)
|
||||
public translation: BelongsTo<typeof Translation>
|
||||
public message: BelongsTo<typeof Translation>
|
||||
|
||||
@column()
|
||||
public translationId: number
|
||||
public messageId: number
|
||||
|
||||
@belongsTo(() => File)
|
||||
public file: BelongsTo<typeof File>
|
||||
public cover: BelongsTo<typeof File>
|
||||
|
||||
@column()
|
||||
public fileId: number
|
||||
public coverId: number
|
||||
|
||||
@column.dateTime({ autoCreate: true })
|
||||
public createdAt: DateTime
|
||||
|
||||
42
app/Validators/experience/ExperienceUpdateValidator.ts
Normal file
42
app/Validators/experience/ExperienceUpdateValidator.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { schema } from '@ioc:Adonis/Core/Validator'
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
|
||||
export default class ExperienceUpdateValidator {
|
||||
constructor (protected ctx: HttpContextContract) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Define schema to validate the "shape", "type", "formatting" and "integrity" of data.
|
||||
*
|
||||
* For example:
|
||||
* 1. The username must be of data type string. But then also, it should
|
||||
* not contain special characters or numbers.
|
||||
* ```
|
||||
* schema.string({}, [ rules.alpha() ])
|
||||
* ```
|
||||
*
|
||||
* 2. The email must be of data type string, formatted as a valid
|
||||
* email. But also, not used by any other user.
|
||||
* ```
|
||||
* schema.string({}, [
|
||||
* rules.email(),
|
||||
* rules.unique({ table: 'users', column: 'email' }),
|
||||
* ])
|
||||
* ```
|
||||
*/
|
||||
public schema = schema.create({
|
||||
})
|
||||
|
||||
/**
|
||||
* Custom messages for validation failures. You can make use of dot notation `(.)`
|
||||
* for targeting nested fields and array expressions `(*)` for targeting all
|
||||
* children of an array. For example:
|
||||
*
|
||||
* {
|
||||
* 'profile.username.required': 'Username is required',
|
||||
* 'scores.*.number': 'Define scores as valid numbers'
|
||||
* }
|
||||
*
|
||||
*/
|
||||
public messages = {}
|
||||
}
|
||||
Reference in New Issue
Block a user