32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
const db = require('../db')
|
|
|
|
const AbiturControllerInterface = require('../controllers/abitur.controller.interface')
|
|
|
|
class AbiturController extends AbiturControllerInterface{
|
|
async createAbitur(req, res) {
|
|
const {first_name, last_name, middle_name} = req.body
|
|
const newAbitur = await db.query('INSERT INTO abitur (first_name, last_name, middle_name) VALUES ($1, $2, $3) RETURNING *', [first_name, last_name, middle_name])
|
|
res.json(newAbitur.rows[0])
|
|
}
|
|
async getAbiturs(req, res) {
|
|
const abiturs = await db.query('SELECT * FROM abitur')
|
|
res.json(abiturs.rows)
|
|
}
|
|
async getOneAbitur(req, res) {
|
|
const id = req.params.id
|
|
const abiturs = await db.query('SELECT * FROM abitur WHERE id=$1', [id])
|
|
res.json(abiturs.rows[0])
|
|
}
|
|
async updateAbitur(req, res) {
|
|
const {id, first_name, last_name, middle_name} = req.body
|
|
const newAbitur = await db.query('UPDATE abitur SET first_name=$1, last_name=$2, middle_name=$3 WHERE id=$4 RETURNING *', [first_name, last_name, middle_name, id])
|
|
res.json(newAbitur.rows[0])
|
|
}
|
|
async deleteAbitur(req, res) {
|
|
const id = req.params.id
|
|
const abiturs = await db.query('DELETE FROM abitur WHERE id=$1', [id])
|
|
res.json(abiturs.rows[0])
|
|
}
|
|
}
|
|
|
|
module.exports = new AbiturController() |