ГОТОВООООООООООО
This commit is contained in:
parent
e04eefb8a2
commit
234b49d7b7
@ -1,2 +1,5 @@
|
|||||||
dbPath='../controllers/'
|
#dbPath='../controllers/'
|
||||||
|
dbPath='../mongo/controllers/'
|
||||||
#delete '/mongo' to switch to pgsql
|
#delete '/mongo' to switch to pgsql
|
||||||
|
|
||||||
|
добавить объектные айди к результатам экзамена и вроде готово!
|
@ -19,7 +19,7 @@ class RequestController extends RequestControllerInterface {
|
|||||||
const newreq = {
|
const newreq = {
|
||||||
_id: new ObjectId(),
|
_id: new ObjectId(),
|
||||||
exam_results: [],
|
exam_results: [],
|
||||||
date: Date.now().toString(),
|
date: new Date(),
|
||||||
specialization: specialization['title'],
|
specialization: specialization['title'],
|
||||||
education_form: education_form['title']
|
education_form: education_form['title']
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ class RequestController extends RequestControllerInterface {
|
|||||||
$push: { requests: {
|
$push: { requests: {
|
||||||
_id: new ObjectId(id),
|
_id: new ObjectId(id),
|
||||||
exam_results: [],
|
exam_results: [],
|
||||||
date: Date.now().toString(),
|
date: new Date(),
|
||||||
specialization: specialization['title'],
|
specialization: specialization['title'],
|
||||||
education_form: education_form['title']
|
education_form: education_form['title']
|
||||||
} }
|
} }
|
||||||
|
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
11
abitur_list_client/package-lock.json
generated
11
abitur_list_client/package-lock.json
generated
@ -12,6 +12,7 @@
|
|||||||
"core-js": "^3.8.3",
|
"core-js": "^3.8.3",
|
||||||
"dotenv": "^16.0.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",
|
||||||
@ -5233,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",
|
||||||
@ -14370,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",
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"core-js": "^3.8.3",
|
"core-js": "^3.8.3",
|
||||||
"dotenv": "^16.0.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",
|
||||||
@ -32,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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
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
|
@ -281,7 +281,7 @@ export default {
|
|||||||
for (const allRes of allResults) {
|
for (const allRes of allResults) {
|
||||||
flag = true;
|
flag = true;
|
||||||
for(const res of this.results) {
|
for(const res of this.results) {
|
||||||
if (allRes['_id'] == res['_id']) {flag = false}
|
if (allRes['title'] == res['title']) {flag = false}
|
||||||
}
|
}
|
||||||
if (flag) {
|
if (flag) {
|
||||||
this.allResults.push(allRes)
|
this.allResults.push(allRes)
|
||||||
|
@ -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,6 +39,70 @@ 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') {
|
if (localStorage.getItem('db') == 'mongo') {
|
||||||
|
Loading…
Reference in New Issue
Block a user