const db = require('../db') const EducationFormControllerInterface = require('./interfaces/educationform.controller.interface') class EducationFormController extends EducationFormControllerInterface { async createEducationForm(req, res) { const {title} = req.body const newEducationForm = await db.query('INSERT INTO education_form (title) VALUES ($1) RETURNING *', [title]) res.json(newEducationForm.rows[0]) } async getEducationForms(req, res) { const forms = await db.query('SELECT * FROM education_form') res.json(forms.rows) } async getOneEducationForm(req, res) { const id = req.params.id const forms = await db.query('SELECT * FROM education_form WHERE id=$1', [id]) res.json(forms.rows[0]) } async updateEducationForm(req, res) { const {id, title} = req.body const newEducationForm = await db.query('UPDATE education_form SET title=$1 WHERE id=$2 RETURNING *', [title, id]) res.json(newEducationForm.rows[0]) } async deleteEducationForm(req, res) { const id = req.params.id const forms = await db.query('DELETE FROM education_form WHERE id=$1', [id]) res.json(forms.rows[0]) } } module.exports = new EducationFormController()