DBLabs/abitur_list_client/controllers/specialization.controller.js

32 lines
1.3 KiB
JavaScript
Raw Normal View History

const db = require('../db')
const SpecializationControllerInterface = require('./interfaces/specialization.controller.interface')
class SpecializationController extends SpecializationControllerInterface {
async createSpecialization(req, res) {
const {title} = req.body
const newSpecialization = await db.query('INSERT INTO specialization (title) VALUES ($1) RETURNING *', [title])
res.json(newSpecialization.rows[0])
}
async getSpecializations(req, res) {
const specializations = await db.query('SELECT * FROM specialization')
res.json(specializations.rows)
}
async getOneSpecialization(req, res) {
const id = req.params.id
const specializations = await db.query('SELECT * FROM specialization WHERE id=$1', [id])
res.json(specializations.rows[0])
}
async updateSpecialization(req, res) {
const {id, title} = req.body
const newSpecialization = await db.query('UPDATE specialization SET title=$1 WHERE id=$2 RETURNING *', [title, id])
res.json(newSpecialization.rows[0])
}
async deleteSpecialization(req, res) {
const id = req.params.id
const specializations = await db.query('DELETE FROM specialization WHERE id=$1', [id])
res.json(specializations.rows[0])
}
}
module.exports = new SpecializationController()