diff --git a/all/node-postgres/config.json b/all/node-postgres/config.json index 1bee88d..2e3dc12 100644 --- a/all/node-postgres/config.json +++ b/all/node-postgres/config.json @@ -3,5 +3,6 @@ "host" : "192.168.56.105", "database" : "StudentsMarksBook", "password" : "password", - "port" : "5432" + "port" : "5432", + "mongodb" : "mongodb://127.0.0.1:27017/" } \ No newline at end of file diff --git a/all/node-postgres/index.js b/all/node-postgres/index.js deleted file mode 100644 index 77d8947..0000000 --- a/all/node-postgres/index.js +++ /dev/null @@ -1,267 +0,0 @@ -const express = require('express') -const cors = require('cors') -const faculty = require('./models/faculty') -const direction = require('./models/direction') -const subject = require('./models/subject') -const teacher = require('./models/teacher') -const test = require('./models/test') -const student = require('./models/student') -const score = require('./models/score') - -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)) -}) - -app.get('/faculty/tests', (req, res) => { - faculty.timeTests() - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/faculty', (req, res) => { - faculty.get() - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/faculty/directions/:id', (req, res) => { - faculty.getDirections(req.params.id) - .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)) -}) -//---------------------------------------------- - -// 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/tests', (req, res) => { - test.timeTests() - .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/tests', (req, res) => { - teacher.timeTests() - .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)) -}) -//---------------------------------------------- - - -// SUBJECT------------------------------------- -app.post('/subject', (req, res) => { - subject.create(req.body.name, req.body.hours_count) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/subject/tests', (req, res) => { - subject.timeTests() - .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) => { - subject.update(req.params.id, req.body.name, req.body.hours_count) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) -//---------------------------------------------- - -// DIRECTION------------------------------------- -app.post('/direction', (req, res) => { - direction.create(req.body.name, req.body.faculty_id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/direction/tests', (req, res) => { - direction.timeTests() - .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) => { - 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) => { - student.create(req.body.name, req.body.surname, req.body.record_book, req.body.direction_id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/student/tests', (req, res) => { - student.timeTests() - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.post('/student/test', (req, res) => { - student.createTest() -}) - -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) => { - student.update(req.params.id, req.body.name, req.body.surname, req.body.record_book, req.body.direction_id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) -//---------------------------------------------- - -// SCORE------------------------------------- -app.post('/score', (req, res) => { - score.create(req.body.value, req.body.subject_id, req.body.test_type_id, req.body.teacher_id, req.body.student_id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/score/tests', (req, res) => { - score.timeTests() - .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) => { - score.update(req.params.id, req.body.value, req.body.subject_id, req.body.test_type_id, req.body.teacher_id, req.body.student_id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) - -app.get('/score/studMarks/:id', (req, res) => { - score.getStudentMarks(req.params.id) - .then(response => res.status(200).send(response)) - .catch(error => res.status(500).send(error)) -}) -//---------------------------------------------- - -app.listen(port, () => { - console.log(`app runnong on port ${port}`) -}) \ No newline at end of file diff --git a/all/node-postgres/mongo.js b/all/node-postgres/mongo.js new file mode 100644 index 0000000..95c2760 --- /dev/null +++ b/all/node-postgres/mongo.js @@ -0,0 +1,109 @@ +const express = require('express') +const config = require('./config.json') +const cors = require('cors') +const { MongoClient, ObjectId } = require('mongodb') +const client = new MongoClient(config.mongodb) + +const app = express() +const port = 3002 + +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(); +}); + +(async () => { + try { + await client.connect() + }catch(err) { + return console.log(err); + } +})(); + +// require('./mongoControllers/scoreC')(app,client) + +app.post('/m/score', async (req, res) =>{ + const score = { + subject: req.body.subject, + value: req.body.value, + test_type: req.body.test_type, + record_book: req.body.record_book, + student: req.body.student, + teacher: req.body.teacher, + date: req.body.date + } + await client.db("labwork07").collection('score').insertOne(score,(err,result) => { + if(err) res.send({'error': 'An error has occurred'}) + else res.send(result) + console.log(res) + console.log(res.ops[0]) + }) +}) + +app.get('/m/score', async (req, res) =>{ + try{ + const scores = await client.db("labwork07").collection('score').find({}).toArray() + res.send(scores) + }catch(err){ + console.log(err) + res.sendStatus(500) + } +}) + +app.post('/m/score/mStudMarks', async (req, res) =>{ + try{ + const scores = await client.db("labwork07").collection('score').find({student: req.body.student}).toArray() + res.send(scores) + }catch(err){ + console.log(err) + res.sendStatus(500) + } +}) + +app.delete("/m/score/del/:id", async(req, res)=>{ + try{ + const result = await client.db("labwork07").collection('score').deleteOne({_id: new ObjectId(req.params.id)}) + if(result.acknowledged) res.sendStatus(200) + else res.sendStatus(404) + } + catch(err){ + console.log(err) + res.sendStatus(500) + } +}) + +app.put("/m/score/upd/:id", async(req, res)=>{ + try{ + const result = await client.db("labwork07").collection('score').updateOne({_id: new ObjectId(req.params.id)},{ $set: { + subject: req.body.subject, + value: req.body.value, + test_type: req.body.test_type, + record_book: req.body.record_book, + student: req.body.student, + teacher: req.body.teacher, + date: req.body.date + }}) + if(result.acknowledged) res.sendStatus(200) + else res.sendStatus(404) + } + catch(err){ + console.log(err) + res.sendStatus(500) + } +}) + +app.listen(port, () => { + console.log(`app running on port ${port}`) +}) + +// прослушиваем прерывание работы программы (ctrl-c) +process.on("SIGINT", async() => { + await client.close() + console.log("Приложение завершило работу") + process.exit() +}); \ No newline at end of file diff --git a/all/node-postgres/mongoControllers/mainC.js b/all/node-postgres/mongoControllers/mainC.js new file mode 100644 index 0000000..6ab0955 --- /dev/null +++ b/all/node-postgres/mongoControllers/mainC.js @@ -0,0 +1,5 @@ +const score = require('./scoreC') + +module.exports = function(app, db){ + score.all(app) +} \ No newline at end of file diff --git a/all/node-postgres/mongoControllers/scoreC.js b/all/node-postgres/mongoControllers/scoreC.js new file mode 100644 index 0000000..d9a0f22 --- /dev/null +++ b/all/node-postgres/mongoControllers/scoreC.js @@ -0,0 +1,32 @@ +const config = require('../config.json') +const { MongoClient } = require('mongodb') + +module.exports = function(app, client){ + app.post('/m/score', async (req, res) =>{ + + const score = { + subject: req.body.subject, + value: req.body.value, + test_type: req.body.test_type, + record_book: req.body.record_book, + student: req.body.student, + teacher: req.body.teacher, + date: req.body.date + } + await client.db("labwork07").collection('score').insertOne(score,(err,result) => { + if(err) res.send({'error': 'An error has occurred'}) + else res.send(result) + console.log(res) + console.log(res.ops[0]) + }) + }) + + app.get('/m/score', async (req, res) =>{ + await client.db("labwork07").collection('score').find((err,result) => { + if(err) res.send({'error': 'An error has occurred'}) + else res.send(result) + console.log(res) + console.log(res.ops[0]) + }) + }) +} diff --git a/all/node-postgres/mongoControllers/scoreModel.js b/all/node-postgres/mongoControllers/scoreModel.js new file mode 100644 index 0000000..e69de29 diff --git a/all/node-postgres/package-lock.json b/all/node-postgres/package-lock.json index f77fe43..c173d19 100644 --- a/all/node-postgres/package-lock.json +++ b/all/node-postgres/package-lock.json @@ -11,9 +11,38 @@ "dependencies": { "cors": "^2.8.5", "express": "^4.18.2", + "mongodb": "^5.5.0", "pg": "^8.10.0" + }, + "devDependencies": { + "nodemon": "^2.0.22" } }, + "node_modules/@types/node": { + "version": "20.1.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.1.4.tgz", + "integrity": "sha512-At4pvmIOki8yuwLtd7BNHl3CiWNbtclUbNtScGx4OHfBd4/oWoJC8KRCIxXwkdndzhxOsPXihrsOoydxBjlE9Q==" + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-xTE1E+YF4aWPJJeUzaZI5DRntlkY3+BCVJi0axFptnjGmAoWxkyREIh/XMrfxVLejwQxMCfDXdICo0VLxThrog==" + }, + "node_modules/@types/whatwg-url": { + "version": "8.2.2", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-8.2.2.tgz", + "integrity": "sha512-FtQu10RWgn3D9U4aazdwIE2yzphmTJREDqNdODHrbrZmmMqI0vMheC/6NE/J1Yveaj8H+ela+YwWTjq5PGmuhA==", + "dependencies": { + "@types/node": "*", + "@types/webidl-conversions": "*" + } + }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "dev": true + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -26,11 +55,39 @@ "node": ">= 0.6" } }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dev": true, + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/array-flatten": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "integrity": "sha512-PCVAQswWemu6UdxsDFFX/+gVeYqKAod3D3UVm91jHwynguOwAvYPhx8nNlM++NqRcK6CxxpUafjmhIdKiHibqg==" }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "dev": true + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/body-parser": { "version": "1.20.1", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.1.tgz", @@ -54,6 +111,36 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dev": true, + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/bson": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-5.3.0.tgz", + "integrity": "sha512-ukmCZMneMlaC5ebPHXIkP8YJzNl5DC41N5MAIvKDqLggdao342t4McltoJBQfQya/nHBWAcSsYRqlXPoQkTJag==", + "engines": { + "node": ">=14.20.1" + } + }, "node_modules/buffer-writer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/buffer-writer/-/buffer-writer-2.0.0.tgz", @@ -82,6 +169,39 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "dev": true + }, "node_modules/content-disposition": { "version": "0.5.4", "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz", @@ -218,6 +338,18 @@ "node": ">= 0.10.0" } }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dev": true, + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/finalhandler": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.2.0.tgz", @@ -251,6 +383,20 @@ "node": ">= 0.6" } }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -269,6 +415,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -280,6 +438,15 @@ "node": ">= 0.4.0" } }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/has-symbols": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", @@ -317,11 +484,22 @@ "node": ">=0.10.0" } }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==", + "dev": true + }, "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, + "node_modules/ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", + "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + }, "node_modules/ipaddr.js": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", @@ -330,6 +508,48 @@ "node": ">= 0.10" } }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "dev": true, + "engines": { + "node": ">=0.12.0" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -338,6 +558,12 @@ "node": ">= 0.6" } }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "optional": true + }, "node_modules/merge-descriptors": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", @@ -381,6 +607,59 @@ "node": ">= 0.6" } }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/mongodb": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-5.5.0.tgz", + "integrity": "sha512-XgrkUgAAdfnZKQfk5AsYL8j7O99WHd4YXPxYxnh8dZxD+ekYWFRA3JktUsBnfg+455Smf75/+asoU/YLwNGoQQ==", + "dependencies": { + "bson": "^5.3.0", + "mongodb-connection-string-url": "^2.6.0", + "socks": "^2.7.1" + }, + "engines": { + "node": ">=14.20.1" + }, + "optionalDependencies": { + "saslprep": "^1.0.3" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.201.0", + "mongodb-client-encryption": ">=2.3.0 <3", + "snappy": "^7.2.2" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-2.6.0.tgz", + "integrity": "sha512-WvTZlI9ab0QYtTYnuMLgobULWhokRjtC7db9LtcVfJ+Hsnyr5eo6ZtNAt3Ly24XZScGMelOcGtm7lSn0332tPQ==", + "dependencies": { + "@types/whatwg-url": "^8.2.1", + "whatwg-url": "^11.0.0" + } + }, "node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -394,6 +673,73 @@ "node": ">= 0.6" } }, + "node_modules/nodemon": { + "version": "2.0.22", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.22.tgz", + "integrity": "sha512-B8YqaKMmyuCO7BowF1Z1/mkPqLk6cs/l63Ojtd6otKjMx47Dq1utxfRxcavH1I7VSaL8n5BUaoutadnsX3AAVQ==", + "dev": true, + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^3.2.7", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^5.7.1", + "simple-update-notifier": "^1.0.7", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=8.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/nodemon/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "node_modules/nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", + "dev": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": "*" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -513,6 +859,18 @@ "split2": "^4.1.0" } }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/postgres-array": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", @@ -560,6 +918,20 @@ "node": ">= 0.10" } }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==", + "dev": true + }, + "node_modules/punycode": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.0.tgz", + "integrity": "sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA==", + "engines": { + "node": ">=6" + } + }, "node_modules/qs": { "version": "6.11.0", "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", @@ -596,6 +968,18 @@ "node": ">= 0.8" } }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dev": true, + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", @@ -620,6 +1004,27 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "node_modules/saslprep": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", + "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", + "optional": true, + "dependencies": { + "sparse-bitfield": "^3.0.3" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, "node_modules/send": { "version": "0.18.0", "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", @@ -680,6 +1085,58 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/simple-update-notifier": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", + "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "dev": true, + "dependencies": { + "semver": "~7.0.0" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/simple-update-notifier/node_modules/semver": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", + "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", + "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "dependencies": { + "ip": "^2.0.0", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.13.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "optional": true, + "dependencies": { + "memory-pager": "^1.0.2" + } + }, "node_modules/split2": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", @@ -696,6 +1153,30 @@ "node": ">= 0.8" } }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dev": true, + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dev": true, + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, "node_modules/toidentifier": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", @@ -704,6 +1185,29 @@ "node": ">=0.6" } }, + "node_modules/touch": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", + "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", + "dev": true, + "dependencies": { + "nopt": "~1.0.10" + }, + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/tr46": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-3.0.0.tgz", + "integrity": "sha512-l7FvfAHlcmulp8kr+flpQZmVwtu7nfRV7NZujtN0OqES8EL4O4e0qqzL0DC5gAvx/ZC/9lk6rhcUwYvkBnBnYA==", + "dependencies": { + "punycode": "^2.1.1" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/type-is": { "version": "1.6.18", "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", @@ -716,6 +1220,12 @@ "node": ">= 0.6" } }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==", + "dev": true + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", @@ -740,6 +1250,26 @@ "node": ">= 0.8" } }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-11.0.0.tgz", + "integrity": "sha512-RKT8HExMpoYx4igMiVMY83lN6UeITKJlBQ+vR/8ZJ8OCdSiN3RwCq+9gH0+Xzj0+5IrM6i4j/6LuvzbZIQgEcQ==", + "dependencies": { + "tr46": "^3.0.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", diff --git a/all/node-postgres/package.json b/all/node-postgres/package.json index 89b1c41..3a192cb 100644 --- a/all/node-postgres/package.json +++ b/all/node-postgres/package.json @@ -4,13 +4,18 @@ "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "dev": "nodemon server.js" }, "author": "", "license": "ISC", "dependencies": { "cors": "^2.8.5", "express": "^4.18.2", + "mongodb": "^5.5.0", "pg": "^8.10.0" + }, + "devDependencies": { + "nodemon": "^2.0.22" } } diff --git a/all/node-postgres/postgres.js b/all/node-postgres/postgres.js new file mode 100644 index 0000000..89f21e2 --- /dev/null +++ b/all/node-postgres/postgres.js @@ -0,0 +1,28 @@ +const express = require('express') +const cors = require('cors') + +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(); +}); + +require('./postgresControllers/facultyC')(app) +require('./postgresControllers/directionC')(app) +require('./postgresControllers/scoreC')(app) +require('./postgresControllers/studentC')(app) +require('./postgresControllers/subjectC')(app) +require('./postgresControllers/teacherC')(app) +require('./postgresControllers/testC')(app) + + +app.listen(port, () => { + console.log(`app running on port ${port}`) +}) \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/directionC.js b/all/node-postgres/postgresControllers/directionC.js new file mode 100644 index 0000000..ff515cf --- /dev/null +++ b/all/node-postgres/postgresControllers/directionC.js @@ -0,0 +1,33 @@ +const direction = require('../models/direction') + +module.exports = function (app) { + app.post('/direction', (req, res) => { + direction.create(req.body.name, req.body.faculty_id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/direction/tests', (req, res) => { + direction.timeTests() + .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) => { + 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)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/facultyC.js b/all/node-postgres/postgresControllers/facultyC.js new file mode 100644 index 0000000..c0ed1d1 --- /dev/null +++ b/all/node-postgres/postgresControllers/facultyC.js @@ -0,0 +1,39 @@ +const faculty = require('../models/faculty') + +module.exports = function (app) { + app.post('/faculty', (req, res) => { + faculty.create(req.body.name) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/faculty/tests', (req, res) => { + faculty.timeTests() + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/faculty', (req, res) => { + faculty.get() + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/faculty/directions/:id', (req, res) => { + faculty.getDirections(req.params.id) + .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)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/scoreC.js b/all/node-postgres/postgresControllers/scoreC.js new file mode 100644 index 0000000..325c7c1 --- /dev/null +++ b/all/node-postgres/postgresControllers/scoreC.js @@ -0,0 +1,39 @@ +const score = require('../models/score') + +module.exports = function (app) { + app.post('/score', (req, res) => { + score.create(req.body.value, req.body.subject_id, req.body.test_type_id, req.body.teacher_id, req.body.student_id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/score/tests', (req, res) => { + score.timeTests() + .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) => { + score.update(req.params.id, req.body.value, req.body.subject_id, req.body.test_type_id, req.body.teacher_id, req.body.student_id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/score/studMarks/:id', (req, res) => { + score.getStudentMarks(req.params.id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/studentC.js b/all/node-postgres/postgresControllers/studentC.js new file mode 100644 index 0000000..e23ce3c --- /dev/null +++ b/all/node-postgres/postgresControllers/studentC.js @@ -0,0 +1,37 @@ +const student = require('../models/student') + +module.exports = function (app) { + app.post('/student', (req, res) => { + student.create(req.body.name, req.body.surname, req.body.record_book, req.body.direction_id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/student/tests', (req, res) => { + student.timeTests() + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.post('/student/test', (req, res) => { + student.createTest() + }) + + 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) => { + student.update(req.params.id, req.body.name, req.body.surname, req.body.record_book, req.body.direction_id) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/subjectC.js b/all/node-postgres/postgresControllers/subjectC.js new file mode 100644 index 0000000..823bf9d --- /dev/null +++ b/all/node-postgres/postgresControllers/subjectC.js @@ -0,0 +1,33 @@ +const subject = require('../models/subject') + +module.exports = function (app) { + app.post('/subject', (req, res) => { + subject.create(req.body.name, req.body.hours_count) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) + + app.get('/subject/tests', (req, res) => { + subject.timeTests() + .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) => { + subject.update(req.params.id, req.body.name, req.body.hours_count) + .then(response => res.status(200).send(response)) + .catch(error => res.status(500).send(error)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/teacherC.js b/all/node-postgres/postgresControllers/teacherC.js new file mode 100644 index 0000000..6ef0a98 --- /dev/null +++ b/all/node-postgres/postgresControllers/teacherC.js @@ -0,0 +1,33 @@ +const teacher = require('../models/teacher') + +module.exports = function (app) { + 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/tests', (req, res) => { + teacher.timeTests() + .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)) + }) +} \ No newline at end of file diff --git a/all/node-postgres/postgresControllers/testC.js b/all/node-postgres/postgresControllers/testC.js new file mode 100644 index 0000000..47af9fd --- /dev/null +++ b/all/node-postgres/postgresControllers/testC.js @@ -0,0 +1,33 @@ +const test = require('../models/test') + +module.exports = function (app) { + 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/tests', (req, res) => { + test.timeTests() + .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)) + }) +} \ No newline at end of file diff --git a/all/react-postgres/src/App.js b/all/react-postgres/src/App.js index 090aa3b..552a755 100644 --- a/all/react-postgres/src/App.js +++ b/all/react-postgres/src/App.js @@ -11,6 +11,8 @@ import ScorePage from './pages/ScorePage'; import StudentMarks from './reports/StudentMarks'; import FacultyDirections from './reports/FacultyDirections'; import Tests from './tests/Test'; +import MScorePage from './pages/MScorePage'; +import MStudentMarks from './reports/MStudentsMarks'; function App() { return ( @@ -28,6 +30,8 @@ function App() { } /> } /> } /> + } /> + } /> ); diff --git a/all/react-postgres/src/common/Header.jsx b/all/react-postgres/src/common/Header.jsx index 4b1d030..3fd43b4 100644 --- a/all/react-postgres/src/common/Header.jsx +++ b/all/react-postgres/src/common/Header.jsx @@ -72,6 +72,18 @@ export default function Header() { TESTS + +
  • + + MONGO SCORE + +
  • + +
  • + + MONGO STUDENT MARKS + +
  • diff --git a/all/react-postgres/src/common/Service.js b/all/react-postgres/src/common/Service.js index 29fa1f7..8513f3f 100644 --- a/all/react-postgres/src/common/Service.js +++ b/all/react-postgres/src/common/Service.js @@ -7,12 +7,30 @@ export default class Service{ return res } + static async getM(url){ + const response = await fetch(url) + const res = response.json() + return res + } + static async getStudMarks(url, id){ const response = await fetch(`${this.mainUrl}${url}/studMarks/${id}`) const res = response.json() return res } + static async getMStudMarks(url, student){ + const response = await fetch(`${url}/mStudMarks`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({student}) + }) + const res = response.json() + return res + } + static async getFacultyDirections(url, id){ const response = await fetch(`${this.mainUrl}${url}/directions/${id}`) const res = response.json() @@ -40,6 +58,17 @@ export default class Service{ return true } + static async postM(url, item){ + await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(item) + }) + return true + } + static async upd(url, item){ await fetch(`${this.mainUrl}${url}/upd/${item.id}`, { method: 'PUT', @@ -51,10 +80,29 @@ export default class Service{ return true } + static async updM(url, item){ + console.log(item) + await fetch(`${url}/upd/${item._id}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(item) + }) + return true + } + static async del(url, id){ await fetch(`${this.mainUrl}${url}/del/${id}`, { method: 'DELETE' }) return true } + + static async delM(url, id){ + await fetch(`${url}/del/${id}`, { + method: 'DELETE' + }) + return true + } } \ No newline at end of file diff --git a/all/react-postgres/src/models/MScore.js b/all/react-postgres/src/models/MScore.js new file mode 100644 index 0000000..8587e25 --- /dev/null +++ b/all/react-postgres/src/models/MScore.js @@ -0,0 +1,12 @@ +export default class MScore { + constructor(data) { + this._id = data?._id + this.subject = data?.subject + this.value = data?.value + this.test_type = data?.test_type + this.record_book = data?.record_book + this.student = data?.student + this.teacher = data?.teacher + this.date = data?.date + } +} \ No newline at end of file diff --git a/all/react-postgres/src/pages/MScorePage.jsx b/all/react-postgres/src/pages/MScorePage.jsx new file mode 100644 index 0000000..97011df --- /dev/null +++ b/all/react-postgres/src/pages/MScorePage.jsx @@ -0,0 +1,167 @@ +import React, {useState, useEffect} from 'react'; +import Modal from '../common/Modal'; +import Score from '../models/MScore'; +import Service from '../common/Service'; + + +export default function MScorePage() { + const url = 'http://localhost:3002/m/score' + + const [items, setItems] = useState([]) + const [item, setItem] = useState(new Score()) + + const [modalHeader, setModalHeader] = useState('') + const [modalConfirm, setModalConfirm] = useState('') + const [modalVisible, setModalVisible] = useState(false) + const [isEdit, setEdit] = useState(false) + + useEffect(() => { + get() + //eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + function save(){ + if(isEdit) upd() + else create() + get() + } + + function get(){ + Service.getM(url) + .then(data => setItems(data)) + } + + function create(){ + Service.postM(url, item) + .then(() => get()) + } + + function upd(){ + Service.updM(url, item) + .then(() => get()) + } + + function del(id){ + console.log(id) + Service.delM(url, id) + .then(() => get()) + } + + function handleCreate(){ + setEdit(false) + setModalHeader('Create'); + setModalConfirm('Add'); + setModalVisible(true); + } + + function handleFormChange(event) { + setItem(prevState => ({ ...prevState, [event.target.id]: event.target.value })) + } + + function handleEdit(data){ + setItem(data) + setEdit(true) + setModalHeader('Update'); + setModalConfirm('Save'); + setModalVisible(true); + } + + const hideModal = () => setModalVisible(false) + const modalDone = () => save() + + return ( + <> + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + + +
    +
    + +
    + + + + + + + + + + + + + + + + + + + { + items.map((data, index) => + + + + + + + + + + + + ) + } + +
    #subjectvaluetest_typerecord_bookstudentteacherdate
    {index + 1}{data.subject}{data.value}{data.test_type}{data.record_book}{data.student}{data.teacher}{data.date} +
    + + +
    +
    +
    + + ); +} \ No newline at end of file diff --git a/all/react-postgres/src/reports/MStudentsMarks.jsx b/all/react-postgres/src/reports/MStudentsMarks.jsx new file mode 100644 index 0000000..9770a53 --- /dev/null +++ b/all/react-postgres/src/reports/MStudentsMarks.jsx @@ -0,0 +1,82 @@ +import React, {useState, useEffect} from 'react'; +import Student from '../models/Student'; +import Service from '../common/Service'; + +export default function MStudentMarks() { + const url = 'http://localhost:3002/m/score' + + const [items, setItems] = useState([]) + const [item, setItem] = useState('') + + const [students, setStudents] = useState([]) + + + useEffect(() => { + get() + //eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + + function get(){ + let studs = [] + Service.getM(url) + .then(data => { + console.log(data) + setStudents([]) + data.map(item => setStudents(prevState => [...prevState, item.student]))}) + console.log(students) + } + + function handleGetReport(){ + Service.getMStudMarks(url, item) + .then(data => setItems(data)) + } + + function handleFormChange(event) { + setItem(event.target.value) + } + + return ( + <> +
    +
    +

    Student:

    + +
    + + + + + + + + + + + + + + { + items.map((data, index) => + + + + + + + + ) + } + +
    #test typevaluesubjectteacher
    {index + 1}{data.test_type}{data.value}{data.subject}{data.teacher}
    +
    + + ); +} \ No newline at end of file