backend/app/controllers/api/v1/FormCode.controller.js
garrettmills ffb5e35205
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
Improve version modal rendering calls
2021-03-16 10:35:57 -05:00

70 lines
1.7 KiB
JavaScript

const Controller = require('libflitter/controller/Controller')
const Codium = require('../../../models/api/Codium.model')
/*
* FormCode Controller
* -------------------------------------------------------------
* Put some description here!
*/
class FormCode extends Controller {
async create_new(req, res) {
const { page, node } = req.form
const code = new Codium({
NodeId: node.UUID,
PageId: page.UUID,
code: '',
})
if ( req.body.Language ) {
code.Language = req.body.Language
}
if ( req.body.code ) {
code.code = req.body.code
}
if ( req.body.UUID ) {
const existingUUID = await Codium.findOne({ UUID: req.body.UUID })
if ( !existingUUID ) {
code.UUID = req.body.UUID
}
}
await code.version_save(`Added to page "${page.Name}"`, req.user.id)
return res.api(code)
}
async get_config(req, res) {
const { codium } = req.form
if ( req.query.version ) {
return res.api(await codium.as_version(req.query.version))
}
return res.api(codium)
}
async set_values(req, res) {
const { page, node, codium } = req.form
codium.code = req.body.code
codium.Language = req.body.Language
codium.NodeId = node.UUID
codium.PageId = page.UUID
await codium.version_save(`Updated in page "${page.Name}"`, req.user.id)
return res.api(codium)
}
async drop_code(req, res) {
const { codium } = req.form
codium.Active = false
await codium.version_save(`Deleted`, req.user.id)
return res.api({})
}
}
module.exports = exports = FormCode