2023-05-03 00:07:18 +04:00
|
|
|
const express = require('express')
|
|
|
|
const cors = require('cors')
|
|
|
|
const faculty = require('./models/faculty')
|
2023-05-05 23:16:46 +04:00
|
|
|
const direction = require('./models/direction')
|
|
|
|
const subject = require('./models/Subject')
|
|
|
|
const teacher = require('./models/teacher')
|
|
|
|
const test = require('./models/test')
|
2023-05-06 01:37:29 +04:00
|
|
|
const student = require('./models/student')
|
|
|
|
const score = require('./models/score')
|
2023-05-03 00:07:18 +04:00
|
|
|
|
|
|
|
const app = express()
|
|
|
|
const port = 3001
|
|
|
|
|
|
|
|
app.use(cors())
|
|
|
|
|
|
|
|
app.use(express.json())
|
|
|
|
app.use(function (req, res, next) {
|
|
|
|
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000')
|
|
|
|
res.setHeader('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE,OPTIONS')
|
|
|
|
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Access-Control-Allow-Headers')
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
// ФАКУЛЬТЕТ-------------------------------------
|
|
|
|
app.post('/faculty', (req, res) => {
|
|
|
|
faculty.create(req.body.name)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
2023-05-05 23:16:46 +04:00
|
|
|
app.get('/faculty', (req, res) => {
|
2023-05-03 00:07:18 +04:00
|
|
|
faculty.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/faculty/del/:id', (req, res) => {
|
|
|
|
faculty.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/faculty/upd/:id', (req, res) => {
|
|
|
|
faculty.update(req.params.id, req.body.name)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
|
|
|
|
2023-05-05 23:16:46 +04:00
|
|
|
// TEST TYPE-------------------------------------
|
|
|
|
app.post('/test', (req, res) => {
|
|
|
|
test.create(req.body.name)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/test', (req, res) => {
|
|
|
|
test.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/test/del/:id', (req, res) => {
|
|
|
|
test.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/test/upd/:id', (req, res) => {
|
|
|
|
test.update(req.params.id, req.body.name)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
|
|
|
|
|
|
|
// TEACHER-------------------------------------
|
|
|
|
app.post('/teacher', (req, res) => {
|
|
|
|
teacher.create(req.body.name, req.body.surname,req.body.post)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/teacher', (req, res) => {
|
|
|
|
teacher.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/teacher/del/:id', (req, res) => {
|
|
|
|
teacher.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/teacher/upd/:id', (req, res) => {
|
|
|
|
teacher.update(req.params.id, req.body.name, req.body.surname,req.body.post)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
2023-05-03 00:07:18 +04:00
|
|
|
|
|
|
|
|
2023-05-05 23:16:46 +04:00
|
|
|
// SUBJECT-------------------------------------
|
|
|
|
app.post('/subject', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
subject.create(req.body.name, req.body.hours_count)
|
2023-05-05 23:16:46 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/subject', (req, res) => {
|
|
|
|
subject.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/subject/del/:id', (req, res) => {
|
|
|
|
subject.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/subject/upd/:id', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
subject.update(req.params.id, req.body.name, req.body.hours_count)
|
2023-05-05 23:16:46 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
|
|
|
|
|
|
|
// DIRECTION-------------------------------------
|
|
|
|
app.post('/direction', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
direction.create(req.body.name, req.body.faculty_id)
|
2023-05-05 23:16:46 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/direction', (req, res) => {
|
|
|
|
direction.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/direction/del/:id', (req, res) => {
|
|
|
|
direction.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/direction/upd/:id', (req, res) => {
|
2023-05-06 01:37:29 +04:00
|
|
|
direction.update(req.params.id, req.body.name, req.body.facultyId)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
|
|
|
|
|
|
|
// STUDENT-------------------------------------
|
|
|
|
app.post('/student', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
student.create(req.body.name, req.body.surname, req.body.record_book, req.body.direction_id)
|
2023-05-06 01:37:29 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/student', (req, res) => {
|
|
|
|
student.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/student/del/:id', (req, res) => {
|
|
|
|
student.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/student/upd/:id', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
student.update(req.params.id, req.body.name, req.body.surname, req.body.record_book, req.body.direction_id)
|
2023-05-06 01:37:29 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
|
|
|
|
|
|
|
// SCORE-------------------------------------
|
|
|
|
app.post('/score', (req, res) => {
|
2023-05-09 17:44:03 +04:00
|
|
|
score.create(req.body.value, req.body.subject_id, req.body.test_type_id, req.body.teacher_id, req.body.student_id)
|
2023-05-06 01:37:29 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.get('/score', (req, res) => {
|
|
|
|
score.get()
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.delete('/score/del/:id', (req, res) => {
|
|
|
|
score.del(req.params.id)
|
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
|
|
|
|
app.put('/score/upd/:id', (req, res) => {
|
2023-05-06 10:39:09 +04:00
|
|
|
score.update(req.params.id, req.body.value, req.body.subjectId, req.body.testId, req.body.teacherId, req.body.studentId)
|
2023-05-05 23:16:46 +04:00
|
|
|
.then(response => res.status(200).send(response))
|
|
|
|
.catch(error => res.status(500).send(error))
|
|
|
|
})
|
|
|
|
//----------------------------------------------
|
2023-05-03 00:07:18 +04:00
|
|
|
|
|
|
|
app.listen(port, () => {
|
|
|
|
console.log(`app runnong on port ${port}`)
|
|
|
|
})
|