mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 20:19:26 +01:00
Lint and update
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Announce from "App/Models/Announce";
|
||||
import AnnounceUpdateValidator from "App/Validators/announce/AnnounceUpdateValidator";
|
||||
import File from "App/Models/File";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Announce from 'App/Models/Announce'
|
||||
import AnnounceUpdateValidator from 'App/Validators/announce/AnnounceUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class AnnouncesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const announce = await Announce
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
@@ -14,17 +13,16 @@ export default class AnnouncesController {
|
||||
.preload('cover')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
announce: announce
|
||||
announce,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(AnnounceUpdateValidator)
|
||||
const announce = await Announce.findOrFail(params.id)
|
||||
|
||||
if (data.code) {
|
||||
if (data.code)
|
||||
await announce.related('message').associate(await getTranslation(data.code))
|
||||
}
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover) await announce.related('cover').associate(cover)
|
||||
@@ -32,8 +30,7 @@ export default class AnnouncesController {
|
||||
await announce.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
announce
|
||||
announce,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,53 +1,52 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import AuthValidator from "App/Validators/AuthValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import AuthValidator from 'App/Validators/AuthValidator'
|
||||
|
||||
export default class AuthController {
|
||||
|
||||
public async loginApi ({ request, auth, response }: HttpContextContract) {
|
||||
public async loginApi({ request, auth, response }: HttpContextContract) {
|
||||
const { email, password } = await request.validate(AuthValidator)
|
||||
const token = await auth.use('api').attempt(email, password, {
|
||||
expiresIn: '2 days'
|
||||
expiresIn: '2 days',
|
||||
})
|
||||
return response.status(200).send({
|
||||
token: token.toJSON()
|
||||
token: token.toJSON(),
|
||||
})
|
||||
}
|
||||
|
||||
public async loginWeb ({ request, auth, response }: HttpContextContract) {
|
||||
public async loginWeb({ request, auth, response }: HttpContextContract) {
|
||||
const { email, password, remember } = await request.validate(AuthValidator)
|
||||
await auth.use('web').attempt(email, password, remember)
|
||||
|
||||
return response.status(200).send({
|
||||
user: auth.use('web').user
|
||||
user: auth.use('web').user,
|
||||
})
|
||||
}
|
||||
|
||||
public async createInfiniteToken ({ request, auth, response }: HttpContextContract) {
|
||||
public async createInfiniteToken({ request, auth, response }: HttpContextContract) {
|
||||
const { email, password } = await request.validate(AuthValidator)
|
||||
const token = await auth.use('api').attempt(email, password)
|
||||
return response.status(200).send({
|
||||
token: token.toJSON()
|
||||
token: token.toJSON(),
|
||||
})
|
||||
}
|
||||
|
||||
public async logoutApi ({ auth, response }: HttpContextContract) {
|
||||
public async logoutApi({ auth, response }: HttpContextContract) {
|
||||
await auth.use('api').revoke()
|
||||
return response.status(200).send({
|
||||
message: 'You have been disconnected!'
|
||||
message: 'You have been disconnected!',
|
||||
})
|
||||
}
|
||||
|
||||
public async logoutWeb ({ auth, response }: HttpContextContract) {
|
||||
public async logoutWeb({ auth, response }: HttpContextContract) {
|
||||
await auth.use('web').logout()
|
||||
return response.status(200).send({
|
||||
message: 'You have been disconnected!'
|
||||
message: 'You have been disconnected!',
|
||||
})
|
||||
}
|
||||
|
||||
public async user ({ auth, response }: HttpContextContract) {
|
||||
public async user({ auth, response }: HttpContextContract) {
|
||||
const user = await auth.use('web').authenticate() || await auth.use('api').authenticate()
|
||||
return response.status(200).send({
|
||||
user
|
||||
user,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,57 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Experience from "App/Models/Experience";
|
||||
import ExperienceStoreValidator from "App/Validators/experience/ExperienceStoreValidator";
|
||||
import ExperienceUpdateValidator from "App/Validators/experience/ExperienceUpdateValidator";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Experience from 'App/Models/Experience'
|
||||
import ExperienceStoreValidator from 'App/Validators/experience/ExperienceStoreValidator'
|
||||
import ExperienceUpdateValidator from 'App/Validators/experience/ExperienceUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class ExperiencesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const experiences = await Experience
|
||||
.query()
|
||||
.orderBy('begin_date', 'desc')
|
||||
.preload('title')
|
||||
return response.status(200).send({
|
||||
experiences: experiences
|
||||
experiences,
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(ExperienceStoreValidator)
|
||||
const experience = await Experience.create(data)
|
||||
await experience.related('title').associate(await getTranslation(data.title))
|
||||
|
||||
return response.status(200).send({
|
||||
experience: experience
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
experience.load('title')
|
||||
return response.status(200).send({
|
||||
experience
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(ExperienceUpdateValidator)
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
|
||||
if (data.title) {
|
||||
if (data.title)
|
||||
await experience.related('title').associate(await getTranslation(data.title))
|
||||
}
|
||||
|
||||
await experience.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
experience
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
await experience.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Experience successfully deleted!'
|
||||
message: 'Experience successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,49 +1,46 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Application from "@ioc:Adonis/Core/Application";
|
||||
import File from "App/Models/File";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Application from '@ioc:Adonis/Core/Application'
|
||||
import File from 'App/Models/File'
|
||||
|
||||
export default class FilesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
files: await File.all()
|
||||
files: await File.all(),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const file = await request.file('file', {
|
||||
extnames: ['jpg', 'png', 'jpeg']
|
||||
extnames: ['jpg', 'png', 'jpeg'],
|
||||
})
|
||||
const label = request.input('label')
|
||||
|
||||
if (!file) {
|
||||
if (!file)
|
||||
return 'Please upload file!'
|
||||
}
|
||||
if (file.hasErrors) {
|
||||
|
||||
if (file.hasErrors)
|
||||
return file.errors
|
||||
}
|
||||
|
||||
await file.move(Application.makePath('storage'), {
|
||||
name: `${label}.${file.extname}`,
|
||||
overwrite: true
|
||||
overwrite: true,
|
||||
})
|
||||
|
||||
return response.status(200).send({
|
||||
file: await File.firstOrCreate({
|
||||
label: label
|
||||
label,
|
||||
}, {
|
||||
fileName: `${label}.${file.extname}`,
|
||||
label: label
|
||||
})
|
||||
label,
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
public async destroy({ params, response }: HttpContextContract) {
|
||||
const file = await File.findOrFail(params.id)
|
||||
await file.delete()
|
||||
return response.status(200).send({
|
||||
message: 'File successfully deleted!'
|
||||
message: 'File successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,35 +1,33 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormStoreValidator from "App/Validators/form/FormStoreValidator";
|
||||
import Form from "App/Models/Form";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormStoreValidator from 'App/Validators/form/FormStoreValidator'
|
||||
import Form from 'App/Models/Form'
|
||||
|
||||
export default class FormsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
forms: Form.query().orderBy('created_at', 'asc')
|
||||
forms: Form.query().orderBy('created_at', 'asc'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormStoreValidator)
|
||||
//todo send confirmation email + email to me with FormConfirmation
|
||||
// todo send confirmation email + email to me with FormConfirmation
|
||||
return response.status(200).send({
|
||||
form: await Form.create(data)
|
||||
form: await Form.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
form: await Form.findOrFail(params.id)
|
||||
form: await Form.findOrFail(params.id),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const form = await Form.findOrFail(params.id)
|
||||
await form.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Form successfully deleted!'
|
||||
message: 'Form successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Information from "App/Models/Information";
|
||||
import InformationUpdateValidator from "App/Validators/information/InformationUpdateValidator";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Information from 'App/Models/Information'
|
||||
import InformationUpdateValidator from 'App/Validators/information/InformationUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class InformationsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
informations: await Information
|
||||
.query()
|
||||
.preload('translation')
|
||||
.first()
|
||||
.first(),
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ response, request }: HttpContextContract) {
|
||||
public async update({ response, request }: HttpContextContract) {
|
||||
const information = await Information.firstOrFail()
|
||||
const data = await request.validate(InformationUpdateValidator)
|
||||
|
||||
@@ -26,8 +25,7 @@ export default class InformationsController {
|
||||
await information.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
information
|
||||
information,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,32 +1,31 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Location from "App/Models/Location";
|
||||
import LocationValidator from "App/Validators/location/LocationValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Location from 'App/Models/Location'
|
||||
import LocationValidator from 'App/Validators/location/LocationValidator'
|
||||
|
||||
export default class LocationsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const location = await Location.query().orderBy('since', 'desc').first()
|
||||
if (location) {
|
||||
return response.status(200).send({
|
||||
location: {
|
||||
place: location.place,
|
||||
left: location.left,
|
||||
since: location.since
|
||||
}
|
||||
since: location.since,
|
||||
},
|
||||
})
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return response.status(200).send({
|
||||
location: 'Location is unknown...'
|
||||
location: 'Location is unknown...',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(LocationValidator)
|
||||
const location = await Location.create(data)
|
||||
return response.status(200).send({
|
||||
location
|
||||
location,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Maintenance from "App/Models/Maintenance";
|
||||
import MaintenanceUpdateValidator from "App/Validators/maintenance/MaintenanceUpdateValidator";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Maintenance from 'App/Models/Maintenance'
|
||||
import MaintenanceUpdateValidator from 'App/Validators/maintenance/MaintenanceUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class MaintenancesController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const maintenance = await Maintenance
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
.preload('reason')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
maintenance: maintenance
|
||||
maintenance,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(MaintenanceUpdateValidator)
|
||||
const maintenance = await Maintenance.findOrFail(params.id)
|
||||
|
||||
if (data.reason) {
|
||||
if (data.reason)
|
||||
await maintenance.related('reason').associate(await getTranslation(data.reason))
|
||||
}
|
||||
|
||||
await maintenance.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
maintenance
|
||||
maintenance,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,46 +1,44 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import PostColor from "App/Models/PostColor";
|
||||
import PostColorStoreValidator from "App/Validators/postColor/PostColorStoreValidator";
|
||||
import PostColorUpdateValidator from "App/Validators/postColor/PostColorUpdateValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import PostColor from 'App/Models/PostColor'
|
||||
import PostColorStoreValidator from 'App/Validators/postColor/PostColorStoreValidator'
|
||||
import PostColorUpdateValidator from 'App/Validators/postColor/PostColorUpdateValidator'
|
||||
|
||||
export default class PostColorsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
post_colors: await PostColor.all()
|
||||
post_colors: await PostColor.all(),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostColorStoreValidator)
|
||||
const postColor = await PostColor.create(data)
|
||||
return response.status(200).send({
|
||||
post_color: postColor
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
return response.status(200).send({
|
||||
post_color: postColor
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostColorUpdateValidator)
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
await postColor.merge(data).save()
|
||||
return response.status(200).send({
|
||||
post_color: postColor
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
await postColor.delete()
|
||||
return response.status(200).send({
|
||||
message: 'PostColor successfully deleted!'
|
||||
message: 'PostColor successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import Post from "App/Models/Post";
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import PostUpdateValidator from "App/Validators/post/PostUpdateValidator";
|
||||
import File from "App/Models/File";
|
||||
import PostStoreValidator from "App/Validators/post/PostStoreValidator";
|
||||
import PostColor from "App/Models/PostColor";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import Post from 'App/Models/Post'
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import PostUpdateValidator from 'App/Validators/post/PostUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import PostStoreValidator from 'App/Validators/post/PostStoreValidator'
|
||||
import PostColor from 'App/Models/PostColor'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class PostsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
posts: await Post.query()
|
||||
.orderBy('id', 'desc')
|
||||
@@ -19,11 +18,11 @@ export default class PostsController {
|
||||
.preload('color')
|
||||
.preload('content')
|
||||
.preload('title')
|
||||
.preload('description')
|
||||
.preload('description'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostStoreValidator)
|
||||
const post = await Post.create(data)
|
||||
|
||||
@@ -40,11 +39,11 @@ export default class PostsController {
|
||||
await post.related('tags').sync(data.tags!)
|
||||
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
await post.load('cover')
|
||||
await post.load('title')
|
||||
@@ -55,16 +54,16 @@ export default class PostsController {
|
||||
tags.preload('label')
|
||||
})
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async get ({ params, response }: HttpContextContract) {
|
||||
public async get({ params, response }: HttpContextContract) {
|
||||
const post = await Post.firstOrCreate({
|
||||
slug: params.slug
|
||||
slug: params.slug,
|
||||
}, {
|
||||
slug: params.slug,
|
||||
likes: 0
|
||||
likes: 0,
|
||||
})
|
||||
await post.load('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
@@ -75,11 +74,11 @@ export default class PostsController {
|
||||
await post.load('content')
|
||||
await post.load('color')
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
const data = await request.validate(PostUpdateValidator)
|
||||
|
||||
@@ -97,43 +96,42 @@ export default class PostsController {
|
||||
if (color) await post.related('color').associate(color)
|
||||
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
await post.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Post successfully deleted!'
|
||||
message: 'Post successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
public async like ({ params, response }: HttpContextContract) {
|
||||
public async like({ params, response }: HttpContextContract) {
|
||||
const post = await Post.firstOrCreate({
|
||||
slug: params.slug
|
||||
slug: params.slug,
|
||||
}, {
|
||||
slug: params.slug,
|
||||
likes: 0
|
||||
likes: 0,
|
||||
})
|
||||
const getLikes = post.likes
|
||||
await post.merge({
|
||||
likes: getLikes + 1
|
||||
likes: getLikes + 1,
|
||||
}).save()
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async unlike ({ params, response }: HttpContextContract) {
|
||||
public async unlike({ params, response }: HttpContextContract) {
|
||||
const post = await Post.findByOrFail('slug', params.slug)
|
||||
const getLikes = post.likes
|
||||
await post.merge({
|
||||
likes: getLikes - 1
|
||||
likes: getLikes - 1,
|
||||
}).save()
|
||||
return response.status(200).send({
|
||||
post
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,47 +1,46 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
|
||||
export default class ProfileController {
|
||||
|
||||
public me ({ response }: HttpContextContract) {
|
||||
public me({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
pronouns: "Arthur",
|
||||
home: ["Paris", "France"],
|
||||
pronouns: 'Arthur',
|
||||
home: ['Paris', 'France'],
|
||||
passions: [
|
||||
"Dev",
|
||||
"DevOps",
|
||||
"New technologies",
|
||||
"Gaming",
|
||||
"Cloud"
|
||||
'Dev',
|
||||
'DevOps',
|
||||
'New technologies',
|
||||
'Gaming',
|
||||
'Cloud',
|
||||
],
|
||||
code: [
|
||||
"Javascript",
|
||||
"Typescript",
|
||||
"HTML",
|
||||
"CSS",
|
||||
"GoLang",
|
||||
"Java"
|
||||
'Javascript',
|
||||
'Typescript',
|
||||
'HTML',
|
||||
'CSS',
|
||||
'GoLang',
|
||||
'Java',
|
||||
],
|
||||
ask_me_about: [
|
||||
"Web dev",
|
||||
"Tech",
|
||||
"Consulting",
|
||||
"Cloud computing",
|
||||
"DevOps",
|
||||
"Software dev"
|
||||
'Web dev',
|
||||
'Tech',
|
||||
'Consulting',
|
||||
'Cloud computing',
|
||||
'DevOps',
|
||||
'Software dev',
|
||||
],
|
||||
technologies: {
|
||||
web_app: ["VueJs", "NuxtJs", "Sass", "TailwindCss", "WindiCss"],
|
||||
desktop_app: ["ElectronJs"],
|
||||
mobile_app: ["React Native", "Vue Native"],
|
||||
web_app: ['VueJs', 'NuxtJs', 'Sass', 'TailwindCss', 'WindiCss'],
|
||||
desktop_app: ['ElectronJs'],
|
||||
mobile_app: ['React Native', 'Vue Native'],
|
||||
back_end: {
|
||||
typescript: ["AdonisJs"],
|
||||
java: ["Spring"]
|
||||
typescript: ['AdonisJs'],
|
||||
java: ['Spring'],
|
||||
},
|
||||
databases: ["MongoDB", "MariaDB", "Redis"],
|
||||
messaging: ["RabbitMQ"],
|
||||
other: ["Docker", "Git"],
|
||||
architecture: ["microservices", "event-driven", "design system pattern"],
|
||||
operating_systems: ['MacOS', "Linux"]
|
||||
databases: ['MongoDB', 'MariaDB', 'Redis'],
|
||||
messaging: ['RabbitMQ'],
|
||||
other: ['Docker', 'Git'],
|
||||
architecture: ['microservices', 'event-driven', 'design system pattern'],
|
||||
operating_systems: ['MacOS', 'Linux'],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Project from "App/Models/Project";
|
||||
import ProjectStoreValidator from "App/Validators/project/ProjectStoreValidator";
|
||||
import ProjectUpdateValidator from "App/Validators/project/ProjectUpdateValidator";
|
||||
import File from "App/Models/File";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Project from 'App/Models/Project'
|
||||
import ProjectStoreValidator from 'App/Validators/project/ProjectStoreValidator'
|
||||
import ProjectUpdateValidator from 'App/Validators/project/ProjectUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class ProjectsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
projects: await Project.query()
|
||||
.orderBy('id', 'asc')
|
||||
@@ -15,11 +14,11 @@ export default class ProjectsController {
|
||||
.preload('description')
|
||||
.preload('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
})
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(ProjectStoreValidator)
|
||||
const project = await Project.create(data)
|
||||
const cover = await File.findByOrFail('label', data.cover)
|
||||
@@ -28,11 +27,11 @@ export default class ProjectsController {
|
||||
await project.related('description').associate(await getTranslation(data.description))
|
||||
await project.related('tags').sync(data.tags!)
|
||||
return response.status(200).send({
|
||||
project
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.load('cover')
|
||||
await project.load('description')
|
||||
@@ -40,11 +39,11 @@ export default class ProjectsController {
|
||||
tags.preload('label')
|
||||
})
|
||||
return response.status(200).send({
|
||||
project
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
const data = await request.validate(ProjectUpdateValidator)
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
@@ -56,16 +55,15 @@ export default class ProjectsController {
|
||||
|
||||
await project.related('tags').sync(data.tags!)
|
||||
return response.status(200).send({
|
||||
project
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Project successfully deleted!'
|
||||
message: 'Project successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import File from "App/Models/File";
|
||||
import Skill from "App/Models/Skill";
|
||||
import SkillStoreValidator from "App/Validators/skill/SkillStoreValidator";
|
||||
import SkillUpdateValidator from "App/Validators/skill/SkillUpdateValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import File from 'App/Models/File'
|
||||
import Skill from 'App/Models/Skill'
|
||||
import SkillStoreValidator from 'App/Validators/skill/SkillStoreValidator'
|
||||
import SkillUpdateValidator from 'App/Validators/skill/SkillUpdateValidator'
|
||||
|
||||
export default class SkillsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const skills = await Skill
|
||||
.query()
|
||||
.preload('file')
|
||||
return response.status(200).send({
|
||||
skills: skills
|
||||
skills,
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(SkillStoreValidator)
|
||||
const skill = await Skill.create(data)
|
||||
|
||||
@@ -23,19 +22,19 @@ export default class SkillsController {
|
||||
if (cover) await skill.related('file').associate(cover)
|
||||
|
||||
return response.status(200).send({
|
||||
skill: skill
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
skill.load('file')
|
||||
return response.status(200).send({
|
||||
skill
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(SkillUpdateValidator)
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
|
||||
@@ -44,16 +43,15 @@ export default class SkillsController {
|
||||
await skill.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
skill
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
await skill.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Skill successfully deleted!'
|
||||
message: 'Skill successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,31 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
||||
import StateSleepingValidator from "App/Validators/states/StateSleepingValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Redis from '@ioc:Adonis/Addons/Redis'
|
||||
import StateSleepingValidator from 'App/Validators/states/StateSleepingValidator'
|
||||
|
||||
export default class StatesController {
|
||||
|
||||
// Listening Music
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const sleeping = this.formatValue(await Redis.get('states:sleeping'))
|
||||
const developing = this.formatValue(await Redis.get('states:developing'))
|
||||
return response.status(200).send({
|
||||
sleeping,
|
||||
developing,
|
||||
listening_music: "Soon"
|
||||
listening_music: 'Soon',
|
||||
})
|
||||
}
|
||||
|
||||
public async setSleeping ({ request, response }: HttpContextContract) {
|
||||
public async setSleeping({ request, response }: HttpContextContract) {
|
||||
const { value } = await request.validate(StateSleepingValidator)
|
||||
await Redis.set('states:sleeping', String(value))
|
||||
await Redis.set('states:developing', String(!value))
|
||||
return response.status(200).send({
|
||||
message: 'State was successfully set!',
|
||||
value: this.formatValue(String(value))
|
||||
value: this.formatValue(String(value)),
|
||||
})
|
||||
}
|
||||
|
||||
public formatValue(value: string | null): string {
|
||||
return value === 'true' ? 'Yes' : 'No'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import CommandsRun from "App/Models/CommandsRun";
|
||||
import BuildsRun from "App/Models/BuildsRun";
|
||||
import CommandsRun from 'App/Models/CommandsRun'
|
||||
import BuildsRun from 'App/Models/BuildsRun'
|
||||
import {
|
||||
fetchDailyStatistics,
|
||||
fetchMonthlyStatistics,
|
||||
fetchStatistics,
|
||||
fetchWeeklyStatistics,
|
||||
NOW
|
||||
} from "App/Utils/StatsUtils";
|
||||
NOW,
|
||||
} from 'App/Utils/StatsUtils'
|
||||
|
||||
export default class StatsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const daily = await fetchDailyStatistics()
|
||||
const weekly = await fetchWeeklyStatistics()
|
||||
const monthly = await fetchMonthlyStatistics()
|
||||
@@ -25,46 +24,45 @@ export default class StatsController {
|
||||
development_time: total.development_time,
|
||||
commands_run: total.commands_ran,
|
||||
builds_run: total.builds_ran,
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
public async incrementCommandCount({ response }: HttpContextContract) {
|
||||
const current_commands = await CommandsRun.firstOrCreate(
|
||||
{
|
||||
date: NOW
|
||||
date: NOW,
|
||||
},
|
||||
{
|
||||
date: NOW,
|
||||
commands: 0
|
||||
}
|
||||
commands: 0,
|
||||
},
|
||||
)
|
||||
|
||||
current_commands.commands++
|
||||
await current_commands.save()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'Commands Count successfully incremented!'
|
||||
message: 'Commands Count successfully incremented!',
|
||||
})
|
||||
}
|
||||
|
||||
public async incrementBuildCount({ response }: HttpContextContract) {
|
||||
const current_builds = await BuildsRun.firstOrCreate(
|
||||
{
|
||||
date: NOW
|
||||
date: NOW,
|
||||
},
|
||||
{
|
||||
date: NOW,
|
||||
builds: 0
|
||||
}
|
||||
builds: 0,
|
||||
},
|
||||
)
|
||||
|
||||
current_builds.builds++
|
||||
await current_builds.save()
|
||||
|
||||
return response.status(200).send({
|
||||
message: 'Builds Count successfully incremented!'
|
||||
message: 'Builds Count successfully incremented!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +1,28 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import Subscriber from "App/Models/Subscriber";
|
||||
import SubscriberStoreValidator from "App/Validators/subscriber/SubscriberStoreValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Subscriber from 'App/Models/Subscriber'
|
||||
import SubscriberStoreValidator from 'App/Validators/subscriber/SubscriberStoreValidator'
|
||||
|
||||
export default class SubscribersController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const subscribers = await Subscriber.query()
|
||||
return response.status(200).send({
|
||||
count: subscribers.length,
|
||||
subscribers: subscribers
|
||||
subscribers,
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(SubscriberStoreValidator)
|
||||
return response.status(200).send({
|
||||
subscriber: await Subscriber.create(data)
|
||||
subscriber: await Subscriber.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ params, response }: HttpContextContract) {
|
||||
public async destroy({ params, response }: HttpContextContract) {
|
||||
const subscriber = await Subscriber.findOrFail(params.id)
|
||||
await subscriber.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Subscriber successfully deleted!'
|
||||
message: 'Subscriber successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,58 +1,55 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import TagStoreValidator from "App/Validators/tag/TagStoreValidator";
|
||||
import TagUpdateValidator from "App/Validators/tag/TagUpdateValidator";
|
||||
import Tag from "App/Models/Tag";
|
||||
import {getTranslation} from "App/Utils/TranslationsUtils";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import TagStoreValidator from 'App/Validators/tag/TagStoreValidator'
|
||||
import TagUpdateValidator from 'App/Validators/tag/TagUpdateValidator'
|
||||
import Tag from 'App/Models/Tag'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class TagsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const tags = await Tag
|
||||
.query()
|
||||
.preload('label')
|
||||
return response.status(200).send({
|
||||
tags: tags
|
||||
tags,
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(TagStoreValidator)
|
||||
const tag = await Tag.create({})
|
||||
|
||||
await tag.related('label').associate(await getTranslation(data.label))
|
||||
|
||||
return response.status(200).send({
|
||||
tag: tag
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
tag.load('label')
|
||||
return response.status(200).send({
|
||||
tag
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(TagUpdateValidator)
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
|
||||
if (data.label) {
|
||||
if (data.label)
|
||||
await tag.related('label').associate(await getTranslation(data.label))
|
||||
}
|
||||
|
||||
return response.status(200).send({
|
||||
tag
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
await tag.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Tag successfully deleted!'
|
||||
message: 'Tag successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +1,43 @@
|
||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||
import Translation from "App/Models/Translation";
|
||||
import TranslationStoreValidator from "App/Validators/translation/TranslationStoreValidator";
|
||||
import TranslationUpdateValidator from "App/Validators/translation/TranslationUpdateValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Translation from 'App/Models/Translation'
|
||||
import TranslationStoreValidator from 'App/Validators/translation/TranslationStoreValidator'
|
||||
import TranslationUpdateValidator from 'App/Validators/translation/TranslationUpdateValidator'
|
||||
|
||||
export default class TranslationsController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translations: await Translation.query().orderBy('id', 'asc')
|
||||
translations: await Translation.query().orderBy('id', 'asc'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(TranslationStoreValidator)
|
||||
return response.status(200).send({
|
||||
translation: await Translation.create(data)
|
||||
translation: await Translation.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translation: await Translation.findOrFail(params.id)
|
||||
translation: await Translation.findOrFail(params.id),
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
const data = await request.validate(TranslationUpdateValidator)
|
||||
await translation.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
translation
|
||||
translation,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params }: HttpContextContract) {
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
await translation.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Translation successfully deleted!'
|
||||
message: 'Translation successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +1,48 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from "App/Models/User";
|
||||
import UserStoreValidator from "App/Validators/user/UserStoreValidator";
|
||||
import UserUpdateValidator from "App/Validators/user/UserUpdateValidator";
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import User from 'App/Models/User'
|
||||
import UserStoreValidator from 'App/Validators/user/UserStoreValidator'
|
||||
import UserUpdateValidator from 'App/Validators/user/UserUpdateValidator'
|
||||
|
||||
export default class UsersController {
|
||||
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
users: await User.all()
|
||||
users: await User.all(),
|
||||
})
|
||||
}
|
||||
|
||||
public async store ({ request, response }: HttpContextContract) {
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(UserStoreValidator)
|
||||
return response.status(200).send({
|
||||
user: await User.create(data)
|
||||
user: await User.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
user: await User.findOrFail(params.id)
|
||||
user: await User.findOrFail(params.id),
|
||||
})
|
||||
}
|
||||
|
||||
public async update ({ request, params, response }: HttpContextContract) {
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const user = await User.findOrFail(params.id)
|
||||
const data = await request.validate(UserUpdateValidator)
|
||||
await user.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
user
|
||||
user,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy ({ response, params, auth }: HttpContextContract) {
|
||||
public async destroy({ response, params, auth }: HttpContextContract) {
|
||||
const user = await User.findOrFail(params.id)
|
||||
const admin = await User.findBy('email', 'arthurdanjou@outlook.fr')
|
||||
|
||||
if (auth.user?.id != admin?.id) {
|
||||
if (auth.user?.id !== admin?.id)
|
||||
return response.unauthorized()
|
||||
}
|
||||
|
||||
await user.delete()
|
||||
return response.status(200).send({
|
||||
message: 'User successfully deleted!'
|
||||
message: 'User successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user