2023-03-31 23:19:54 +04:00
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 ] )
}
2023-04-29 14:20:44 +04:00
async createExamResultWithId ( req , res ) {
const { id , title , result , abitur _id } = req . body
const newExamResult = await db . query ( 'INSERT INTO exam_result (id, title, result, abitur_id) VALUES ($1, $2, $3, $4) RETURNING *' , [ id , title , result , abitur _id ] )
res . json ( newExamResult . rows [ 0 ] )
}
2023-03-31 23:19:54 +04:00
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 ] )
}
2023-04-03 01:00:37 +04:00
async getAbiturExamResults ( req , res ) {
const id = req . params . id
const results = await db . query ( 'SELECT * FROM exam_result WHERE abitur_id=$1' , [ id ] )
res . json ( results . rows )
}
2023-04-29 14:20:44 +04:00
async getAverageResultBySpecialization ( req , res ) {
const id = req . params . id
const result = await db . query ( 'select avg(result) from exam_result where id in (select exam_result_id from request_exam_result where request_id in (select id from request where specialization_id = $1))' , [ id ] )
res . json ( result . rows [ 0 ] )
}
2023-03-31 23:19:54 +04:00
}
module . exports = new ExamResultController ( )