Compare commits
No commits in common. "Lab8" and "main" have entirely different histories.
@ -1,5 +0,0 @@
|
||||
#dbPath='../controllers/'
|
||||
dbPath='../mongo/controllers/'
|
||||
#delete '/mongo' to switch to pgsql
|
||||
|
||||
добавить объектные айди к результатам экзамена и вроде готово!
|
32
abitur_list_client/controllers/enrollment.controller.js
Normal file
32
abitur_list_client/controllers/enrollment.controller.js
Normal file
@ -0,0 +1,32 @@
|
||||
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])
|
||||
}
|
||||
async deleteExamResult(req, res) {
|
||||
const {result_id} = req.body
|
||||
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [result_id])
|
||||
const id = req.params.id
|
||||
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [id])
|
||||
res.json(results.rows[0])
|
||||
}
|
||||
async getAbiturExamResults(req, res) {
|
||||
|
@ -28,8 +28,8 @@ class RequestController extends RequestControllerInterface {
|
||||
res.json(newRequest.rows[0])
|
||||
}
|
||||
async deleteRequest(req, res) {
|
||||
const {request_id} = req.body
|
||||
const requests = await db.query('DELETE FROM request WHERE id=' + request_id.toString())
|
||||
const id = req.params.id
|
||||
const requests = await db.query('DELETE FROM request WHERE id=$1', [id])
|
||||
res.json(requests.rows[0])
|
||||
}
|
||||
async getAbiturRequests(req, res) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
const express = require('express')
|
||||
require('dotenv').config()
|
||||
|
||||
const abiturRouter = require('./routes/abitur.routes')
|
||||
const examResultRouter = require('./routes/examresult.routes')
|
||||
|
@ -1,127 +0,0 @@
|
||||
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()
|
@ -1,37 +0,0 @@
|
||||
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()
|
@ -1,103 +0,0 @@
|
||||
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()
|
@ -1,159 +0,0 @@
|
||||
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()
|
@ -1,37 +0,0 @@
|
||||
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()
|
File diff suppressed because one or more lines are too long
@ -1,20 +0,0 @@
|
||||
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,9 +10,7 @@
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"core-js": "^3.8.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"fs": "^0.0.1-security",
|
||||
"mongodb": "^5.5.0",
|
||||
"mongoose": "^7.1.1",
|
||||
"pg": "^8.10.0",
|
||||
@ -2590,15 +2588,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"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": {
|
||||
"version": "5.0.8",
|
||||
"resolved": "https://registry.npmmirror.com/@vue/cli-shared-utils/-/cli-shared-utils-5.0.8.tgz",
|
||||
@ -4738,11 +4727,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==",
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv-expand": {
|
||||
@ -5234,11 +5224,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": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
||||
@ -12201,14 +12186,6 @@
|
||||
"webpack-merge": "^5.7.3",
|
||||
"webpack-virtual-modules": "^0.4.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": {
|
||||
@ -13967,9 +13944,10 @@
|
||||
}
|
||||
},
|
||||
"dotenv": {
|
||||
"version": "16.0.3",
|
||||
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz",
|
||||
"integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ=="
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-10.0.0.tgz",
|
||||
"integrity": "sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==",
|
||||
"dev": true
|
||||
},
|
||||
"dotenv-expand": {
|
||||
"version": "5.1.0",
|
||||
@ -14376,11 +14354,6 @@
|
||||
"resolved": "https://registry.npmmirror.com/fresh/-/fresh-0.5.2.tgz",
|
||||
"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": {
|
||||
"version": "9.1.0",
|
||||
"resolved": "https://registry.npmmirror.com/fs-extra/-/fs-extra-9.1.0.tgz",
|
||||
|
@ -5,15 +5,12 @@
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"start": "pm2 start index.js",
|
||||
"startMongo": "node mongoIndex.js"
|
||||
"start": "pm2 start index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^1.3.4",
|
||||
"core-js": "^3.8.3",
|
||||
"dotenv": "^16.0.3",
|
||||
"express": "^4.18.2",
|
||||
"fs": "^0.0.1-security",
|
||||
"mongodb": "^5.5.0",
|
||||
"mongoose": "^7.1.1",
|
||||
"pg": "^8.10.0",
|
||||
@ -33,10 +30,5 @@
|
||||
"last 2 versions",
|
||||
"not dead",
|
||||
"not ie 11"
|
||||
],
|
||||
"browser": {
|
||||
"fs": false,
|
||||
"path": false,
|
||||
"os": false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
//const abiturController = require('../controllers/abitur.controller')
|
||||
const abiturController = require(process.env.dbPath + 'abitur.controller')
|
||||
const abiturController = require('../controllers/abitur.controller')
|
||||
|
||||
router.post('/abitur', abiturController.createAbitur)
|
||||
router.post('/abitur/manual', abiturController.createAbiturWithId)
|
||||
|
@ -1,8 +1,7 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
//const educationformController = require('../controllers/educationform.controller')
|
||||
const educationformController = require(process.env.dbPath + 'educationform.controller')
|
||||
const educationformController = require('../controllers/educationform.controller')
|
||||
|
||||
router.post('/educationform', educationformController.createEducationForm)
|
||||
router.get('/educationform', educationformController.getEducationForms)
|
||||
|
12
abitur_list_client/routes/enrollment.routes.js
Normal file
12
abitur_list_client/routes/enrollment.routes.js
Normal file
@ -0,0 +1,12 @@
|
||||
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,15 +1,14 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
//const examResultController = require('../controllers/examresult.controller')
|
||||
const examResultController = require(process.env.dbPath + 'examresult.controller')
|
||||
const examResultController = require('../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', examResultController.deleteExamResult)
|
||||
router.delete('/examresult/:id', examResultController.deleteExamResult)
|
||||
router.get('/examresult/abitur/:id', examResultController.getAbiturExamResults)
|
||||
router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization)
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
//const requestController = require('..//controllers/request.controller')
|
||||
const requestController = require(process.env.dbPath + 'request.controller')
|
||||
const requestController = require('../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/', requestController.deleteRequest)
|
||||
router.delete('/request/:id', requestController.deleteRequest)
|
||||
router.get('/request/abitur/:id', requestController.getAbiturRequests)
|
||||
router.get('/request/spec/:id', requestController.getCountBySpec)
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
const Router = require('express')
|
||||
const router = new Router()
|
||||
|
||||
//const specializationController = require('../controllers/specialization.controller')
|
||||
const specializationController = require(process.env.dbPath + 'specialization.controller')
|
||||
const specializationController = require('../controllers/specialization.controller')
|
||||
|
||||
router.post('/specialization', specializationController.createSpecialization)
|
||||
router.get('/specialization', specializationController.getSpecializations)
|
||||
|
@ -1,53 +0,0 @@
|
||||
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()
|
@ -1,65 +0,0 @@
|
||||
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,6 +4,17 @@
|
||||
Здравствуйте, {{this.firstName}} {{this.lastName}}
|
||||
</p>
|
||||
|
||||
<!--
|
||||
Добавить логин и пароль для абитуриента при регистрации и авторизации (хранить в бд) done!
|
||||
Добавить уведомления при регистрации и авторизации done!
|
||||
Добавить секретную страничку для админа с отчетом
|
||||
Добавить отчет
|
||||
Добавить генерацию данных для отчета и замер запроса для отчета
|
||||
При выборе предметов во время создания заявки сделать более удобный выбор предметов и их добавление done!
|
||||
Шифровка пароля done!
|
||||
-->
|
||||
|
||||
|
||||
|
||||
<p class='h5'>Мои результаты:</p>
|
||||
<ul class='text-start'>
|
||||
@ -15,7 +26,7 @@
|
||||
Результат: {{ result['result']}}
|
||||
</p>
|
||||
<p>
|
||||
<button @click="deleteResultClick(result['id'] ?? result['_id'])" type="button" class="btn btn-danger ms-3" >
|
||||
<button @click="deleteResultClick(result['id'])" type="button" class="btn btn-danger ms-3" >
|
||||
Удалить
|
||||
</button>
|
||||
</p>
|
||||
@ -55,10 +66,10 @@
|
||||
Дата: {{ request['date'].slice(0,10)}}
|
||||
</p>
|
||||
<p>
|
||||
<button @click="onRequestButtonClick(request['id'] ?? request['_id'])" type="button" class="btn btn-warning ms-3" >
|
||||
<button @click="onRequestButtonClick(request['id'])" type="button" class="btn btn-warning ms-3" >
|
||||
Посмотреть
|
||||
</button>
|
||||
<button @click="deleteRequest(request['id'] ?? request['_id'])" type="button" class="btn btn-danger ms-3"> Удалить</button>
|
||||
<button @click="deleteRequest(request['id'])" type="button" class="btn btn-danger ms-3"> Удалить</button>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
@ -90,22 +101,12 @@ 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
|
||||
|
||||
@ -150,42 +151,7 @@ export default {
|
||||
},
|
||||
|
||||
async deleteResultClick(id) {
|
||||
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 axios.delete('http://127.0.0.1:8080/api/examresult/' + id)
|
||||
await this.refresh()
|
||||
window.location.reload()
|
||||
},
|
||||
@ -224,7 +190,7 @@ export default {
|
||||
|
||||
await axios.request(config)
|
||||
.then((response) => {
|
||||
requestId = response.data['id'] ?? response.data['_id']
|
||||
requestId = response.data['id']
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
@ -241,46 +207,7 @@ export default {
|
||||
},
|
||||
|
||||
async deleteRequest(requestId) {
|
||||
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()
|
||||
await axios.delete('http://127.0.0.1:8080/api/request/' + requestId)
|
||||
window.location.reload()
|
||||
},
|
||||
|
||||
|
@ -47,16 +47,10 @@ 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) {
|
||||
|
@ -1,11 +1,11 @@
|
||||
<template>
|
||||
<div class="text-center m-3">
|
||||
<p class="h3"> Ваша заявка: </p>
|
||||
<p class=""> Дата: {{ this.request == null ? '' : this.request['date']}} </p>
|
||||
<p class=""> Дата: {{ this.request['date'].slice(0,10) ?? ''}} </p>
|
||||
<div class="h4">
|
||||
Специализация:
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{{ specialization == null ? '' : specialization['title'] ?? specialization }}
|
||||
{{ specialization['title'] ?? '' }}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="examResult">
|
||||
<li v-for="spec in specializations">
|
||||
@ -16,7 +16,7 @@
|
||||
<div class="h4">
|
||||
Форма обучения:
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="examResult" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
{{ educationForm == null ? '' : educationForm['title'] ?? educationForm}}
|
||||
{{ educationForm['title'] ?? ''}}
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="examResult">
|
||||
<li v-for="form in forms">
|
||||
@ -35,7 +35,7 @@
|
||||
Результат: {{ result['result'] ?? ''}}
|
||||
</p>
|
||||
<p>
|
||||
<button @click="deleteResultClick(result)" type="button" class="btn btn-danger ms-3" >
|
||||
<button @click="deleteResultClick(result['id'])" type="button" class="btn btn-danger ms-3" >
|
||||
Удалить
|
||||
</button>
|
||||
</p>
|
||||
@ -56,7 +56,7 @@
|
||||
|
||||
<button type="button" @click="addResultToRequest" class="btn btn-success p-3 ms-5"> Добавить </button>
|
||||
</div> -->
|
||||
<div v-if="allResults != null && allResults.length>0">
|
||||
<div>
|
||||
<div v-for="res in allResults" >
|
||||
<p>
|
||||
<span class="me-4">{{res['title'] ?? '' }}: {{ res['result'] ?? '' }} баллов</span>
|
||||
@ -86,28 +86,13 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
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
|
||||
}
|
||||
async deleteResultClick(id) {
|
||||
|
||||
let data = JSON.stringify({
|
||||
"request_id": this.requestId,
|
||||
"exam_result_id": res['id']
|
||||
"exam_result_id": id
|
||||
});
|
||||
|
||||
|
||||
|
||||
let config = {
|
||||
method: 'delete',
|
||||
maxBodyLength: Infinity,
|
||||
@ -118,7 +103,7 @@ export default {
|
||||
data : data
|
||||
};
|
||||
|
||||
await axios.request(config)
|
||||
axios.request(config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
})
|
||||
@ -130,16 +115,6 @@ export default {
|
||||
|
||||
async addResultToRequest(res) {
|
||||
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(this.requestId)
|
||||
console.log(res)
|
||||
@ -176,52 +151,8 @@ export default {
|
||||
window.location.reload()
|
||||
},
|
||||
|
||||
async saveRequest(withPush) {
|
||||
async saveRequest() {
|
||||
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({
|
||||
"id": this.requestId,
|
||||
"education_form_id": this.educationForm['id'],
|
||||
@ -239,7 +170,7 @@ export default {
|
||||
data : data
|
||||
};
|
||||
|
||||
await axios.request(config)
|
||||
axios.request(config)
|
||||
.then((response) => {
|
||||
console.log(JSON.stringify(response.data));
|
||||
})
|
||||
@ -262,38 +193,6 @@ export default {
|
||||
// получаем заявку
|
||||
this.requestId = this.$route.params.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
|
||||
console.log(this.request)
|
||||
// получаем ее специализацию и форму обучения
|
||||
@ -312,6 +211,7 @@ export default {
|
||||
var allResults = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.request['abitur_id'])).data
|
||||
//console.log(allResults)
|
||||
//
|
||||
|
||||
var flag = true;
|
||||
for (const allRes of allResults) {
|
||||
flag = true;
|
||||
@ -323,6 +223,7 @@ export default {
|
||||
this.allResults.push(allRes)
|
||||
}
|
||||
}
|
||||
|
||||
// получаем все формы обучения и специализации
|
||||
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
|
||||
|
@ -26,8 +26,6 @@
|
||||
</template>
|
||||
<script>
|
||||
import axios from 'axios'
|
||||
import fs from 'fs'
|
||||
|
||||
export default {
|
||||
data(){
|
||||
return {
|
||||
@ -39,76 +37,9 @@ export default {
|
||||
}
|
||||
},
|
||||
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() {
|
||||
if (this.specialization == null) return
|
||||
if (localStorage.getItem('db') == 'mongo') {
|
||||
await this.getMongoDestiny()
|
||||
return
|
||||
}
|
||||
|
||||
var time = performance.now()
|
||||
|
||||
var avg = (await axios.get('http://127.0.0.1:8080/api/examresult/avgBySpec/'+this.specialization['id'])).data
|
||||
@ -126,22 +57,6 @@ export default {
|
||||
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() {
|
||||
try {
|
||||
this.deleteAllMessage='Жнец идет за их душами...'
|
||||
@ -162,12 +77,6 @@ export default {
|
||||
if (this.specializations == null || this.specialization.length == 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if (localStorage.getItem('db') == 'mongo') {
|
||||
await this.generateMongoSlaves()
|
||||
return
|
||||
}
|
||||
|
||||
console.log(this.specializations)
|
||||
// удалим старых, дорогу молодым емае
|
||||
await this.deleteAllAbiturs()
|
||||
@ -291,77 +200,11 @@ export default {
|
||||
var matan = Math.floor(Math.random() * max);
|
||||
console.log('matan end')
|
||||
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() {
|
||||
|
||||
this.specializations = (await axios.get('http://127.0.0.1:8080/api/specialization')).data
|
||||
this.specialization = this.specializations[0]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user