const db = require('../db') const RequestControllerInterface = require('./interfaces/request.controller.interface') class RequestController extends RequestControllerInterface { async createRequest(req, res) { const {abitur_id, education_form_id, specialization_id} = req.body const newRequest = await db.query('INSERT INTO request (abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4) RETURNING *', [abitur_id, education_form_id, specialization_id, new Date()]) res.json(newRequest.rows[0]) } async getRequests(req, res) { const requests = await db.query('SELECT * FROM request') res.json(requests.rows) } async getOneRequest(req, res) { const id = req.params.id const requests = await db.query('SELECT * FROM request WHERE id=$1', [id]) res.json(requests.rows[0]) } async updateRequest(req, res) { const {id, education_form_id, specialization_id, date} = req.body const newRequest = await db.query('UPDATE request SET education_form_id=$1, specialization_id=$2, date=$3 WHERE id=$4 RETURNING *', [education_form_id, specialization_id, date, id]) res.json(newRequest.rows[0]) } async deleteRequest(req, res) { const id = req.params.id const requests = await db.query('DELETE FROM request WHERE id=$1', [id]) res.json(requests.rows[0]) } } module.exports = new RequestController()