SubmissionController.js
Home
/
app /
Controllers /
Http /
SubmissionController.js
'use strict'
/** @typedef {import('@adonisjs/framework/src/Request')} Request */
/** @typedef {import('@adonisjs/framework/src/Response')} Response */
/** @typedef {import('@adonisjs/framework/src/View')} View */
const Submission = use('App/Models/Submission')
const Element = use('App/Models/Element')
const Steward = use('App/Models/Steward')
const Status = use('App/Models/Status')
const { validate, validateAll } = use('Validator')
const Env = use('Env')
/**
* Resourceful controller for interacting with submissions
*/
class SubmissionController {
/**
* Show a list of all submissions.
* GET submissions
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
* @param {View} ctx.view
*/
async index ({ request, response, view }) {
const submissions = await Submission.query()
.with('element')
.with('element.theme')
.with('steward.contact')
.with('status')
.orderBy('created_at', 'desc')
.fetch()
return view.render('submissions.index', {
submissions: submissions.toJSON()
})
}
/**
* Render a form to be used for creating a new submission.
* GET submissions/create
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
* @param {View} ctx.view
*/
async create ({ request, response, view }) {
const elements = await Element.all()
const stewards = await Steward.query().with('contact').fetch()
const status = await Status.all()
return view.render('submissions.create', {
elements: elements.toJSON(),
stewards: stewards.toJSON(),
statuses: status.toJSON()
})
}
/**
* Create/save a new submission.
* POST submissions
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
*/
async store ({ request, response, session }) {
const data = request.only(['name', 'upload_date',
'creation_date', 'published_date', 'element_id',
'steward_id', 'public', 'status_id'])
const validation = await validateAll(data, {
'name': 'required',
'element_id': 'required',
'steward_id': 'required',
'public': 'required',
'status_id': 'required'
})
if(validation.fails()) {
session
.withErrors(validation.messages())
.flashAll()
return response.redirect('back')
}
await Submission.create(data)
return response.redirect(Env.get('APP_URL') + '/submissions')
}
/**
* Display a single submission.
* GET submissions/:id
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
* @param {View} ctx.view
*/
async show ({ params, request, response, view }) {
}
/**
* Render a form to update an existing submission.
* GET submissions/:id/edit
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
* @param {View} ctx.view
*/
async edit ({ params, request, response, view }) {
}
/**
* Update submission details.
* PUT or PATCH submissions/:id
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
*/
async update ({ params, request, response }) {
}
/**
* Delete a submission with id.
* DELETE submissions/:id
*
* @param {object} ctx
* @param {Request} ctx.request
* @param {Response} ctx.response
*/
async destroy ({ params, request, response }) {
}
}
module.exports = SubmissionController