DBLabs/abitur_list_client/controllers/examresult.controller.js

32 lines
1.3 KiB
JavaScript
Raw Normal View History

const db = require('../db')
const ExamResultControllerInterface = require('./interfaces/examresult.controller.interface')
class ExamResultController extends ExamResultControllerInterface {
async createExamResult(req, res) {
const {title, result, abitur_id} = req.body
const newExamResult = await db.query('INSERT INTO exam_result (title, result, abitur_id) VALUES ($1, $2, $3) RETURNING *', [title, result, abitur_id])
res.json(newExamResult.rows[0])
}
async getExamResults(req, res) {
const results = await db.query('SELECT * FROM exam_result')
res.json(results.rows)
}
async getOneExamResult(req, res) {
const id = req.params.id
const results = await db.query('SELECT * FROM exam_result WHERE id=$1', [id])
res.json(results.rows[0])
}
async updateExamResult(req, res) {
const {id, title, result} = req.body
const newExamResult = await db.query('UPDATE exam_result SET title=$1, result=$2 WHERE id=$3 RETURNING *', [title, result, id])
res.json(newExamResult.rows[0])
}
async deleteExamResult(req, res) {
const id = req.params.id
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [id])
res.json(results.rows[0])
}
}
module.exports = new ExamResultController()