- Iscrizione Conacreis
- Ordini - Carrello
This commit is contained in:
@@ -10,7 +10,6 @@ const { ObjectID } = require('mongodb');
|
||||
|
||||
const tools = require('../../tools/general');
|
||||
|
||||
const telegrambot = require('../../telegram/telegrambot');
|
||||
|
||||
module.exports = {
|
||||
doOtherThingsAfterDeleted: async function (tablename, rec, notifBot, req) {
|
||||
|
||||
@@ -19,9 +19,9 @@ const sendNotif = async (res, idapp, user, recbooking) => {
|
||||
|
||||
// Send Email
|
||||
if (recbooking.booked)
|
||||
return await sendemail.sendEmail_Booking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
return sendemail.sendEmail_Booking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
else
|
||||
return await sendemail.sendEmail_CancelBooking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
return sendemail.sendEmail_CancelBooking(res, user.lang, user.email, user, idapp, recbooking);
|
||||
};
|
||||
|
||||
router.post('/', authenticate, (req, res) => {
|
||||
@@ -51,7 +51,7 @@ router.post('/', authenticate, (req, res) => {
|
||||
// tools.mylog('booking:', booking);
|
||||
// tools.mylog('already exist');
|
||||
sendNotif(res, myrec.idapp, req.user, myrec);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: id_bookedevent });
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id });
|
||||
});
|
||||
} else {
|
||||
// save to database a new record
|
||||
@@ -63,11 +63,14 @@ router.post('/', authenticate, (req, res) => {
|
||||
Booking.findById(idobj)
|
||||
.then((recbooking) => {
|
||||
sendNotif(res, myrec.idapp, req.user, writeresult);
|
||||
res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: writeresult._id });
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, msg: '', id: writeresult._id });
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.error('Error', e);
|
||||
res.status(400).send();
|
||||
});
|
||||
});
|
||||
|
||||
router.delete('/:id/:notify/:idapp', authenticate, (req, res) => {
|
||||
|
||||
@@ -178,8 +178,10 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
const user = req.user;
|
||||
let status = req.body.status;
|
||||
|
||||
|
||||
const mycart = await Cart.getCartByUserId(userId, idapp);
|
||||
const numorder = await OrdersCart.getNewNumOrder(userId, idapp);
|
||||
let statusOrderCart = await OrdersCart.getStatusCartByUserId(userId, idapp, numorder);
|
||||
|
||||
try {
|
||||
if (!!mycart) {
|
||||
@@ -205,7 +207,7 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
const myris = ris;
|
||||
// Cancella il Cart appena salvato in OrdersCart
|
||||
|
||||
Cart.deleteCartByCartId(mycart.id)
|
||||
return Cart.deleteCartByCartId(mycart.id)
|
||||
.then((ris) => {
|
||||
|
||||
const orders = OrdersCart.getOrdersCartByUserId(userId, idapp, numorder)
|
||||
@@ -216,7 +218,7 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
return res.send({
|
||||
code: server_constants.RIS_CODE_OK,
|
||||
status: myris.status,
|
||||
orders: orders[0]
|
||||
orders: orders
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -241,7 +243,70 @@ router.post('/:userId/cartstatus', authenticate, async function (req, res, next)
|
||||
|
||||
}
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, status: statusOrderCart });
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
//POST cart
|
||||
router.post('/:userId/orderstatus', authenticate, async function (req, res, next) {
|
||||
let idapp = req.body.idapp;
|
||||
let userId = req.params.userId;
|
||||
let order_id = req.body.order_id;
|
||||
const user = req.user;
|
||||
let status = req.body.status;
|
||||
|
||||
const orderCart = await OrdersCart.find({ idapp, _id: order_id });
|
||||
|
||||
if ((userId !== String(req.user._id)) && !User.isManager(req.user.perm)) {
|
||||
// I'm trying to write something not mine!
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_TODO_CREATING_NOTMYUSER });
|
||||
}
|
||||
|
||||
try {
|
||||
if (!!orderCart) {
|
||||
|
||||
let fields_to_update = { status };
|
||||
|
||||
if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
fields_to_update = {
|
||||
status,
|
||||
completed_at: new Date()
|
||||
}
|
||||
}
|
||||
|
||||
await OrdersCart.findOneAndUpdate({ _id: order_id }, { $set: fields_to_update }
|
||||
, { new: false })
|
||||
.then((ris) => {
|
||||
|
||||
if (ris) {
|
||||
|
||||
let ordertype = '';
|
||||
|
||||
if (status === shared_consts.OrderStatus.ORDER_CONFIRMED) {
|
||||
ordertype = 'order_confirmed';
|
||||
} else if (status === shared_consts.OrderStatus.RECEIVED) {
|
||||
ordertype = 'order_completed';
|
||||
} else if (status === shared_consts.OrderStatus.CANCELED) {
|
||||
ordertype = 'order_canceled';
|
||||
}
|
||||
|
||||
if (ordertype !== '') {
|
||||
sendemail.sendEmail_Order(user.lang, idapp, orderCart[0], user, ordertype)
|
||||
.then((ris) => {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
return res.send({ code: server_constants.RIS_CODE_OK, status });
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
return res.send({ code: server_constants.RIS_CODE_ERR, status: 0 });
|
||||
|
||||
@@ -58,6 +58,8 @@ const OrdersCart = require('../models/orderscart');
|
||||
const Storehouse = require('../models/storehouse');
|
||||
const Department = require('../models/department');
|
||||
const ShareWithUs = require('../models/sharewithus');
|
||||
const Site = require('../models/site');
|
||||
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
||||
const Group = require('../models/group');
|
||||
const { Todo } = require('../models/todo');
|
||||
const Hours = require('../models/hours');
|
||||
@@ -210,6 +212,10 @@ function getTableByTableName(tablename) {
|
||||
mytable = Department;
|
||||
else if (tablename === 'sharewithus')
|
||||
mytable = ShareWithUs;
|
||||
else if (tablename === 'sites')
|
||||
mytable = Site;
|
||||
else if (tablename === 'iscritticonacreis')
|
||||
mytable = IscrittiConacreis;
|
||||
else if (tablename === 'groups')
|
||||
mytable = Group;
|
||||
else if (tablename === 'todos')
|
||||
@@ -340,6 +346,21 @@ router.post('/gettable', authenticate, (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
router.post('/getpage', async (req, res) => {
|
||||
const params = req.body;
|
||||
const idapp = req.body.idapp;
|
||||
const mypath = params.path;
|
||||
|
||||
return MyPage.findOne({ idapp, path: mypath })
|
||||
.then((ris) => {
|
||||
return res.send({ mypage: ris });
|
||||
}).catch((e) => {
|
||||
console.log(e.message);
|
||||
res.status(400).send(e);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
router.patch('/setlang', authenticate, async (req, res) => {
|
||||
const username = req.body.data.username;
|
||||
@@ -381,7 +402,7 @@ router.patch('/chval', authenticate, async (req, res) => {
|
||||
// tools.mylogshow('PATCH CHVAL: ', id, fieldsvalue);
|
||||
|
||||
// If I change my record...
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isTraduttrici(req.user.perm) && !User.isTutor(req.user.perm)) && (req.user._id.toString() !== id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
||||
if ((!User.isAdmin(req.user.perm) && !User.isManager(req.user.perm) && !User.isEditor(req.user.perm) && !User.isTutor(req.user.perm)) && (req.user._id.toString() !== id) && !tools.ModificheConsentite(mydata.table, fieldsvalue)) {
|
||||
// If without permissions, exit
|
||||
return res.status(404).send({ code: server_constants.RIS_CODE_ERR_UNAUTHORIZED, msg: '' });
|
||||
}
|
||||
@@ -1138,7 +1159,7 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
|
||||
let newstosent = Promise.resolve([]);
|
||||
let mailinglist = Promise.resolve([]);
|
||||
let mypage = MyPage.findAllIdApp(idapp);
|
||||
let mypage = MyPage.findOnlyStruttRec(idapp);
|
||||
let calzoom = CalZoom.findAllIdApp(idapp);
|
||||
let gallery = Gallery.findAllIdApp(idapp);
|
||||
let producers = Producer.findAllIdApp(idapp);
|
||||
@@ -1157,7 +1178,12 @@ router.get('/loadsite/:userId/:idapp/:sall', authenticate_noerror, (req, res) =>
|
||||
if (req.user) {
|
||||
calcstat = User.calculateStat(idapp, req.user.username);
|
||||
cart = Cart.getCartByUserId(req.user.id, idapp);
|
||||
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
||||
if (User.isManager(req.user.perm)) {
|
||||
// Prende Tutti gli Ordini !
|
||||
orderscart = OrdersCart.getOrdersCartByUserId("ALL", idapp, 0);
|
||||
} else {
|
||||
orderscart = OrdersCart.getOrdersCartByUserId(req.user.id, idapp, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
82
src/server/router/iscrittiConacreis_router.js
Executable file
82
src/server/router/iscrittiConacreis_router.js
Executable file
@@ -0,0 +1,82 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const IscrittiConacreis = require('../models/iscrittiConacreis');
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const sendemail = require('../sendemail');
|
||||
|
||||
const { Settings } = require('../models/settings');
|
||||
|
||||
const tools = require('../tools/general');
|
||||
const shared_consts = require('../tools/shared_nodejs');
|
||||
|
||||
const server_constants = require('../tools/server_constants');
|
||||
|
||||
const telegrambot = require('../telegram/telegrambot');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
|
||||
// POST /iscritti_conacreis
|
||||
router.post('/', async (req, res) => {
|
||||
tools.mylog("POST /iscritti_conacreis");
|
||||
const body = _.pick(req.body, ['idapp', 'userId', 'name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on', 'iscrizione_compilata', 'annoTesseramento', 'note', 'accetta_carta_costituzionale_on', 'terms']);
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const iscritti = new IscrittiConacreis(body);
|
||||
iscritti.ipaddr = tools.getiPAddressUser(req);
|
||||
iscritti.lang = req.locale;
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + iscritti.lang, "IDAPP", iscritti.idapp);
|
||||
|
||||
if (!tools.isAlphaNumeric(body.name)) {
|
||||
await tools.snooze(5000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tools.blockwords(body.email) || tools.blockwords(body.name) || tools.blockwords(body.surname)) {
|
||||
// tools.writeIPToBan(iscritti.ipaddr + ': [' + iscritti.username + '] ' + iscritti.name + ' ' + iscritti.surname);
|
||||
await tools.snooze(5000);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
iscritti.dateofreg = new Date();
|
||||
|
||||
// Controlla se anche l'ultimo record era dallo stesso IP:
|
||||
const lastrec = await IscrittiConacreis.getLastRec(body.idapp);
|
||||
if (!!lastrec) {
|
||||
if (process.env.LOCALE !== "1") {
|
||||
if (lastrec.ipaddr === iscritti.ipaddr) {
|
||||
// Se l'ha fatto troppo ravvicinato
|
||||
if (lastrec.date_reg) {
|
||||
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
|
||||
if (ris) {
|
||||
tools.writeIPToBan(iscritti.ipaddr + ': ' + iscritti.name + ' ' + iscritti.surname);
|
||||
await tools.snooze(10000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await iscritti.save()
|
||||
.then(async () => {
|
||||
await sendemail.sendEmail_IscrizioneConacreis(iscritti.lang, iscritti.email, iscritti, iscritti.idapp);
|
||||
// }
|
||||
return res.status(200).send();
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@@ -121,6 +121,8 @@ async function SendMsgToParam(idapp, params) {
|
||||
invia = user.profile.socio;
|
||||
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_SOCIO_RESIDENTE) {
|
||||
invia = user.profile.socioresidente;
|
||||
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_SOCIO_RESIDENTE) {
|
||||
invia = user.profile.consiglio;
|
||||
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_NON_SOCI) {
|
||||
invia = !user.profile.socio;
|
||||
}else if (params.typemsg === shared_consts.TypeMsg.SEND_TO_PAOLO) {
|
||||
|
||||
@@ -288,6 +288,95 @@ router.post('/', async (req, res) => {
|
||||
return true;
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
// POST /users/iscriviti_conacreis
|
||||
router.post('/iscriviti_conacreis', async (req, res) => {
|
||||
tools.mylog("POST /users");
|
||||
const body = _.pick(req.body, ['name', 'surname', 'email', 'fiscalcode', 'residency_address', 'residency_city', 'residency_province', 'residency_country', 'residency_zipcode', 'dateofbirth', 'cell_phone', 'newsletter_on']);
|
||||
body.email = body.email.toLowerCase();
|
||||
|
||||
const user = new User(body);
|
||||
user.ipaddr = tools.getiPAddressUser(req);
|
||||
|
||||
// tools.mylog("LANG PASSATO = " + user.lang, "IDAPP", user.idapp);
|
||||
|
||||
if (!tools.isAlphaNumeric(body.name)) {
|
||||
await tools.snooze(5000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_USERNAME_NOT_VALID, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (tools.blockwords(body.email) || tools.blockwords(body.name) || tools.blockwords(body.surname)) {
|
||||
// tools.writeIPToBan(user.ipaddr + ': [' + user.username + '] ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(5000);
|
||||
return res.status(404).send();
|
||||
}
|
||||
|
||||
|
||||
user.date_reg = new Date();
|
||||
|
||||
// Controlla se anche l'ultimo record era dallo stesso IP:
|
||||
const lastrec = await User.getLastRec(body.idapp);
|
||||
if (!!lastrec) {
|
||||
if (process.env.LOCALE !== "1") {
|
||||
if (lastrec.ipaddr === user.ipaddr) {
|
||||
// Se l'ha fatto troppo ravvicinato
|
||||
if (lastrec.date_reg) {
|
||||
let ris = tools.isdiffSecDateLess(lastrec.date_reg, 120);
|
||||
if (ris) {
|
||||
tools.writeIPToBan(user.ipaddr + ': ' + user.name + ' ' + user.surname);
|
||||
await tools.snooze(10000);
|
||||
res.status(400).send({ code: server_constants.RIS_CODE_BANIP, msg: '' });
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await user.save()
|
||||
.then(async () => {
|
||||
return await User.findByUsername(user.idapp, user.username, false)
|
||||
.then((usertrovato) => {
|
||||
|
||||
// tools.mylog("TROVATO USERNAME ? ", user.username, usertrovato);
|
||||
if (usertrovato !== null) {
|
||||
return user.generateAuthToken(req);
|
||||
} else {
|
||||
res.status(400).send();
|
||||
return 0;
|
||||
}
|
||||
})
|
||||
.then(async (token) => {
|
||||
// tools.mylog("passo il TOKEN: ", token);
|
||||
|
||||
if (recextra) {
|
||||
recextra.registered = true;
|
||||
recextra.username = user.username;
|
||||
await recextra.save();
|
||||
|
||||
// await User.fixUsername(user.idapp, user.ind_order, user.username);
|
||||
}
|
||||
return token;
|
||||
})
|
||||
.then(async (token) => {
|
||||
|
||||
// tools.mylog("LINKREG = " + user.linkreg);
|
||||
// Invia un'email all'utente
|
||||
// tools.mylog('process.env.TESTING_ON', process.env.TESTING_ON);
|
||||
console.log('res.locale', res.locale);
|
||||
// if (!tools.testing()) {
|
||||
await sendemail.sendEmail_Registration(user.lang, user.email, user, user.idapp, user.linkreg);
|
||||
// }
|
||||
res.header('x-auth', token).send(user);
|
||||
return true;
|
||||
});
|
||||
}).catch((e) => {
|
||||
console.error(e.message);
|
||||
res.status(400).send(e);
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user