From 5cdd7ec75272d2ee240bcb0819a959d321346161 Mon Sep 17 00:00:00 2001
From: Danila_Mochalov
Date: Sun, 14 May 2023 01:50:44 +0400
Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D0=B0=20?=
=?UTF-8?q?=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20=D0=BF?=
=?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4?=
=?UTF-8?q?=D0=BB=D1=8F=20=D0=BC=D0=B0=D0=BD=D0=B3=D0=BE=D0=B4=D0=B1=20?=
=?UTF-8?q?=D0=9A=D0=A0=D0=9E=D0=9C=D0=95=20=D0=BE=D1=82=D1=87=D0=B5=D1=82?=
=?UTF-8?q?=D0=BE=D0=B2=20(=D1=81=D0=BF=D0=B0=D1=82=D1=8C=20=D1=85=D0=BE?=
=?UTF-8?q?=D1=87=D1=83)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controllers/enrollment.controller.js | 32 ----
.../controllers/examresult.controller.js | 4 +-
.../controllers/request.controller.js | 4 +-
.../mongo/controllers/abitur.controller.js | 123 +++++++++++++++
.../controllers/educationform.controller.js | 37 +++++
.../controllers/examresult.controller.js | 86 +++++++++++
.../mongo/controllers/request.controller.js | 143 ++++++++++++++++++
.../controllers/specialization.controller.js | 37 +++++
abitur_list_client/mongoIndex.js | 20 +++
abitur_list_client/package.json | 3 +-
abitur_list_client/routes/abitur.routes.js | 1 +
.../routes/educationform.routes.js | 1 +
.../routes/enrollment.routes.js | 12 --
.../routes/examresult.routes.js | 3 +-
abitur_list_client/routes/request.routes.js | 5 +-
.../routes/specialization.routes.js | 1 +
.../src/components/AbiturMain.vue | 139 +++++++++++++----
abitur_list_client/src/components/Enter.vue | 8 +-
abitur_list_client/src/components/Request.vue | 123 +++++++++++++--
19 files changed, 684 insertions(+), 98 deletions(-)
delete mode 100644 abitur_list_client/controllers/enrollment.controller.js
create mode 100644 abitur_list_client/mongo/controllers/abitur.controller.js
create mode 100644 abitur_list_client/mongo/controllers/educationform.controller.js
create mode 100644 abitur_list_client/mongo/controllers/examresult.controller.js
create mode 100644 abitur_list_client/mongo/controllers/request.controller.js
create mode 100644 abitur_list_client/mongo/controllers/specialization.controller.js
create mode 100644 abitur_list_client/mongoIndex.js
delete mode 100644 abitur_list_client/routes/enrollment.routes.js
diff --git a/abitur_list_client/controllers/enrollment.controller.js b/abitur_list_client/controllers/enrollment.controller.js
deleted file mode 100644
index 137b573..0000000
--- a/abitur_list_client/controllers/enrollment.controller.js
+++ /dev/null
@@ -1,32 +0,0 @@
-const db = require('../db')
-
-const EnrollmentControllerInterface = require('./interfaces/enrollment.controller.interface')
-
-class EnrollmentController extends EnrollmentControllerInterface {
- async createEnrollment(req, res) {
- const {request_id} = req.body
- const newEnrollment = await db.query('INSERT INTO enrollment (request_id, date) VALUES ($1, $2) RETURNING *', [request_id, new Date()])
- res.json(newEnrollment.rows[0])
- }
- async getEnrollments(req, res) {
- const enrollments = await db.query('SELECT * FROM enrollment')
- res.json(enrollments.rows)
- }
- async getOneEnrollment(req, res) {
- const id = req.params.id
- const enrollments = await db.query('SELECT * FROM enrollment WHERE id=$1', [id])
- res.json(enrollments.rows[0])
- }
- async updateEnrollment(req, res) {
- const {id, request_id, date} = req.body
- const newEnrollment = await db.query('UPDATE enrollment SET request_id=$1, date=$2 WHERE id=$3 RETURNING *', [request_id, date, id])
- res.json(newEnrollment.rows[0])
- }
- async deleteEnrollment(req, res) {
- const id = req.params.id
- const enrollments = await db.query('DELETE FROM enrollment WHERE id=$1', [id])
- res.json(enrollments.rows[0])
- }
-}
-
-module.exports = new EnrollmentController()
\ No newline at end of file
diff --git a/abitur_list_client/controllers/examresult.controller.js b/abitur_list_client/controllers/examresult.controller.js
index c4f0ad1..cf548b4 100644
--- a/abitur_list_client/controllers/examresult.controller.js
+++ b/abitur_list_client/controllers/examresult.controller.js
@@ -28,8 +28,8 @@ class ExamResultController extends ExamResultControllerInterface {
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])
+ const {result_id} = req.body
+ const results = await db.query('DELETE FROM exam_result WHERE id=$1', [result_id])
res.json(results.rows[0])
}
async getAbiturExamResults(req, res) {
diff --git a/abitur_list_client/controllers/request.controller.js b/abitur_list_client/controllers/request.controller.js
index 0685adb..6af6f38 100644
--- a/abitur_list_client/controllers/request.controller.js
+++ b/abitur_list_client/controllers/request.controller.js
@@ -28,8 +28,8 @@ class RequestController extends RequestControllerInterface {
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])
+ const {request_id} = req.body
+ const requests = await db.query('DELETE FROM request WHERE id=' + request_id.toString())
res.json(requests.rows[0])
}
async getAbiturRequests(req, res) {
diff --git a/abitur_list_client/mongo/controllers/abitur.controller.js b/abitur_list_client/mongo/controllers/abitur.controller.js
new file mode 100644
index 0000000..e2b61fa
--- /dev/null
+++ b/abitur_list_client/mongo/controllers/abitur.controller.js
@@ -0,0 +1,123 @@
+const mymongodb = require('../../mongoIndex')
+
+const crypto = require('crypto');
+
+const AbiturControllerInterface = require('../../controllers/interfaces/abitur.controller.interface');
+
+const { ObjectId } = require('mongodb');
+
+class AbiturController extends AbiturControllerInterface{
+
+ async createAbitur(req, res) {
+ // const {first_name, last_name, middle_name, email, password} = req.body
+
+ // var hash = crypto.createHash('md5').update(password).digest('hex');
+
+ // const newAbitur = await db.query('INSERT INTO abitur (first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5) RETURNING *', [first_name, last_name, middle_name, email, hash])
+ // res.json(newAbitur.rows[0])
+
+ const {first_name, last_name, middle_name, email, password} = req.body
+
+ var hash = crypto.createHash('md5').update(password).digest('hex')
+
+ const collection = mymongodb.collection('abiturs')
+
+ const newAbitur = collection.insertOne({
+ first_name: first_name,
+ last_name: last_name,
+ middle_name: middle_name,
+ email: email,
+ password: hash
+ })
+ res.json({id: 1})
+ }
+ async createAbiturWithId(req, res) {
+ // const {id, first_name, last_name, middle_name, email, password} = req.body
+
+ // var hash = crypto.createHash('md5').update(password).digest('hex');
+
+ // const newAbitur = await db.query('INSERT INTO abitur (id, first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *', [id, first_name, last_name, middle_name, email, hash])
+ // res.json(newAbitur.rows[0])
+
+ const {id, first_name, last_name, middle_name, email, password} = req.body
+
+ var hash = crypto.createHash('md5').update(password).digest('hex')
+
+ const collection = mymongodb.collection('abiturs')
+
+ const newAbitur = await collection.insertOne({
+ _id: new ObjectId(id),
+ first_name: first_name,
+ last_name: last_name,
+ middle_name: middle_name,
+ email: email,
+ password: hash
+ })
+
+ if (newAbitur!=null) res.json({id: 1})
+ }
+ async getAbiturs(req, res) {
+ // const abiturs = await db.query('SELECT * FROM abitur')
+ // res.json(abiturs.rows)
+ const collection = mymongodb.collection('abiturs')
+ const abiturs = await collection.find().toArray()
+ res.json(abiturs)
+ }
+ 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])
+ const id = req.params.id
+ const collection = mymongodb.collection('abiturs')
+ const abiturs = await collection.findOne({_id: new ObjectId(id)})
+ res.json(abiturs)
+ }
+ async authAbitur(req, res) {
+ // const {email, password} = req.body
+ // var hash = crypto.createHash('md5').update(password).digest('hex');
+ // const abitur = await db.query('SELECT * FROM abitur WHERE email = $1 AND password = $2', [email, hash])
+ // res.json(abitur.rows[0])
+
+ const collection = mymongodb.collection('abiturs')
+ const {email, password} = req.body
+ var hash = crypto.createHash('md5').update(password).digest('hex')
+
+ const abitur = await collection.findOne({email: email, password: hash})
+
+ res.json(abitur)
+ }
+ 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])
+
+ const {id, first_name, last_name, middle_name} = req.body
+ const collection = mymongodb.collection('abiturs')
+ await collection.findOneAndUpdate({_id: id}, {$set: {
+ first_name: first_name,
+ last_name: last_name,
+ middle_name: middle_name,
+ }})
+ res.json({id: 1})
+ }
+ 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])
+
+ const id = req.params.id
+ const collection = mymongodb.collection('abiturs')
+ await collection.findOneAndDelete({_id: id})
+ res.json({id: 1})
+
+ }
+ async deleteAll(req, res) {
+ // const abiturs = await db.query('DELETE FROM abitur')
+ // res.json(abiturs.rows)
+
+ const collection = mymongodb.collection('abiturs')
+ await collection.drop()
+ }
+}
+
+module.exports = new AbiturController()
diff --git a/abitur_list_client/mongo/controllers/educationform.controller.js b/abitur_list_client/mongo/controllers/educationform.controller.js
new file mode 100644
index 0000000..c4bf457
--- /dev/null
+++ b/abitur_list_client/mongo/controllers/educationform.controller.js
@@ -0,0 +1,37 @@
+const mymongodb = require('../../mongoIndex')
+
+
+const EducationFormControllerInterface = require('../../controllers/interfaces/educationform.controller.interface');
+const { ObjectId } = require('mongodb');
+
+class EducationFormController extends EducationFormControllerInterface {
+ async createEducationForm(req, res) {
+ // const {title} = req.body
+ // const newEducationForm = await db.query('INSERT INTO education_form (title) VALUES ($1) RETURNING *', [title])
+ // res.json(newEducationForm.rows[0])
+ }
+ async getEducationForms(req, res) {
+ // const forms = await db.query('SELECT * FROM education_form')
+ // res.json(forms.rows)
+
+ const forms = await mymongodb.collection('educationforms').find().toArray()
+ res.json(forms)
+ }
+ async getOneEducationForm(req, res) {
+ // const id = req.params.id
+ // const forms = await db.query('SELECT * FROM education_form WHERE id=$1', [id])
+ // res.json(forms.rows[0])
+ }
+ async updateEducationForm(req, res) {
+ // const {id, title} = req.body
+ // const newEducationForm = await db.query('UPDATE education_form SET title=$1 WHERE id=$2 RETURNING *', [title, id])
+ // res.json(newEducationForm.rows[0])
+ }
+ async deleteEducationForm(req, res) {
+ // const id = req.params.id
+ // const forms = await db.query('DELETE FROM education_form WHERE id=$1', [id])
+ // res.json(forms.rows[0])
+ }
+}
+
+module.exports = new EducationFormController()
\ No newline at end of file
diff --git a/abitur_list_client/mongo/controllers/examresult.controller.js b/abitur_list_client/mongo/controllers/examresult.controller.js
new file mode 100644
index 0000000..2c724ae
--- /dev/null
+++ b/abitur_list_client/mongo/controllers/examresult.controller.js
@@ -0,0 +1,86 @@
+const mymongodb = require('../../mongoIndex')
+
+
+const ExamResultControllerInterface = require('../../controllers/interfaces/examresult.controller.interface');
+const { ObjectId } = require('mongodb');
+
+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])
+
+ const {title, result, abitur_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {
+ $push: { exam_results: {
+ _id: new ObjectId(),
+ title: title,
+ result: result
+ } }
+ }
+ )
+ }
+ 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])
+
+ const {id, title, result, abitur_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {
+ $push: { exam_results: {
+ _id: new ObjectId(id),
+ title: title,
+ result: result
+ } }
+ }
+ )
+ }
+ 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])
+
+ const {abitur_id, result_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {$pull: {
+ exam_results: {_id: new ObjectId(result_id)}
+ }}
+ )
+ }
+ 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)
+ const collection = mymongodb.collection('abiturs')
+ const id = req.params.id
+ const abitur = await collection.findOne({_id: new ObjectId(id)})
+ res.json(abitur['exam_results'])
+ }
+ 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])
+ }
+}
+
+module.exports = new ExamResultController()
\ No newline at end of file
diff --git a/abitur_list_client/mongo/controllers/request.controller.js b/abitur_list_client/mongo/controllers/request.controller.js
new file mode 100644
index 0000000..ccdb09c
--- /dev/null
+++ b/abitur_list_client/mongo/controllers/request.controller.js
@@ -0,0 +1,143 @@
+const mymongodb = require('../../mongoIndex')
+
+
+const RequestControllerInterface = require('../../controllers/interfaces/request.controller.interface');
+const { ObjectId } = require('mongodb');
+
+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])
+
+ const {abitur_id, education_form_id, specialization_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+
+ const education_form = await mymongodb.collection('educationforms').findOne({id: education_form_id})
+ const specialization = await mymongodb.collection('specializations').findOne({id: specialization_id})
+
+ const newreq = {
+ _id: new ObjectId(),
+ exam_results: [],
+ date: Date.now().toString(),
+ specialization: specialization['title'],
+ education_form: education_form['title']
+ }
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {
+ $push: { requests: newreq }
+ }
+ )
+
+ res.json(newreq)
+
+ }
+ 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])
+
+ const {id, abitur_id, education_form_id, specialization_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+
+ const education_form = await mymongodb.collection('educationforms').findOne({id: education_form_id})
+ const specialization = await mymongodb.collection('specializations').findOne({id: specialization_id})
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {
+ $push: { requests: {
+ _id: new ObjectId(id),
+ exam_results: [],
+ date: Date.now().toString(),
+ specialization: specialization['title'],
+ education_form: education_form['title']
+ } }
+ }
+ )
+ }
+ 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])
+
+ const id = req.params.id
+ const collection = mymongodb.collection('abiturs')
+ const abitur = await collection.findOne({"requests._id": new ObjectId(id)}, {_id: 0, requests: {$elemMatch: {_id: new ObjectId(id)}}})
+ for(const req of abitur['requests']) {
+ if (req['_id'] == id){
+ console.log(req)
+ res.json(req)
+ break
+ }
+ }
+ }
+ 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])
+
+ const {id, education_form, specialization, exam_results, date, abitur_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+
+ if (exam_results != null) {
+ var dictionary = {}
+ for(const newres of exam_results) {
+ dictionary[newres['title']] += 1
+ if (dictionary[newres['title']] > 1){
+ console.log('same result')
+ return
+ }
+ }
+ }
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {$pull: {
+ requests: {_id: new ObjectId(id)}
+ }}
+ )
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {
+ $push: { requests: {
+ _id: new ObjectId(id),
+ exam_results: exam_results,
+ date: date,
+ specialization: specialization,
+ education_form: education_form
+ } }
+ }
+ )
+ }
+ 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])
+
+ const {abitur_id, request_id} = req.body
+ const collection = mymongodb.collection('abiturs')
+
+ await collection.updateOne({_id: new ObjectId(abitur_id)},
+ {$pull: {
+ requests: {_id: new ObjectId(request_id)}
+ }}
+ )
+ }
+ 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)
+ }
+ 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])
+ }
+}
+
+module.exports = new RequestController()
\ No newline at end of file
diff --git a/abitur_list_client/mongo/controllers/specialization.controller.js b/abitur_list_client/mongo/controllers/specialization.controller.js
new file mode 100644
index 0000000..ce7ca21
--- /dev/null
+++ b/abitur_list_client/mongo/controllers/specialization.controller.js
@@ -0,0 +1,37 @@
+const mymongodb = require('../../mongoIndex')
+
+
+const SpecializationControllerInterface = require('../../controllers/interfaces/specialization.controller.interface');
+const { ObjectId } = require('mongodb');
+
+class SpecializationController extends SpecializationControllerInterface {
+ async createSpecialization(req, res) {
+ // const {title} = req.body
+ // const newSpecialization = await db.query('INSERT INTO specialization (title) VALUES ($1) RETURNING *', [title])
+ // res.json(newSpecialization.rows[0])
+ }
+ async getSpecializations(req, res) {
+ // const specializations = await db.query('SELECT * FROM specialization')
+ // res.json(specializations.rows)
+
+ const specializations = await mymongodb.collection('specializations').find().toArray()
+ res.json(specializations)
+ }
+ async getOneSpecialization(req, res) {
+ // const id = req.params.id
+ // const specializations = await db.query('SELECT * FROM specialization WHERE id=$1', [id])
+ // res.json(specializations.rows[0])
+ }
+ async updateSpecialization(req, res) {
+ // const {id, title} = req.body
+ // const newSpecialization = await db.query('UPDATE specialization SET title=$1 WHERE id=$2 RETURNING *', [title, id])
+ // res.json(newSpecialization.rows[0])
+ }
+ async deleteSpecialization(req, res) {
+ // const id = req.params.id
+ // const specializations = await db.query('DELETE FROM specialization WHERE id=$1', [id])
+ // res.json(specializations.rows[0])
+ }
+}
+
+module.exports = new SpecializationController()
\ No newline at end of file
diff --git a/abitur_list_client/mongoIndex.js b/abitur_list_client/mongoIndex.js
new file mode 100644
index 0000000..d5a4c60
--- /dev/null
+++ b/abitur_list_client/mongoIndex.js
@@ -0,0 +1,20 @@
+const {MongoClient} = require('mongodb')
+
+const client = new MongoClient('mongodb://127.0.0.1:27017')
+const mymongodb = client.db('labfin')
+
+const start = async () => {
+ console.log('in start')
+ try{
+ await client.connect()
+ const mymongodb = client.db('labfin')
+ console.log('connected!!!!!!!!!11')
+ }
+ catch(e) {
+ console.log(e)
+ }
+}
+
+start()
+
+module.exports = mymongodb
\ No newline at end of file
diff --git a/abitur_list_client/package.json b/abitur_list_client/package.json
index 357f2c7..8682d88 100644
--- a/abitur_list_client/package.json
+++ b/abitur_list_client/package.json
@@ -5,7 +5,8 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
- "start": "pm2 start index.js"
+ "start": "pm2 start index.js",
+ "startMongo": "node mongoIndex.js"
},
"dependencies": {
"axios": "^1.3.4",
diff --git a/abitur_list_client/routes/abitur.routes.js b/abitur_list_client/routes/abitur.routes.js
index 8ca3955..b205796 100644
--- a/abitur_list_client/routes/abitur.routes.js
+++ b/abitur_list_client/routes/abitur.routes.js
@@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const abiturController = require('../controllers/abitur.controller')
+//const abiturController = require('../mongo/controllers/abitur.controller')
router.post('/abitur', abiturController.createAbitur)
router.post('/abitur/manual', abiturController.createAbiturWithId)
diff --git a/abitur_list_client/routes/educationform.routes.js b/abitur_list_client/routes/educationform.routes.js
index 611f77c..e40b9d8 100644
--- a/abitur_list_client/routes/educationform.routes.js
+++ b/abitur_list_client/routes/educationform.routes.js
@@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const educationformController = require('../controllers/educationform.controller')
+//const educationformController = require('../mongo/controllers/educationform.controller')
router.post('/educationform', educationformController.createEducationForm)
router.get('/educationform', educationformController.getEducationForms)
diff --git a/abitur_list_client/routes/enrollment.routes.js b/abitur_list_client/routes/enrollment.routes.js
deleted file mode 100644
index cd39154..0000000
--- a/abitur_list_client/routes/enrollment.routes.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const Router = require('express')
-const router = new Router()
-
-const enrollmentController = require('../controllers/enrollment.controller')
-
-router.post('/enrollment', enrollmentController.createEnrollment)
-router.get('/enrollment', enrollmentController.getEnrollments)
-router.get('/enrollment/:id', enrollmentController.getOneEnrollment)
-router.put('/enrollment', enrollmentController.updateEnrollment)
-router.delete('/enrollment/:id', enrollmentController.deleteEnrollment)
-
-module.exports = router
\ No newline at end of file
diff --git a/abitur_list_client/routes/examresult.routes.js b/abitur_list_client/routes/examresult.routes.js
index 9d0bb3a..6a983ff 100644
--- a/abitur_list_client/routes/examresult.routes.js
+++ b/abitur_list_client/routes/examresult.routes.js
@@ -2,13 +2,14 @@ const Router = require('express')
const router = new Router()
const examResultController = require('../controllers/examresult.controller')
+//const examResultController = require('../mongo/controllers/examresult.controller')
router.post('/examresult', examResultController.createExamResult)
router.post('/examresult/manual', examResultController.createExamResultWithId)
router.get('/examresult', examResultController.getExamResults)
router.get('/examresult/:id', examResultController.getOneExamResult)
router.put('/examresult', examResultController.updateExamResult)
-router.delete('/examresult/:id', examResultController.deleteExamResult)
+router.delete('/examresult', examResultController.deleteExamResult)
router.get('/examresult/abitur/:id', examResultController.getAbiturExamResults)
router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization)
diff --git a/abitur_list_client/routes/request.routes.js b/abitur_list_client/routes/request.routes.js
index 9178ea6..29d32c8 100644
--- a/abitur_list_client/routes/request.routes.js
+++ b/abitur_list_client/routes/request.routes.js
@@ -1,14 +1,15 @@
const Router = require('express')
const router = new Router()
-const requestController = require('../controllers/request.controller')
+const requestController = require('..//controllers/request.controller')
+//const requestController = require('../mongo/controllers/request.controller')
router.post('/request', requestController.createRequest)
router.post('/request/manual', requestController.createRequestWithId)
router.get('/request', requestController.getRequests)
router.get('/request/:id', requestController.getOneRequest)
router.put('/request', requestController.updateRequest)
-router.delete('/request/:id', requestController.deleteRequest)
+router.delete('/request/', requestController.deleteRequest)
router.get('/request/abitur/:id', requestController.getAbiturRequests)
router.get('/request/spec/:id', requestController.getCountBySpec)
diff --git a/abitur_list_client/routes/specialization.routes.js b/abitur_list_client/routes/specialization.routes.js
index bda016a..75ef85e 100644
--- a/abitur_list_client/routes/specialization.routes.js
+++ b/abitur_list_client/routes/specialization.routes.js
@@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const specializationController = require('../controllers/specialization.controller')
+//const specializationController = require('../mongo/controllers/specialization.controller')
router.post('/specialization', specializationController.createSpecialization)
router.get('/specialization', specializationController.getSpecializations)
diff --git a/abitur_list_client/src/components/AbiturMain.vue b/abitur_list_client/src/components/AbiturMain.vue
index b2068a8..945788e 100644
--- a/abitur_list_client/src/components/AbiturMain.vue
+++ b/abitur_list_client/src/components/AbiturMain.vue
@@ -4,17 +4,6 @@
Здравствуйте, {{this.firstName}} {{this.lastName}}
-
-
-
Мои результаты:
@@ -26,7 +15,7 @@
Результат: {{ result['result']}}
-
@@ -66,10 +55,10 @@
Дата: {{ request['date'].slice(0,10)}}
-
+
Посмотреть
- Удалить
+ Удалить
@@ -101,12 +90,22 @@ export default {
async beforeMount(){
this.abiturId = this.$route.params.abiturId
var response = (await axios.get('http://127.0.0.1:8080/api/abitur/' + this.abiturId)).data
+
+ if (localStorage.getItem('db') == 'mongo') {
+ this.firstName = response['first_name']
+ this.lastName = response['last_name']
+ this.examResults = response['exam_results'] ?? []
+ this.requests = response['requests'] ?? []
+
+ localStorage.setItem('abiturId', response['_id'])
+
+ return
+ }
+
this.firstName = response['first_name']
this.lastName = response['last_name']
-
response = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.abiturId)).data
this.examResults = response
-
response = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + this.abiturId)).data
this.requests = response
@@ -151,9 +150,44 @@ export default {
},
async deleteResultClick(id) {
- await axios.delete('http://127.0.0.1:8080/api/examresult/' + id)
- await this.refresh()
- window.location.reload()
+ if (localStorage.getItem('db') =='mongo'){
+ let data = JSON.stringify({
+ "abitur_id": this.abiturId,
+ "result_id": id
+ });
+ console.log(data)
+ let config = {
+ method: 'delete',
+ maxBodyLength: Infinity,
+ url: 'http://127.0.0.1:8080/api/examresult',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data : data
+ };
+ axios.request(config)
+ setTimeout(()=>{
+ window.location.reload(true);
+ });
+ }
+
+ let data = JSON.stringify({
+ "result_id": id
+ });
+ console.log(data)
+ let config = {
+ method: 'delete',
+ maxBodyLength: Infinity,
+ url: 'http://127.0.0.1:8080/api/examresult',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data : data
+ };
+
+ await axios.request(config)
+ await this.refresh()
+ window.location.reload()
},
onRequestButtonClick(requestId) {
@@ -179,21 +213,21 @@ export default {
});
let config = {
- method: 'post',
- maxBodyLength: Infinity,
- url: 'http://127.0.0.1:8080/api/request',
- headers: {
- 'Content-Type': 'application/json'
- },
- data : data
+ method: 'post',
+ maxBodyLength: Infinity,
+ url: 'http://127.0.0.1:8080/api/request',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data : data
};
await axios.request(config)
- .then((response) => {
- requestId = response.data['id']
- })
- .catch((error) => {
- console.log(error);
+ .then((response) => {
+ requestId = response.data['id'] ?? response.data['_id']
+ })
+ .catch((error) => {
+ console.log(error);
});
this.$router.push(
@@ -207,8 +241,47 @@ export default {
},
async deleteRequest(requestId) {
- await axios.delete('http://127.0.0.1:8080/api/request/' + requestId)
- window.location.reload()
+ if (localStorage.getItem('db') =='mongo'){
+
+ let data = JSON.stringify({
+ "abitur_id": this.abiturId,
+ "request_id": requestId
+ });
+
+ let config = {
+ method: 'delete',
+ maxBodyLength: Infinity,
+ url: 'http://127.0.0.1:8080/api/request',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data : data
+ };
+
+ axios.request(config)
+ setTimeout(()=>{
+ window.location.reload(true);
+ });
+ return
+ }
+
+ let data = JSON.stringify({
+ "request_id": requestId
+ });
+ console.log(data)
+ let config = {
+ method: 'delete',
+ maxBodyLength: Infinity,
+ url: 'http://127.0.0.1:8080/api/request',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ data : data
+ };
+
+ await axios.request(config)
+ await this.refresh()
+ window.location.reload()
},
async refresh() {
diff --git a/abitur_list_client/src/components/Enter.vue b/abitur_list_client/src/components/Enter.vue
index 267115c..26e0f7d 100644
--- a/abitur_list_client/src/components/Enter.vue
+++ b/abitur_list_client/src/components/Enter.vue
@@ -47,10 +47,16 @@ export default {
await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
+ console.log(response.data)
this.abiturId = response.data['id']
+ localStorage.setItem('db', 'pgsql')
+ if (this.abiturId == null) {
+ this.abiturId = response.data['_id']
+ localStorage.setItem('db', 'mongo')
+ }
})
.catch((error) => {
- this.message = 'Ошибка при входе в аккаунт'
+ this.message = 'Непредвиденная шибка при входе в аккаунт'
console.log(error);
});
if (this.abiturId <= 0 || this.abiturId == null) {
diff --git a/abitur_list_client/src/components/Request.vue b/abitur_list_client/src/components/Request.vue
index 5013cf3..b89cf60 100644
--- a/abitur_list_client/src/components/Request.vue
+++ b/abitur_list_client/src/components/Request.vue
@@ -1,11 +1,11 @@
Ваша заявка:
-
Дата: {{ this.request['date'].slice(0,10) ?? ''}}
+
Дата: {{ this.request == null ? '' : this.request['date']}}
Специализация:
- {{ specialization['title'] ?? '' }}
+ {{ specialization == null ? '' : specialization['title'] ?? specialization }}