Lista Città (prese dal server: pickup)
This commit is contained in:
@@ -1,32 +1,57 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const mongoose = require('mongoose').set('debug', false)
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
const cfgserver = mongoose.model('cfgserver');
|
||||
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
const {City} = require('../models/city');
|
||||
|
||||
var {authenticate} = require('../middleware/authenticate');
|
||||
|
||||
router.post('/updateval', authenticate, async (req, res) => {
|
||||
console.log('/updateval', req.body.pairval);
|
||||
idapp = req.body.idapp;
|
||||
pair = req.body.pairval;
|
||||
|
||||
return await cfgserver.findOneAndUpdate({ chiave: pair.chiave, idapp, userId: pair.userId }, { $set: pair }, { new: false })
|
||||
.then((item) => {
|
||||
// cfgserver.find({ chiave: pair.chiave }, (err, item) => {
|
||||
if (!!item) {
|
||||
res.status(200).send();
|
||||
} else {
|
||||
res.status(400).send();
|
||||
}
|
||||
}).catch(err => {
|
||||
return await cfgserver.findOneAndUpdate(
|
||||
{chiave: pair.chiave, idapp, userId: pair.userId}, {$set: pair},
|
||||
{new: false}).then((item) => {
|
||||
// cfgserver.find({ chiave: pair.chiave }, (err, item) => {
|
||||
if (!!item) {
|
||||
res.status(200).send();
|
||||
} else {
|
||||
res.status(400).send();
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log('ERR:', err);
|
||||
res.status(400).send();
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
router.post('/import', authenticate, async (req, res) => {
|
||||
const cmd = req.body.cmd;
|
||||
const data = [];
|
||||
|
||||
try {
|
||||
const liste = require('../data/liste');
|
||||
|
||||
if (cmd === shared_consts.Cmd.CITIES_SERVER) {
|
||||
return City.insertMany(liste.Comuni).then((ris) => {
|
||||
return res.status(200).send(true);
|
||||
});
|
||||
|
||||
}
|
||||
}catch (e) {
|
||||
console.error('e', e);
|
||||
res.status(400).send();
|
||||
}
|
||||
|
||||
res.status(400).send();
|
||||
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user