2023-03-31 23:19:54 +04:00
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 ] )
}
2023-04-29 14:20:44 +04:00
async createRequestWithId ( req , res ) {
const { id , abitur _id , education _form _id , specialization _id } = req . body
const newRequest = await db . query ( 'INSERT INTO request (id, abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4, $5) RETURNING *' , [ id , abitur _id , education _form _id , specialization _id , new Date ( ) ] )
res . json ( newRequest . rows [ 0 ] )
}
2023-03-31 23:19:54 +04:00
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 ] )
}
2023-04-03 01:00:37 +04:00
async getAbiturRequests ( req , res ) {
const id = req . params . id
const requests = await db . query ( 'SELECT * FROM request WHERE abitur_id=$1' , [ id ] )
res . json ( requests . rows )
}
2023-04-29 14:20:44 +04:00
async getCountBySpec ( req , res ) {
const id = req . params . id
const requests = await db . query ( 'SELECT COUNT(*) FROM request WHERE specialization_id=$1' , [ id ] )
res . json ( requests . rows [ 0 ] )
}
2023-03-31 23:19:54 +04:00
}
module . exports = new RequestController ( )