Сделана настройка приложения для мангодб КРОМЕ отчетов (спать хочу)

This commit is contained in:
Данила Мочалов 2023-05-14 01:50:44 +04:00
parent c83120d742
commit 5cdd7ec752
19 changed files with 684 additions and 98 deletions

View File

@ -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()

View File

@ -28,8 +28,8 @@ class ExamResultController extends ExamResultControllerInterface {
res.json(newExamResult.rows[0])
}
async deleteExamResult(req, res) {
const id = req.params.id
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [id])
const {result_id} = req.body
const results = await db.query('DELETE FROM exam_result WHERE id=$1', [result_id])
res.json(results.rows[0])
}
async getAbiturExamResults(req, res) {

View File

@ -28,8 +28,8 @@ class RequestController extends RequestControllerInterface {
res.json(newRequest.rows[0])
}
async deleteRequest(req, res) {
const id = req.params.id
const requests = await db.query('DELETE FROM request WHERE id=$1', [id])
const {request_id} = req.body
const requests = await db.query('DELETE FROM request WHERE id=' + request_id.toString())
res.json(requests.rows[0])
}
async getAbiturRequests(req, res) {

View File

@ -0,0 +1,123 @@
const mymongodb = require('../../mongoIndex')
const crypto = require('crypto');
const AbiturControllerInterface = require('../../controllers/interfaces/abitur.controller.interface');
const { ObjectId } = require('mongodb');
class AbiturController extends AbiturControllerInterface{
async createAbitur(req, res) {
// const {first_name, last_name, middle_name, email, password} = req.body
// var hash = crypto.createHash('md5').update(password).digest('hex');
// const newAbitur = await db.query('INSERT INTO abitur (first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5) RETURNING *', [first_name, last_name, middle_name, email, hash])
// res.json(newAbitur.rows[0])
const {first_name, last_name, middle_name, email, password} = req.body
var hash = crypto.createHash('md5').update(password).digest('hex')
const collection = mymongodb.collection('abiturs')
const newAbitur = collection.insertOne({
first_name: first_name,
last_name: last_name,
middle_name: middle_name,
email: email,
password: hash
})
res.json({id: 1})
}
async createAbiturWithId(req, res) {
// const {id, first_name, last_name, middle_name, email, password} = req.body
// var hash = crypto.createHash('md5').update(password).digest('hex');
// const newAbitur = await db.query('INSERT INTO abitur (id, first_name, last_name, middle_name, email, password) VALUES ($1, $2, $3, $4, $5, $6) RETURNING *', [id, first_name, last_name, middle_name, email, hash])
// res.json(newAbitur.rows[0])
const {id, first_name, last_name, middle_name, email, password} = req.body
var hash = crypto.createHash('md5').update(password).digest('hex')
const collection = mymongodb.collection('abiturs')
const newAbitur = await collection.insertOne({
_id: new ObjectId(id),
first_name: first_name,
last_name: last_name,
middle_name: middle_name,
email: email,
password: hash
})
if (newAbitur!=null) res.json({id: 1})
}
async getAbiturs(req, res) {
// const abiturs = await db.query('SELECT * FROM abitur')
// res.json(abiturs.rows)
const collection = mymongodb.collection('abiturs')
const abiturs = await collection.find().toArray()
res.json(abiturs)
}
async getOneAbitur(req, res) {
// const id = req.params.id
// const abiturs = await db.query('SELECT * FROM abitur WHERE id=$1', [id])
// res.json(abiturs.rows[0])
const id = req.params.id
const collection = mymongodb.collection('abiturs')
const abiturs = await collection.findOne({_id: new ObjectId(id)})
res.json(abiturs)
}
async authAbitur(req, res) {
// const {email, password} = req.body
// var hash = crypto.createHash('md5').update(password).digest('hex');
// const abitur = await db.query('SELECT * FROM abitur WHERE email = $1 AND password = $2', [email, hash])
// res.json(abitur.rows[0])
const collection = mymongodb.collection('abiturs')
const {email, password} = req.body
var hash = crypto.createHash('md5').update(password).digest('hex')
const abitur = await collection.findOne({email: email, password: hash})
res.json(abitur)
}
async updateAbitur(req, res) {
// const {id, first_name, last_name, middle_name} = req.body
// const newAbitur = await db.query('UPDATE abitur SET first_name=$1, last_name=$2, middle_name=$3 WHERE id=$4 RETURNING *', [first_name, last_name, middle_name, id])
// res.json(newAbitur.rows[0])
const {id, first_name, last_name, middle_name} = req.body
const collection = mymongodb.collection('abiturs')
await collection.findOneAndUpdate({_id: id}, {$set: {
first_name: first_name,
last_name: last_name,
middle_name: middle_name,
}})
res.json({id: 1})
}
async deleteAbitur(req, res) {
// const id = req.params.id
// const abiturs = await db.query('DELETE FROM abitur WHERE id=$1', [id])
// res.json(abiturs.rows[0])
const id = req.params.id
const collection = mymongodb.collection('abiturs')
await collection.findOneAndDelete({_id: id})
res.json({id: 1})
}
async deleteAll(req, res) {
// const abiturs = await db.query('DELETE FROM abitur')
// res.json(abiturs.rows)
const collection = mymongodb.collection('abiturs')
await collection.drop()
}
}
module.exports = new AbiturController()

View File

@ -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()

View File

@ -0,0 +1,86 @@
const mymongodb = require('../../mongoIndex')
const ExamResultControllerInterface = require('../../controllers/interfaces/examresult.controller.interface');
const { ObjectId } = require('mongodb');
class ExamResultController extends ExamResultControllerInterface {
async createExamResult(req, res) {
// const {title, result, abitur_id} = req.body
// const newExamResult = await db.query('INSERT INTO exam_result (title, result, abitur_id) VALUES ($1, $2, $3) RETURNING *', [title, result, abitur_id])
// res.json(newExamResult.rows[0])
const {title, result, abitur_id} = req.body
const collection = mymongodb.collection('abiturs')
await collection.updateOne({_id: new ObjectId(abitur_id)},
{
$push: { exam_results: {
_id: new ObjectId(),
title: title,
result: result
} }
}
)
}
async createExamResultWithId(req, res) {
// const {id, title, result, abitur_id} = req.body
// const newExamResult = await db.query('INSERT INTO exam_result (id, title, result, abitur_id) VALUES ($1, $2, $3, $4) RETURNING *', [id, title, result, abitur_id])
// res.json(newExamResult.rows[0])
const {id, title, result, abitur_id} = req.body
const collection = mymongodb.collection('abiturs')
await collection.updateOne({_id: new ObjectId(abitur_id)},
{
$push: { exam_results: {
_id: new ObjectId(id),
title: title,
result: result
} }
}
)
}
async getExamResults(req, res) {
// const results = await db.query('SELECT * FROM exam_result')
// res.json(results.rows)
}
async getOneExamResult(req, res) {
// const id = req.params.id
// const results = await db.query('SELECT * FROM exam_result WHERE id=$1', [id])
// res.json(results.rows[0])
}
async updateExamResult(req, res) {
// const {id, title, result} = req.body
// const newExamResult = await db.query('UPDATE exam_result SET title=$1, result=$2 WHERE id=$3 RETURNING *', [title, result, id])
// res.json(newExamResult.rows[0])
}
async deleteExamResult(req, res) {
// const id = req.params.id
// const results = await db.query('DELETE FROM exam_result WHERE id=$1', [id])
// res.json(results.rows[0])
const {abitur_id, result_id} = req.body
const collection = mymongodb.collection('abiturs')
await collection.updateOne({_id: new ObjectId(abitur_id)},
{$pull: {
exam_results: {_id: new ObjectId(result_id)}
}}
)
}
async getAbiturExamResults(req, res) {
// const id = req.params.id
// const results = await db.query('SELECT * FROM exam_result WHERE abitur_id=$1', [id])
// res.json(results.rows)
const collection = mymongodb.collection('abiturs')
const id = req.params.id
const abitur = await collection.findOne({_id: new ObjectId(id)})
res.json(abitur['exam_results'])
}
async getAverageResultBySpecialization(req, res) {
// const id = req.params.id
// const result = await db.query('select avg(result) from exam_result where id in (select exam_result_id from request_exam_result where request_id in (select id from request where specialization_id = $1))', [id])
// res.json(result.rows[0])
}
}
module.exports = new ExamResultController()

View File

@ -0,0 +1,143 @@
const mymongodb = require('../../mongoIndex')
const RequestControllerInterface = require('../../controllers/interfaces/request.controller.interface');
const { ObjectId } = require('mongodb');
class RequestController extends RequestControllerInterface {
async createRequest(req, res) {
// const {abitur_id, education_form_id, specialization_id} = req.body
// const newRequest = await db.query('INSERT INTO request (abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4) RETURNING *', [abitur_id, education_form_id, specialization_id, new Date()])
// res.json(newRequest.rows[0])
const {abitur_id, education_form_id, specialization_id} = req.body
const collection = mymongodb.collection('abiturs')
const education_form = await mymongodb.collection('educationforms').findOne({id: education_form_id})
const specialization = await mymongodb.collection('specializations').findOne({id: specialization_id})
const newreq = {
_id: new ObjectId(),
exam_results: [],
date: Date.now().toString(),
specialization: specialization['title'],
education_form: education_form['title']
}
await collection.updateOne({_id: new ObjectId(abitur_id)},
{
$push: { requests: newreq }
}
)
res.json(newreq)
}
async createRequestWithId(req, res) {
// const {id, abitur_id, education_form_id, specialization_id} = req.body
// const newRequest = await db.query('INSERT INTO request (id, abitur_id, education_form_id, specialization_id, date) VALUES ($1, $2, $3, $4, $5) RETURNING *', [id, abitur_id, education_form_id, specialization_id, new Date()])
// res.json(newRequest.rows[0])
const {id, abitur_id, education_form_id, specialization_id} = req.body
const collection = mymongodb.collection('abiturs')
const education_form = await mymongodb.collection('educationforms').findOne({id: education_form_id})
const specialization = await mymongodb.collection('specializations').findOne({id: specialization_id})
await collection.updateOne({_id: new ObjectId(abitur_id)},
{
$push: { requests: {
_id: new ObjectId(id),
exam_results: [],
date: Date.now().toString(),
specialization: specialization['title'],
education_form: education_form['title']
} }
}
)
}
async getRequests(req, res) {
// const requests = await db.query('SELECT * FROM request')
// res.json(requests.rows)
}
async getOneRequest(req, res) {
// const id = req.params.id
// const requests = await db.query('SELECT * FROM request WHERE id=$1', [id])
// res.json(requests.rows[0])
const id = req.params.id
const collection = mymongodb.collection('abiturs')
const abitur = await collection.findOne({"requests._id": new ObjectId(id)}, {_id: 0, requests: {$elemMatch: {_id: new ObjectId(id)}}})
for(const req of abitur['requests']) {
if (req['_id'] == id){
console.log(req)
res.json(req)
break
}
}
}
async updateRequest(req, res) {
// const {id, education_form_id, specialization_id, date} = req.body
// const newRequest = await db.query('UPDATE request SET education_form_id=$1, specialization_id=$2, date=$3 WHERE id=$4 RETURNING *', [education_form_id, specialization_id, date, id])
// res.json(newRequest.rows[0])
const {id, education_form, specialization, exam_results, date, abitur_id} = req.body
const collection = mymongodb.collection('abiturs')
if (exam_results != null) {
var dictionary = {}
for(const newres of exam_results) {
dictionary[newres['title']] += 1
if (dictionary[newres['title']] > 1){
console.log('same result')
return
}
}
}
await collection.updateOne({_id: new ObjectId(abitur_id)},
{$pull: {
requests: {_id: new ObjectId(id)}
}}
)
await collection.updateOne({_id: new ObjectId(abitur_id)},
{
$push: { requests: {
_id: new ObjectId(id),
exam_results: exam_results,
date: date,
specialization: specialization,
education_form: education_form
} }
}
)
}
async deleteRequest(req, res) {
// const id = req.params.id
// const requests = await db.query('DELETE FROM request WHERE id=$1', [id])
// res.json(requests.rows[0])
const {abitur_id, request_id} = req.body
const collection = mymongodb.collection('abiturs')
await collection.updateOne({_id: new ObjectId(abitur_id)},
{$pull: {
requests: {_id: new ObjectId(request_id)}
}}
)
}
async getAbiturRequests(req, res) {
// const id = req.params.id
// const requests = await db.query('SELECT * FROM request WHERE abitur_id=$1', [id])
// res.json(requests.rows)
}
async getCountBySpec(req, res) {
// const id = req.params.id
// const requests = await db.query('SELECT COUNT(*) FROM request WHERE specialization_id=$1', [id])
// res.json(requests.rows[0])
}
}
module.exports = new RequestController()

View File

@ -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()

View 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

View File

@ -5,7 +5,8 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"start": "pm2 start index.js"
"start": "pm2 start index.js",
"startMongo": "node mongoIndex.js"
},
"dependencies": {
"axios": "^1.3.4",

View File

@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const abiturController = require('../controllers/abitur.controller')
//const abiturController = require('../mongo/controllers/abitur.controller')
router.post('/abitur', abiturController.createAbitur)
router.post('/abitur/manual', abiturController.createAbiturWithId)

View File

@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const educationformController = require('../controllers/educationform.controller')
//const educationformController = require('../mongo/controllers/educationform.controller')
router.post('/educationform', educationformController.createEducationForm)
router.get('/educationform', educationformController.getEducationForms)

View File

@ -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

View File

@ -2,13 +2,14 @@ const Router = require('express')
const router = new Router()
const examResultController = require('../controllers/examresult.controller')
//const examResultController = require('../mongo/controllers/examresult.controller')
router.post('/examresult', examResultController.createExamResult)
router.post('/examresult/manual', examResultController.createExamResultWithId)
router.get('/examresult', examResultController.getExamResults)
router.get('/examresult/:id', examResultController.getOneExamResult)
router.put('/examresult', examResultController.updateExamResult)
router.delete('/examresult/:id', examResultController.deleteExamResult)
router.delete('/examresult', examResultController.deleteExamResult)
router.get('/examresult/abitur/:id', examResultController.getAbiturExamResults)
router.get('/examresult/avgBySpec/:id', examResultController.getAverageResultBySpecialization)

View File

@ -1,14 +1,15 @@
const Router = require('express')
const router = new Router()
const requestController = require('../controllers/request.controller')
const requestController = require('..//controllers/request.controller')
//const requestController = require('../mongo/controllers/request.controller')
router.post('/request', requestController.createRequest)
router.post('/request/manual', requestController.createRequestWithId)
router.get('/request', requestController.getRequests)
router.get('/request/:id', requestController.getOneRequest)
router.put('/request', requestController.updateRequest)
router.delete('/request/:id', requestController.deleteRequest)
router.delete('/request/', requestController.deleteRequest)
router.get('/request/abitur/:id', requestController.getAbiturRequests)
router.get('/request/spec/:id', requestController.getCountBySpec)

View File

@ -2,6 +2,7 @@ const Router = require('express')
const router = new Router()
const specializationController = require('../controllers/specialization.controller')
//const specializationController = require('../mongo/controllers/specialization.controller')
router.post('/specialization', specializationController.createSpecialization)
router.get('/specialization', specializationController.getSpecializations)

View File

@ -4,17 +4,6 @@
Здравствуйте, {{this.firstName}} {{this.lastName}}
</p>
<!--
Добавить логин и пароль для абитуриента при регистрации и авторизации (хранить в бд) done!
Добавить уведомления при регистрации и авторизации done!
Добавить секретную страничку для админа с отчетом
Добавить отчет
Добавить генерацию данных для отчета и замер запроса для отчета
При выборе предметов во время создания заявки сделать более удобный выбор предметов и их добавление done!
Шифровка пароля done!
-->
<p class='h5'>Мои результаты:</p>
<ul class='text-start'>
@ -26,7 +15,7 @@
Результат: {{ result['result']}}
</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>
</p>
@ -66,10 +55,10 @@
Дата: {{ request['date'].slice(0,10)}}
</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 @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>
</li>
</ul>
@ -101,12 +90,22 @@ export default {
async beforeMount(){
this.abiturId = this.$route.params.abiturId
var response = (await axios.get('http://127.0.0.1:8080/api/abitur/' + this.abiturId)).data
if (localStorage.getItem('db') == 'mongo') {
this.firstName = response['first_name']
this.lastName = response['last_name']
this.examResults = response['exam_results'] ?? []
this.requests = response['requests'] ?? []
localStorage.setItem('abiturId', response['_id'])
return
}
this.firstName = response['first_name']
this.lastName = response['last_name']
response = (await axios.get('http://127.0.0.1:8080/api/examresult/abitur/' + this.abiturId)).data
this.examResults = response
response = (await axios.get('http://127.0.0.1:8080/api/request/abitur/' + this.abiturId)).data
this.requests = response
@ -151,7 +150,42 @@ export default {
},
async deleteResultClick(id) {
await axios.delete('http://127.0.0.1:8080/api/examresult/' + 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 this.refresh()
window.location.reload()
},
@ -190,7 +224,7 @@ export default {
await axios.request(config)
.then((response) => {
requestId = response.data['id']
requestId = response.data['id'] ?? response.data['_id']
})
.catch((error) => {
console.log(error);
@ -207,7 +241,46 @@ export default {
},
async deleteRequest(requestId) {
await axios.delete('http://127.0.0.1:8080/api/request/' + 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()
window.location.reload()
},

View File

@ -47,10 +47,16 @@ export default {
await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
console.log(response.data)
this.abiturId = response.data['id']
localStorage.setItem('db', 'pgsql')
if (this.abiturId == null) {
this.abiturId = response.data['_id']
localStorage.setItem('db', 'mongo')
}
})
.catch((error) => {
this.message = 'Ошибка при входе в аккаунт'
this.message = 'Непредвиденная шибка при входе в аккаунт'
console.log(error);
});
if (this.abiturId <= 0 || this.abiturId == null) {

View File

@ -1,11 +1,11 @@
<template>
<div class="text-center m-3">
<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">
Специализация:
<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>
<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['title'] ?? ''}}
{{ educationForm == null ? '' : educationForm['title'] ?? educationForm}}
</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['id'])" type="button" class="btn btn-danger ms-3" >
<button @click="deleteResultClick(result)" 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>
<div v-if="allResults != null && allResults.length>0">
<div v-for="res in allResults" >
<p>
<span class="me-4">{{res['title'] ?? '' }}: {{ res['result'] ?? '' }} баллов</span>
@ -86,13 +86,28 @@ export default {
},
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({
"request_id": this.requestId,
"exam_result_id": id
"exam_result_id": res['id']
});
let config = {
method: 'delete',
maxBodyLength: Infinity,
@ -103,7 +118,7 @@ export default {
data : data
};
axios.request(config)
await axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
@ -115,6 +130,16 @@ 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)
@ -151,8 +176,52 @@ export default {
window.location.reload()
},
async saveRequest() {
async saveRequest(withPush) {
const axios = require('axios');
if (localStorage.getItem('db') == 'mongo'){
let data = JSON.stringify({
"id": this.requestId,
"education_form": this.educationForm,
"specialization": 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
};
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'],
@ -193,6 +262,38 @@ 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['_id'] == res['_id']) {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)
// получаем ее специализацию и форму обучения
@ -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
//console.log(allResults)
//
var flag = true;
for (const allRes of allResults) {
flag = true;
@ -223,7 +323,6 @@ 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