Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
234b49d7b7 | |||
e04eefb8a2 | |||
5cdd7ec752 |
5
abitur_list_client/.env
Normal file
5
abitur_list_client/.env
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#dbPath='../controllers/'
|
||||||
|
dbPath='../mongo/controllers/'
|
||||||
|
#delete '/mongo' to switch to pgsql
|
||||||
|
|
||||||
|
добавить объектные айди к результатам экзамена и вроде готово!
|
@ -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()
|
|
@ -28,8 +28,8 @@ class ExamResultController extends ExamResultControllerInterface {
|
|||||||
res.json(newExamResult.rows[0])
|
res.json(newExamResult.rows[0])
|
||||||
}
|
}
|
||||||
async deleteExamResult(req, res) {
|
async deleteExamResult(req, res) {
|
||||||
const id = req.params.id
|
const {result_id} = req.body
|
||||||
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [id])
|
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [result_id])
|
||||||
res.json(results.rows[0])
|
res.json(results.rows[0])
|
||||||
}
|
}
|
||||||
async getAbiturExamResults(req, res) {
|
async getAbiturExamResults(req, res) {
|
||||||
|
@ -28,8 +28,8 @@ class RequestController extends RequestControllerInterface {
|
|||||||
res.json(newRequest.rows[0])
|
res.json(newRequest.rows[0])
|
||||||
}
|
}
|
||||||
async deleteRequest(req, res) {
|
async deleteRequest(req, res) {
|
||||||
const id = req.params.id
|
const {request_id} = req.body
|
||||||
const requests = await db.query('DELETE FROM request WHERE id=$1', [id])
|
const requests = await db.query('DELETE FROM request WHERE id=' + request_id.toString())
|
||||||
res.json(requests.rows[0])
|
res.json(requests.rows[0])
|
||||||
}
|
}
|
||||||
async getAbiturRequests(req, res) {
|
async getAbiturRequests(req, res) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
require('dotenv').config()
|
||||||
|
|
||||||
const abiturRouter = require('./routes/abitur.routes')
|
const abiturRouter = require('./routes/abitur.routes')
|
||||||
const examResultRouter = require('./routes/examresult.routes')
|
const examResultRouter = require('./routes/examresult.routes')
|
||||||
|
127
abitur_list_client/mongo/controllers/abitur.controller.js
Normal file
127
abitur_list_client/mongo/controllers/abitur.controller.js
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
const mymongodb = require('../../mongoIndex')
|
||||||
|
|
||||||
|
const crypto = require('crypto');
|
||||||
|
|
||||||
|
const AbiturControllerInterface = require('../../controllers/interfaces/abitur.controller.interface');
|
||||||
|
|
||||||
|
const { ObjectId } = require('mongodb');
|
||||||
|
const e = require('express');
|
||||||
|
|
||||||
|
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, exam_results, requests} = 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,
|
||||||
|
exam_results: exam_results,
|
||||||
|
requests: requests
|
||||||
|
})
|
||||||
|
|
||||||
|
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.deleteMany({})
|
||||||
|
res.json({id: 1})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new AbiturController()
|
@ -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()
|
103
abitur_list_client/mongo/controllers/examresult.controller.js
Normal file
103
abitur_list_client/mongo/controllers/examresult.controller.js
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
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])
|
||||||
|
|
||||||
|
const title = req.params.id
|
||||||
|
const collection = mymongodb.collection('abiturs')
|
||||||
|
const answer = await collection.aggregate([
|
||||||
|
{ $match: { "requests.specialization": title } },
|
||||||
|
{ $unwind: "$requests" },
|
||||||
|
{ $unwind: "$requests.exam_results" },
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: {
|
||||||
|
specialization: "$requests.specialization"
|
||||||
|
},
|
||||||
|
avg_result: { $avg: "$requests.exam_results.result" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).toArray()
|
||||||
|
res.json(answer[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new ExamResultController()
|
159
abitur_list_client/mongo/controllers/request.controller.js
Normal file
159
abitur_list_client/mongo/controllers/request.controller.js
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
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: new Date(),
|
||||||
|
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: new Date(),
|
||||||
|
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
|
||||||
|
} }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
res.json({id: 1})
|
||||||
|
}
|
||||||
|
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])
|
||||||
|
|
||||||
|
const title = req.params.id
|
||||||
|
const collection = mymongodb.collection('abiturs')
|
||||||
|
const answer = await collection.aggregate([
|
||||||
|
{ $unwind: "$requests" },
|
||||||
|
{ $match: { "requests.specialization": title } },
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: { firstname: "$first_name", lastname: "$last_name"},
|
||||||
|
count: { $sum: 1 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]).toArray()
|
||||||
|
res.json(answer.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new RequestController()
|
@ -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()
|
1
abitur_list_client/mongoDataSave.json
Normal file
1
abitur_list_client/mongoDataSave.json
Normal file
File diff suppressed because one or more lines are too long
20
abitur_list_client/mongoIndex.js
Normal file
20
abitur_list_client/mongoIndex.js
Normal file
@ -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
|
45
abitur_list_client/package-lock.json
generated
45
abitur_list_client/package-lock.json
generated
@ -10,7 +10,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"core-js": "^3.8.3",
|
"core-js": "^3.8.3",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
"mongodb": "^5.5.0",
|
"mongodb": "^5.5.0",
|
||||||
"mongoose": "^7.1.1",
|
"mongoose": "^7.1.1",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
@ -2588,6 +2590,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@vue/cli-service/node_modules/dotenv": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@vue/cli-shared-utils": {
|
"node_modules/@vue/cli-shared-utils": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
|
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
|
||||||
@ -4727,12 +4738,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dotenv": {
|
"node_modules/dotenv": {
|
||||||
"version": "10.0.0",
|
"version": "16.0.3",
|
||||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/dotenv-expand": {
|
"node_modules/dotenv-expand": {
|
||||||
@ -5224,6 +5234,11 @@
|
|||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fs": {
|
||||||
|
"version": "0.0.1-security",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||||
|
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
||||||
|
},
|
||||||
"node_modules/fs-extra": {
|
"node_modules/fs-extra": {
|
||||||
"version": "9.1.0",
|
"version": "9.1.0",
|
||||||
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
||||||
@ -12186,6 +12201,14 @@
|
|||||||
"webpack-merge": "^5.7.3",
|
"webpack-merge": "^5.7.3",
|
||||||
"webpack-virtual-modules": "^0.4.2",
|
"webpack-virtual-modules": "^0.4.2",
|
||||||
"whatwg-fetch": "^3.6.2"
|
"whatwg-fetch": "^3.6.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"dotenv": {
|
||||||
|
"version": "10.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz",
|
||||||
|
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@vue/cli-shared-utils": {
|
"@vue/cli-shared-utils": {
|
||||||
@ -13944,10 +13967,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dotenv": {
|
"dotenv": {
|
||||||
"version": "10.0.0",
|
"version": "16.0.3",
|
||||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"dotenv-expand": {
|
"dotenv-expand": {
|
||||||
"version": "5.1.0",
|
"version": "5.1.0",
|
||||||
@ -14354,6 +14376,11 @@
|
|||||||
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||||
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="
|
"integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="
|
||||||
},
|
},
|
||||||
|
"fs": {
|
||||||
|
"version": "0.0.1-security",
|
||||||
|
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||||
|
"integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w=="
|
||||||
|
},
|
||||||
"fs-extra": {
|
"fs-extra": {
|
||||||
"version": "9.1.0",
|
"version": "9.1.0",
|
||||||
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
||||||
|
@ -5,12 +5,15 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
"build": "vue-cli-service build",
|
"build": "vue-cli-service build",
|
||||||
"start": "pm2 start index.js"
|
"start": "pm2 start index.js",
|
||||||
|
"startMongo": "node mongoIndex.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"core-js": "^3.8.3",
|
"core-js": "^3.8.3",
|
||||||
|
"dotenv": "^16.0.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
"mongodb": "^5.5.0",
|
"mongodb": "^5.5.0",
|
||||||
"mongoose": "^7.1.1",
|
"mongoose": "^7.1.1",
|
||||||
"pg": "^8.10.0",
|
"pg": "^8.10.0",
|
||||||
@ -30,5 +33,10 @@
|
|||||||
"last 2 versions",
|
"last 2 versions",
|
||||||
"not dead",
|
"not dead",
|
||||||
"not ie 11"
|
"not ie 11"
|
||||||
]
|
],
|
||||||
|
"browser": {
|
||||||
|
"fs": false,
|
||||||
|
"path": false,
|
||||||
|
"os": false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const Router = require('express')
|
const Router = require('express')
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
const abiturController = require('../controllers/abitur.controller')
|
//const abiturController = require('../controllers/abitur.controller')
|
||||||
|
const abiturController = require(process.env.dbPath + 'abitur.controller')
|
||||||
|
|
||||||
router.post('/abitur', abiturController.createAbitur)
|
router.post('/abitur', abiturController.createAbitur)
|
||||||
router.post('/abitur/manual', abiturController.createAbiturWithId)
|
router.post('/abitur/manual', abiturController.createAbiturWithId)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const Router = require('express')
|
const Router = require('express')
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
const educationformController = require('../controllers/educationform.controller')
|
//const educationformController = require('../controllers/educationform.controller')
|
||||||
|
const educationformController = require(process.env.dbPath + 'educationform.controller')
|
||||||
|
|
||||||
router.post('/educationform', educationformController.createEducationForm)
|
router.post('/educationform', educationformController.createEducationForm)
|
||||||
router.get('/educationform', educationformController.getEducationForms)
|
router.get('/educationform', educationformController.getEducationForms)
|
||||||
|
@ -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
|
|
@ -1,14 +1,15 @@
|
|||||||
const Router = require('express')
|
const Router = require('express')
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
const examResultController = require('../controllers/examresult.controller')
|
//const examResultController = require('../controllers/examresult.controller')
|
||||||
|
const examResultController = require(process.env.dbPath + 'examresult.controller')
|
||||||
|
|
||||||
router.post('/examresult', examResultController.createExamResult)
|
router.post('/examresult', examResultController.createExamResult)
|
||||||
router.post('/examresult/manual', examResultController.createExamResultWithId)
|
router.post('/examresult/manual', examResultController.createExamResultWithId)
|
||||||
router.get('/examresult', examResultController.getExamResults)
|
router.get('/examresult', examResultController.getExamResults)
|
||||||
router.get('/examresult/:id', examResultController.getOneExamResult)
|
router.get('/examresult/:id', examResultController.getOneExamResult)
|
||||||
router.put('/examresult', examResultController.updateExamResult)
|
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/abitur/:id', examResultController.getAbiturExamResults)
|
||||||
router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization)
|
router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization)
|
||||||
|
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
const Router = require('express')
|
const Router = require('express')
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
const requestController = require('../controllers/request.controller')
|
//const requestController = require('..//controllers/request.controller')
|
||||||
|
const requestController = require(process.env.dbPath + 'request.controller')
|
||||||
|
|
||||||
router.post('/request', requestController.createRequest)
|
router.post('/request', requestController.createRequest)
|
||||||
router.post('/request/manual', requestController.createRequestWithId)
|
router.post('/request/manual', requestController.createRequestWithId)
|
||||||
router.get('/request', requestController.getRequests)
|
router.get('/request', requestController.getRequests)
|
||||||
router.get('/request/:id', requestController.getOneRequest)
|
router.get('/request/:id', requestController.getOneRequest)
|
||||||
router.put('/request', requestController.updateRequest)
|
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/abitur/:id', requestController.getAbiturRequests)
|
||||||
router.get('/request/spec/:id', requestController.getCountBySpec)
|
router.get('/request/spec/:id', requestController.getCountBySpec)
|
||||||
|
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
const Router = require('express')
|
const Router = require('express')
|
||||||
const router = new Router()
|
const router = new Router()
|
||||||
|
|
||||||
const specializationController = require('../controllers/specialization.controller')
|
//const specializationController = require('../controllers/specialization.controller')
|
||||||
|
const specializationController = require(process.env.dbPath + 'specialization.controller')
|
||||||
|
|
||||||
router.post('/specialization', specializationController.createSpecialization)
|
router.post('/specialization', specializationController.createSpecialization)
|
||||||
router.get('/specialization', specializationController.getSpecializations)
|
router.get('/specialization', specializationController.getSpecializations)
|
||||||
|
53
abitur_list_client/saveJSONDataToMongo.js
Normal file
53
abitur_list_client/saveJSONDataToMongo.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
const axios = require('axios');
|
||||||
|
const fs = require('fs');
|
||||||
|
const {MongoClient, ObjectId} = require('mongodb')
|
||||||
|
const client = new MongoClient('mongodb://127.0.0.1:27017')
|
||||||
|
const mymongodb = client.db('labfin')
|
||||||
|
|
||||||
|
const loadFromJson = async () => {
|
||||||
|
let rawdata = fs.readFileSync('mongoDataSave.json');
|
||||||
|
let data = JSON.parse(rawdata);
|
||||||
|
//console.log(data);
|
||||||
|
|
||||||
|
await client.connect()
|
||||||
|
const mymongodb = client.db('labfin')
|
||||||
|
console.log('connected!!!!!!!!!11')
|
||||||
|
|
||||||
|
for(const record of data) {
|
||||||
|
|
||||||
|
const finalRequests = []
|
||||||
|
for(const req of record['requests']) {
|
||||||
|
finalRequests.push({
|
||||||
|
_id: new ObjectId(),
|
||||||
|
date: req['date'],
|
||||||
|
specialization: req['specialization'],
|
||||||
|
education_form: req['education_form'],
|
||||||
|
exam_results: req['exam_results']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const finalResults = []
|
||||||
|
for(const res of record['exam_results']) {
|
||||||
|
finalResults.push({
|
||||||
|
_id: new ObjectId(),
|
||||||
|
title: res['title'],
|
||||||
|
results: res['result']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
await mymongodb.collection('abiturs').insertOne({
|
||||||
|
_id: new ObjectId(),
|
||||||
|
first_name: record['first_name'],
|
||||||
|
last_name: record['last_name'],
|
||||||
|
middle_name: record['middle_name'],
|
||||||
|
email: record['email'],
|
||||||
|
password: record['password'],
|
||||||
|
exam_results: finalResults,
|
||||||
|
requests: finalRequests
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('loaded from json!')
|
||||||
|
}
|
||||||
|
|
||||||
|
loadFromJson()
|
65
abitur_list_client/savePostgresToJSON.js
Normal file
65
abitur_list_client/savePostgresToJSON.js
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
const axios = require('axios');
|
||||||
|
const fs = require('fs');
|
||||||
|
const {MongoClient, ObjectId} = require('mongodb')
|
||||||
|
|
||||||
|
const saveToJson = async () => {
|
||||||
|
var mongoData = []
|
||||||
|
var abiturs = (await axios.get('http://127.0.0.1:8080/api/abitur')).data
|
||||||
|
mongoData = mongoData.concat(abiturs)
|
||||||
|
|
||||||
|
for(let abitur of mongoData) {
|
||||||
|
// saving exam results for every abitur
|
||||||
|
var exam_results = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + abitur['id'])).data
|
||||||
|
for (let exam_res of exam_results) {
|
||||||
|
abitur['exam_results'] = abitur['exam_results'] ?? []
|
||||||
|
abitur['exam_results'].push({
|
||||||
|
'title': exam_res['title'],
|
||||||
|
'result': exam_res['result']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//saving requests for every abitur
|
||||||
|
var requests = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + abitur['id'])).data
|
||||||
|
//console.log(requests)
|
||||||
|
for (let req of requests) {
|
||||||
|
abitur['requests'] = abitur['requests'] ?? []
|
||||||
|
|
||||||
|
let education_form = (await axios.get('http://127.0.0.1:8080/api/educationform/' + req['education_form_id'])).data
|
||||||
|
let specialization = (await axios.get('http://127.0.0.1:8080/api/specialization/' + req['specialization_id'])).data
|
||||||
|
|
||||||
|
//получаем закрепленные за заявкой результаты
|
||||||
|
let results = []
|
||||||
|
|
||||||
|
var request_result_pairs = (await axios.get('http://127.0.0.1:8080/api/request_examresult/' + req['id'])).data
|
||||||
|
for(const pair of request_result_pairs) {
|
||||||
|
results.push((await axios.get('http://127.0.0.1:8080/api/examresult/' + pair['exam_result_id'])).data)
|
||||||
|
}
|
||||||
|
|
||||||
|
let formattedResults = []
|
||||||
|
|
||||||
|
|
||||||
|
for(let res of results) {
|
||||||
|
formattedResults.push({
|
||||||
|
'title': res['title'],
|
||||||
|
'result': res['result']
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
abitur['requests'].push({
|
||||||
|
'date': req['date'],
|
||||||
|
'education_form': education_form['title'],
|
||||||
|
'specialization': specialization['title'],
|
||||||
|
'exam_results': formattedResults
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(mongoData)
|
||||||
|
let data = JSON.stringify(mongoData)
|
||||||
|
fs.writeFileSync('mongoDataSave.json', data)
|
||||||
|
console.log('saved!')
|
||||||
|
}
|
||||||
|
|
||||||
|
saveToJson()
|
||||||
|
|
||||||
|
module.exports = saveToJson
|
@ -4,17 +4,6 @@
|
|||||||
Здравствуйте, {{this.firstName}} {{this.lastName}}
|
Здравствуйте, {{this.firstName}} {{this.lastName}}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<!--
|
|
||||||
Добавить логин и пароль для абитуриента при регистрации и авторизации (хранить в бд) done!
|
|
||||||
Добавить уведомления при регистрации и авторизации done!
|
|
||||||
Добавить секретную страничку для админа с отчетом
|
|
||||||
Добавить отчет
|
|
||||||
Добавить генерацию данных для отчета и замер запроса для отчета
|
|
||||||
При выборе предметов во время создания заявки сделать более удобный выбор предметов и их добавление done!
|
|
||||||
Шифровка пароля done!
|
|
||||||
-->
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p class='h5'>Мои результаты:</p>
|
<p class='h5'>Мои результаты:</p>
|
||||||
<ul class='text-start'>
|
<ul class='text-start'>
|
||||||
@ -26,7 +15,7 @@
|
|||||||
Результат: {{ result['result']}}
|
Результат: {{ result['result']}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button @click="deleteResultClick(result['id'])" type="button" class="btn btn-danger ms-3" >
|
<button @click="deleteResultClick(result['id'] ?? result['_id'])" type="button" class="btn btn-danger ms-3" >
|
||||||
Удалить
|
Удалить
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
@ -66,10 +55,10 @@
|
|||||||
Дата: {{ request['date'].slice(0,10)}}
|
Дата: {{ request['date'].slice(0,10)}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button @click="onRequestButtonClick(request['id'])" type="button" class="btn btn-warning ms-3" >
|
<button @click="onRequestButtonClick(request['id'] ?? request['_id'])" type="button" class="btn btn-warning ms-3" >
|
||||||
Посмотреть
|
Посмотреть
|
||||||
</button>
|
</button>
|
||||||
<button @click="deleteRequest(request['id'])" type="button" class="btn btn-danger ms-3"> Удалить</button>
|
<button @click="deleteRequest(request['id'] ?? request['_id'])" type="button" class="btn btn-danger ms-3"> Удалить</button>
|
||||||
</p>
|
</p>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -101,12 +90,22 @@ export default {
|
|||||||
async beforeMount(){
|
async beforeMount(){
|
||||||
this.abiturId = this.$route.params.abiturId
|
this.abiturId = this.$route.params.abiturId
|
||||||
var response = (await axios.get('http://127.0.0.1:8080/api/abitur/' + this.abiturId)).data
|
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.firstName = response['first_name']
|
||||||
this.lastName = response['last_name']
|
this.lastName = response['last_name']
|
||||||
|
|
||||||
response = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.abiturId)).data
|
response = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.abiturId)).data
|
||||||
this.examResults = response
|
this.examResults = response
|
||||||
|
|
||||||
response = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + this.abiturId)).data
|
response = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + this.abiturId)).data
|
||||||
this.requests = response
|
this.requests = response
|
||||||
|
|
||||||
@ -151,9 +150,44 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async deleteResultClick(id) {
|
async deleteResultClick(id) {
|
||||||
await axios.delete('http://127.0.0.1:8080/api/examresult/' + id)
|
if (localStorage.getItem('db') =='mongo'){
|
||||||
await this.refresh()
|
let data = JSON.stringify({
|
||||||
window.location.reload()
|
"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) {
|
onRequestButtonClick(requestId) {
|
||||||
@ -179,21 +213,21 @@ export default {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
url: 'http://127.0.0.1:8080/api/request',
|
url: 'http://127.0.0.1:8080/api/request',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
data : data
|
data : data
|
||||||
};
|
};
|
||||||
|
|
||||||
await axios.request(config)
|
await axios.request(config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
requestId = response.data['id']
|
requestId = response.data['id'] ?? response.data['_id']
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$router.push(
|
this.$router.push(
|
||||||
@ -207,8 +241,47 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async deleteRequest(requestId) {
|
async deleteRequest(requestId) {
|
||||||
await axios.delete('http://127.0.0.1:8080/api/request/' + requestId)
|
if (localStorage.getItem('db') =='mongo'){
|
||||||
window.location.reload()
|
|
||||||
|
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() {
|
async refresh() {
|
||||||
|
@ -47,10 +47,16 @@ export default {
|
|||||||
await axios.request(config)
|
await axios.request(config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(JSON.stringify(response.data));
|
console.log(JSON.stringify(response.data));
|
||||||
|
console.log(response.data)
|
||||||
this.abiturId = response.data['id']
|
this.abiturId = response.data['id']
|
||||||
|
localStorage.setItem('db', 'pgsql')
|
||||||
|
if (this.abiturId == null) {
|
||||||
|
this.abiturId = response.data['_id']
|
||||||
|
localStorage.setItem('db', 'mongo')
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.message = 'Ошибка при входе в аккаунт'
|
this.message = 'Непредвиденная шибка при входе в аккаунт'
|
||||||
console.log(error);
|
console.log(error);
|
||||||
});
|
});
|
||||||
if (this.abiturId <= 0 || this.abiturId == null) {
|
if (this.abiturId <= 0 || this.abiturId == null) {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="text-center m-3">
|
<div class="text-center m-3">
|
||||||
<p class="h3"> Ваша заявка: </p>
|
<p class="h3"> Ваша заявка: </p>
|
||||||
<p class=""> Дата: {{ this.request['date'].slice(0,10) ?? ''}} </p>
|
<p class=""> Дата: {{ this.request == null ? '' : this.request['date']}} </p>
|
||||||
<div class="h4">
|
<div class="h4">
|
||||||
Специализация:
|
Специализация:
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
{{ specialization['title'] ?? '' }}
|
{{ specialization == null ? '' : specialization['title'] ?? specialization }}
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="examResult">
|
<ul class="dropdown-menu" aria-labelledby="examResult">
|
||||||
<li v-for="spec in specializations">
|
<li v-for="spec in specializations">
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<div class="h4">
|
<div class="h4">
|
||||||
Форма обучения:
|
Форма обучения:
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
{{ educationForm['title'] ?? ''}}
|
{{ educationForm == null ? '' : educationForm['title'] ?? educationForm}}
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="examResult">
|
<ul class="dropdown-menu" aria-labelledby="examResult">
|
||||||
<li v-for="form in forms">
|
<li v-for="form in forms">
|
||||||
@ -35,7 +35,7 @@
|
|||||||
Результат: {{ result['result'] ?? ''}}
|
Результат: {{ result['result'] ?? ''}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<button @click="deleteResultClick(result['id'])" type="button" class="btn btn-danger ms-3" >
|
<button @click="deleteResultClick(result)" type="button" class="btn btn-danger ms-3" >
|
||||||
Удалить
|
Удалить
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
@ -56,7 +56,7 @@
|
|||||||
|
|
||||||
<button type="button" @click="addResultToRequest" class="btn btn-success p-3 ms-5"> Добавить </button>
|
<button type="button" @click="addResultToRequest" class="btn btn-success p-3 ms-5"> Добавить </button>
|
||||||
</div> -->
|
</div> -->
|
||||||
<div>
|
<div v-if="allResults != null && allResults.length>0">
|
||||||
<div v-for="res in allResults" >
|
<div v-for="res in allResults" >
|
||||||
<p>
|
<p>
|
||||||
<span class="me-4">{{res['title'] ?? '' }}: {{ res['result'] ?? '' }} баллов</span>
|
<span class="me-4">{{res['title'] ?? '' }}: {{ res['result'] ?? '' }} баллов</span>
|
||||||
@ -86,13 +86,28 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
async deleteResultClick(id) {
|
async deleteResultClick(res) {
|
||||||
|
|
||||||
|
if (localStorage.getItem('db') == 'mongo'){
|
||||||
|
for(const oldres of this.results){
|
||||||
|
if (res['title'] == oldres['title']) {
|
||||||
|
const index = this.results.indexOf(oldres)
|
||||||
|
this.results.splice(index, 1)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await this.saveRequest(false)
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let data = JSON.stringify({
|
let data = JSON.stringify({
|
||||||
"request_id": this.requestId,
|
"request_id": this.requestId,
|
||||||
"exam_result_id": id
|
"exam_result_id": res['id']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
method: 'delete',
|
method: 'delete',
|
||||||
maxBodyLength: Infinity,
|
maxBodyLength: Infinity,
|
||||||
@ -103,7 +118,7 @@ export default {
|
|||||||
data : data
|
data : data
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.request(config)
|
await axios.request(config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(JSON.stringify(response.data));
|
console.log(JSON.stringify(response.data));
|
||||||
})
|
})
|
||||||
@ -115,6 +130,16 @@ export default {
|
|||||||
|
|
||||||
async addResultToRequest(res) {
|
async addResultToRequest(res) {
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
if (localStorage.getItem('db') == 'mongo'){
|
||||||
|
console.log(res)
|
||||||
|
// добавление результата к заявке
|
||||||
|
this.results.push(res)
|
||||||
|
await this.saveRequest(false)
|
||||||
|
window.location.reload()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log('Save new result')
|
console.log('Save new result')
|
||||||
console.log(this.requestId)
|
console.log(this.requestId)
|
||||||
console.log(res)
|
console.log(res)
|
||||||
@ -151,8 +176,52 @@ export default {
|
|||||||
window.location.reload()
|
window.location.reload()
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveRequest() {
|
async saveRequest(withPush) {
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
|
||||||
|
if (localStorage.getItem('db') == 'mongo'){
|
||||||
|
|
||||||
|
let data = JSON.stringify({
|
||||||
|
"id": this.requestId,
|
||||||
|
"education_form": this.educationForm['title'] ?? this.educationForm,
|
||||||
|
"specialization": this.specialization['title'] ?? this.specialization,
|
||||||
|
"exam_results": this.results,
|
||||||
|
"date": this.request['date'],
|
||||||
|
"abitur_id": localStorage.getItem('abiturId')
|
||||||
|
});
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
method: 'put',
|
||||||
|
maxBodyLength: Infinity,
|
||||||
|
url: 'http://127.0.0.1:8080/api/request',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data : data
|
||||||
|
};
|
||||||
|
|
||||||
|
await axios.request(config)
|
||||||
|
.then((response) => {
|
||||||
|
console.log(JSON.stringify(response.data));
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (withPush == false) return
|
||||||
|
this.$router.push(
|
||||||
|
{
|
||||||
|
name: "AbiturMain",
|
||||||
|
params: {
|
||||||
|
abiturId: localStorage.getItem('abiturId')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
let data = JSON.stringify({
|
let data = JSON.stringify({
|
||||||
"id": this.requestId,
|
"id": this.requestId,
|
||||||
"education_form_id": this.educationForm['id'],
|
"education_form_id": this.educationForm['id'],
|
||||||
@ -170,7 +239,7 @@ export default {
|
|||||||
data : data
|
data : data
|
||||||
};
|
};
|
||||||
|
|
||||||
axios.request(config)
|
await axios.request(config)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
console.log(JSON.stringify(response.data));
|
console.log(JSON.stringify(response.data));
|
||||||
})
|
})
|
||||||
@ -193,6 +262,38 @@ export default {
|
|||||||
// получаем заявку
|
// получаем заявку
|
||||||
this.requestId = this.$route.params.requestId
|
this.requestId = this.$route.params.requestId
|
||||||
console.log(this.requestId)
|
console.log(this.requestId)
|
||||||
|
if (localStorage.getItem('db') == 'mongo'){
|
||||||
|
this.request = (await axios.get('http://127.0.0.1:8080/api/request/' + this.requestId)).data
|
||||||
|
console.log('mongo')
|
||||||
|
console.log(this.request)
|
||||||
|
console.log(this.request['date'])
|
||||||
|
this.educationForm = this.request['education_form']
|
||||||
|
this.specialization = this.request['specialization']
|
||||||
|
|
||||||
|
var request_result_pairs = this.request['exam_results']
|
||||||
|
for(const pair of request_result_pairs) {
|
||||||
|
this.results.push(pair)
|
||||||
|
}
|
||||||
|
|
||||||
|
var allResults = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + localStorage.getItem('abiturId'))).data
|
||||||
|
|
||||||
|
var flag = true;
|
||||||
|
for (const allRes of allResults) {
|
||||||
|
flag = true;
|
||||||
|
for(const res of this.results) {
|
||||||
|
if (allRes['title'] == res['title']) {flag = false}
|
||||||
|
}
|
||||||
|
if (flag) {
|
||||||
|
this.allResults.push(allRes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//specs and forms
|
||||||
|
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
||||||
|
this.forms = (await axios.get('http://127.0.0.1:8080/api/educationform')).data
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log('pgsql')
|
||||||
this.request = (await axios.get('http://127.0.0.1:8080/api/request/' + this.requestId)).data
|
this.request = (await axios.get('http://127.0.0.1:8080/api/request/' + this.requestId)).data
|
||||||
console.log(this.request)
|
console.log(this.request)
|
||||||
// получаем ее специализацию и форму обучения
|
// получаем ее специализацию и форму обучения
|
||||||
@ -211,7 +312,6 @@ export default {
|
|||||||
var allResults = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.request['abitur_id'])).data
|
var allResults = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.request['abitur_id'])).data
|
||||||
//console.log(allResults)
|
//console.log(allResults)
|
||||||
//
|
//
|
||||||
|
|
||||||
var flag = true;
|
var flag = true;
|
||||||
for (const allRes of allResults) {
|
for (const allRes of allResults) {
|
||||||
flag = true;
|
flag = true;
|
||||||
@ -223,7 +323,6 @@ export default {
|
|||||||
this.allResults.push(allRes)
|
this.allResults.push(allRes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// получаем все формы обучения и специализации
|
// получаем все формы обучения и специализации
|
||||||
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
||||||
this.forms = (await axios.get('http://127.0.0.1:8080/api/educationform')).data
|
this.forms = (await axios.get('http://127.0.0.1:8080/api/educationform')).data
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import fs from 'fs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
@ -37,9 +39,76 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
|
//async saveDataToJson() {
|
||||||
|
// if (localStorage.getItem('db') == 'mongo') {
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
|
// var mongoData = []
|
||||||
|
// var abiturs = (await axios.get('http://127.0.0.1:8080/api/abitur')).data
|
||||||
|
// mongoData = mongoData.concat(abiturs)
|
||||||
|
|
||||||
|
// for(let abitur of mongoData) {
|
||||||
|
// // saving exam results for every abitur
|
||||||
|
// var exam_results = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + abitur['id'])).data
|
||||||
|
// for (let exam_res of exam_results) {
|
||||||
|
// abitur['exam_results'] = abitur['exam_results'] ?? []
|
||||||
|
// abitur['exam_results'].push({
|
||||||
|
// 'title': exam_res['title'],
|
||||||
|
// 'result': exam_res['result']
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
// //saving requests for every abitur
|
||||||
|
// var requests = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + abitur['id'])).data
|
||||||
|
// //console.log(requests)
|
||||||
|
// for (let req of requests) {
|
||||||
|
// abitur['requests'] = abitur['requests'] ?? []
|
||||||
|
|
||||||
|
// let education_form = (await axios.get('http://127.0.0.1:8080/api/educationform/' + req['education_form_id'])).data
|
||||||
|
// let specialization = (await axios.get('http://127.0.0.1:8080/api/specialization/' + req['specialization_id'])).data
|
||||||
|
|
||||||
|
// //получаем закрепленные за заявкой результаты
|
||||||
|
// let results = []
|
||||||
|
|
||||||
|
// var request_result_pairs = (await axios.get('http://127.0.0.1:8080/api/request_examresult/' + req['id'])).data
|
||||||
|
// for(const pair of request_result_pairs) {
|
||||||
|
// results.push((await axios.get('http://127.0.0.1:8080/api/examresult/' + pair['exam_result_id'])).data)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let formattedResults = []
|
||||||
|
|
||||||
|
|
||||||
|
// for(let res of results) {
|
||||||
|
// formattedResults.push({
|
||||||
|
// 'title': res['title'],
|
||||||
|
// 'result': res['result']
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
|
||||||
|
// abitur['requests'].push({
|
||||||
|
// 'date': req['date'],
|
||||||
|
// 'education_form': education_form['title'],
|
||||||
|
// 'specialization': specialization['title'],
|
||||||
|
// 'exam_results': formattedResults
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// console.log(mongoData)
|
||||||
|
// const fs = require('fs');
|
||||||
|
// let data = JSON.stringify(mongoData)
|
||||||
|
// fs.writeFileSync('mongoDataSave.json', data)
|
||||||
|
// console.log('saved!')
|
||||||
|
//},
|
||||||
|
|
||||||
async getDestiny() {
|
async getDestiny() {
|
||||||
if (this.specialization == null) return
|
if (this.specialization == null) return
|
||||||
|
if (localStorage.getItem('db') == 'mongo') {
|
||||||
|
await this.getMongoDestiny()
|
||||||
|
return
|
||||||
|
}
|
||||||
var time = performance.now()
|
var time = performance.now()
|
||||||
|
|
||||||
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['id'])).data
|
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['id'])).data
|
||||||
@ -57,6 +126,22 @@ export default {
|
|||||||
this.destiny = 'ЗАПРОСОВ: ' + count['count'] + ', СРЕДНИЙ BALL: ' + avg['avg'] + '. ПОЗДРАВЛЯЮ! Время: ' + time + 'c.'
|
this.destiny = 'ЗАПРОСОВ: ' + count['count'] + ', СРЕДНИЙ BALL: ' + avg['avg'] + '. ПОЗДРАВЛЯЮ! Время: ' + time + 'c.'
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getMongoDestiny() {
|
||||||
|
var time = performance.now()
|
||||||
|
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['title'] ?? this.specialization)).data
|
||||||
|
console.log(avg['avg_result'])
|
||||||
|
var count = (await axios.get('http://127.0.0.1:8080/api/request/spec/'+this.specialization['title'])).data
|
||||||
|
console.log(count)
|
||||||
|
var time = (performance.now() - time) / 1000
|
||||||
|
|
||||||
|
if (count == null || avg == null) {
|
||||||
|
this.destiny = 'ТВОЯ ОТЧЕТНОСТЬ ПРОКЛЯТА. УБИРАЙСЯ!'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.destiny = 'ЗАПРОСОВ: ' + count + ', СРЕДНИЙ BALL: ' + avg['avg_result'] + '. ПОЗДРАВЛЯЮ! Время: ' + time + 'c.'
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
async deleteAllAbiturs() {
|
async deleteAllAbiturs() {
|
||||||
try {
|
try {
|
||||||
this.deleteAllMessage='Жнец идет за их душами...'
|
this.deleteAllMessage='Жнец идет за их душами...'
|
||||||
@ -77,6 +162,12 @@ export default {
|
|||||||
if (this.specializations == null || this.specialization.length == 0) {
|
if (this.specializations == null || this.specialization.length == 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (localStorage.getItem('db') == 'mongo') {
|
||||||
|
await this.generateMongoSlaves()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
console.log(this.specializations)
|
console.log(this.specializations)
|
||||||
// удалим старых, дорогу молодым емае
|
// удалим старых, дорогу молодым емае
|
||||||
await this.deleteAllAbiturs()
|
await this.deleteAllAbiturs()
|
||||||
@ -200,11 +291,77 @@ export default {
|
|||||||
var matan = Math.floor(Math.random() * max);
|
var matan = Math.floor(Math.random() * max);
|
||||||
console.log('matan end')
|
console.log('matan end')
|
||||||
return matan
|
return matan
|
||||||
}
|
},
|
||||||
|
|
||||||
|
async generateMongoSlaves() {
|
||||||
|
// удалим старых, дорогу молодым емае
|
||||||
|
await this.deleteAllAbiturs()
|
||||||
|
this.magicMessage='Плодим, ждите...'
|
||||||
|
var averageTime = 0
|
||||||
|
|
||||||
|
for(const spec of this.specializations) {
|
||||||
|
// создаем бедных студентиков сто штучек оптовая цена
|
||||||
|
var oneSpecTime = performance.now()
|
||||||
|
|
||||||
|
for (let abiturNum = 0 + parseInt(spec['id'], 10) * 100; abiturNum < 100 + parseInt(spec['id'], 10) * 100; abiturNum++) {
|
||||||
|
|
||||||
|
let exam_results = [
|
||||||
|
{
|
||||||
|
"title": "Exam#" + abiturNum + "-1",
|
||||||
|
"result": this.getRandomInt(100)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Exam#" + abiturNum + "-2",
|
||||||
|
"result": this.getRandomInt(100)
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "Exam#" + abiturNum + "-3",
|
||||||
|
"result": this.getRandomInt(100)
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
let data = JSON.stringify({
|
||||||
|
"id": abiturNum,
|
||||||
|
"first_name": "Vasya " + abiturNum,
|
||||||
|
"last_name": "Pupkin " + abiturNum,
|
||||||
|
"middle_name": "Vasylyevich " + abiturNum,
|
||||||
|
"email": "mylo" + abiturNum,
|
||||||
|
"password": "parol" + abiturNum,
|
||||||
|
"exam_results": exam_results,
|
||||||
|
"requests": [
|
||||||
|
{
|
||||||
|
"exam_results": exam_results,
|
||||||
|
"date": Date.now(),
|
||||||
|
"specialization": spec['title'],
|
||||||
|
"education_form": "Заочная"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
let config = {
|
||||||
|
method: 'post',
|
||||||
|
maxBodyLength: Infinity,
|
||||||
|
url: 'http://127.0.0.1:8080/api/abitur/manual',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
data : data
|
||||||
|
};
|
||||||
|
|
||||||
|
await axios.request(config)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
oneSpecTime = performance.now() - oneSpecTime
|
||||||
|
averageTime += oneSpecTime
|
||||||
|
}
|
||||||
|
averageTime = averageTime / this.specializations.length / 1000
|
||||||
|
this.magicMessage='Наплодили! Среднее время на каждую специализацию: '+ averageTime + 'c.'
|
||||||
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
|
|
||||||
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
||||||
this.specialization = this.specializations[0]
|
this.specialization = this.specializations[0]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user