Creazione tabella Product
This commit is contained in:
38
emails/registration_cnm/enUs/html.pug
Executable file
38
emails/registration_cnm/enUs/html.pug
Executable file
@@ -0,0 +1,38 @@
|
||||
p Welcome #{name} to the portal #{nomeapp}!
|
||||
p Your access data to remember are:
|
||||
span Username:
|
||||
strong #{username}<br>
|
||||
span Forgot your Password? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Find it here</a><br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p To confirm the registration click on the button, or click here #{strlinkreg}:
|
||||
div.divbtn <a href=#{strlinkreg} target="_blank">
|
||||
button.btn.btn-lg Verify Registration</a>
|
||||
|
||||
|
||||
p You could enter to the site and Login.
|
||||
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/registration_cnm/enUs/subject.pug
Executable file
1
emails/registration_cnm/enUs/subject.pug
Executable file
@@ -0,0 +1 @@
|
||||
=`Confirm Registration to ${nomeapp}`
|
||||
37
emails/registration_cnm/esEs/html.pug
Executable file
37
emails/registration_cnm/esEs/html.pug
Executable file
@@ -0,0 +1,37 @@
|
||||
p ¡Bienvenido #{name} al portal #{nomeapp}!
|
||||
p Sus datos de acceso a recordar son:
|
||||
Nombre Usuario:
|
||||
strong #{username}<br>
|
||||
span ¿Olvidaste tu contraseña? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Encuéntrelo aquí</a><br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p Para confirmar el registro haz clic en el botón:
|
||||
div.divbtn <a href=#{strlinkreg} target="_blank">
|
||||
button.btn.btn-lg Verificar registro</a>
|
||||
|
||||
p Así puedes entrar al sitio e iniciar la sesión.
|
||||
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/registration_cnm/esEs/subject.pug
Executable file
1
emails/registration_cnm/esEs/subject.pug
Executable file
@@ -0,0 +1 @@
|
||||
=`Confirmar registro a ${nomeapp}`
|
||||
37
emails/registration_cnm/it/html.pug
Executable file
37
emails/registration_cnm/it/html.pug
Executable file
@@ -0,0 +1,37 @@
|
||||
p Benvenuto #{name} nel portale di #{nomeapp}!
|
||||
p I tuoi dati di accesso da ricordare sono:
|
||||
span Username:
|
||||
strong #{username}<br>
|
||||
span hai dimenticato la Password? :
|
||||
strong <a href=#{forgetpwd} target="_blank">Trovala qui</a><br>
|
||||
span Email:
|
||||
strong #{emailto}<br>
|
||||
p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}:
|
||||
div.divbtn <a href=#{strlinkreg} target="_blank">
|
||||
button.btn.btn-lg Verifica Registrazione</a>
|
||||
|
||||
p Potrai cosi' accedere al sito digitando i tuoi dati di accesso.
|
||||
|
||||
|
||||
style(type="text/css").
|
||||
html, body {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.divbtn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.btn-lg {
|
||||
padding: 5px;
|
||||
margin: 5px;
|
||||
font-size: 26px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
background: #027be3 !important;
|
||||
border-radius: 28px;
|
||||
|
||||
}
|
||||
1
emails/registration_cnm/it/subject.pug
Executable file
1
emails/registration_cnm/it/subject.pug
Executable file
@@ -0,0 +1 @@
|
||||
=`Confermare la Registrazione a ${nomeapp}`
|
||||
13
emails/registration_cnm/it/textold.pug
Executable file
13
emails/registration_cnm/it/textold.pug
Executable file
@@ -0,0 +1,13 @@
|
||||
Benvenuto #{name} nel portale di #{nomeapp}!
|
||||
I tuoi dati di accesso da ricordare sono:
|
||||
Username: #{username}
|
||||
|
||||
hai dimenticato la Password?
|
||||
Trovala qui: #{forgetpwd}
|
||||
|
||||
Email #{emailto}
|
||||
|
||||
Per confermare la registrazione clicca su questo link:
|
||||
#{strlinkreg}
|
||||
|
||||
Potrai cosi' accedere al sito digitando i tuoi dati di accesso.
|
||||
@@ -151,14 +151,14 @@ if (process.env.NODE_ENV === 'production') {
|
||||
{
|
||||
idapp: '10',
|
||||
name: 'Comunità Nuovo Mondo',
|
||||
adminemail: 'comunitanuovomondo@gmail.com',
|
||||
adminemail: 'cnmrimini@gmail.com',
|
||||
manageremail: '',
|
||||
replyTo: '',
|
||||
host: 'https://comunitanuovomondo.app',
|
||||
portapp: '0',
|
||||
dir: '/var/www/comunitanuovomondo.app',
|
||||
email_from: 'comunitanuovomondo@gmail.com',
|
||||
email_pwd: 'c6f63e7aba9393c73f56e338a7fe5283a73949363662d26bd375dd05b6f6f37ebkw4vINQ0O/4d8JN71aNH3UsyndeFRgyyMvJMVl4iOk=',
|
||||
email_from: 'cnmrimini@gmail.com',
|
||||
email_pwd: '385e9bdfbfd8dd13505fbbc65ff6728b5fa836594054aadf9c7eb55b6b46100adUeazC8qEt2YEOkOFYWPvw==',
|
||||
telegram_key:'1202788747:AAErwzIsD7k-3Yj5AX6ci3p7ELMuyASq4vA',
|
||||
telegram_bot_name: 'comunitanuovomondo_bot',
|
||||
pathreg_add:'_cnm',
|
||||
|
||||
67
src/server/models/cart.js
Executable file
67
src/server/models/cart.js
Executable file
@@ -0,0 +1,67 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const CartSchema = new Schema({
|
||||
userId: { type: Schema.Types.ObjectId, ref: 'User' },
|
||||
totalQty: { type: Number, default: 0 },
|
||||
totalPrice: { type: Number, default: 0 },
|
||||
items: [{
|
||||
item: { type: Schema.Types.ObjectId, ref: 'Product' },
|
||||
quantity: { type: Number, default: 1 },
|
||||
price: { type: Number, default: 0 }
|
||||
}]
|
||||
});
|
||||
|
||||
module.exports.getCartByUserId = function (uid, callback) {
|
||||
let query = { userId: uid }
|
||||
Cart.find(query, callback)
|
||||
}
|
||||
|
||||
module.exports.getCartById = function (id, callback) {
|
||||
Cart.findById(id, callback)
|
||||
}
|
||||
|
||||
module.exports.updateCartByUserId = function (userId, newCart, callback) {
|
||||
let query = { userId: userId }
|
||||
Cart.find(query, function (err, c) {
|
||||
if (err) throw err
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
Cart.findOneAndUpdate(
|
||||
{ userId: userId },
|
||||
{
|
||||
$set: {
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
}
|
||||
},
|
||||
{ new: true },
|
||||
callback
|
||||
)
|
||||
} else {
|
||||
//no cart in database
|
||||
newCart.save(callback)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.updateCartByCartId = function (cartId, newCart, callback) {
|
||||
Cart.findById(
|
||||
{ _id: cartId },
|
||||
{
|
||||
$set: newCart
|
||||
},
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports.createCart = function (newCart, callback) {
|
||||
newCart.save(callback)
|
||||
}
|
||||
|
||||
module.exports = mongoose.model('Cart', CartSchema);
|
||||
30
src/server/models/category.js
Executable file
30
src/server/models/category.js
Executable file
@@ -0,0 +1,30 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const CategorySchema = new Schema({
|
||||
name: {
|
||||
type: String,
|
||||
unique: true,
|
||||
index: true,
|
||||
lowercase: true
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.getAllCategories = function (callback) {
|
||||
Category.find(callback)
|
||||
}
|
||||
|
||||
module.exports.getCategoryById = function (id, callback) {
|
||||
Category.findById(id, callback);
|
||||
}
|
||||
|
||||
module.exports = mongoose.model('Category', CategorySchema);
|
||||
115
src/server/models/product.js
Executable file
115
src/server/models/product.js
Executable file
@@ -0,0 +1,115 @@
|
||||
mongoose = require('mongoose');
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.level = "F";
|
||||
|
||||
|
||||
// Resolving error Unknown modifier: $pushAll
|
||||
mongoose.plugin(schema => {
|
||||
schema.options.usePushEach = true
|
||||
});
|
||||
|
||||
const productSchema = new Schema({
|
||||
idapp: {
|
||||
type: String,
|
||||
},
|
||||
idProducer: {
|
||||
type: String
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
},
|
||||
department: {
|
||||
type: String
|
||||
},
|
||||
category: {
|
||||
type: mongoose.Schema.Types.ObjectId, ref: 'Category'
|
||||
// type: String
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
},
|
||||
color: {
|
||||
type: String
|
||||
},
|
||||
size: {
|
||||
type: String
|
||||
},
|
||||
quantity: {
|
||||
type: Number
|
||||
},
|
||||
date: {
|
||||
type: Number
|
||||
},
|
||||
icon: {
|
||||
type: String,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
|
||||
var Product = module.exports = mongoose.model('Product', productSchema);
|
||||
|
||||
module.exports.getFieldsForSearch = function () {
|
||||
return [{field: 'name', type: tools.FieldType.string}]
|
||||
};
|
||||
|
||||
module.exports.executeQueryTable = function (idapp, params) {
|
||||
params.fieldsearch = this.getFieldsForSearch();
|
||||
return tools.executeQueryTable(this, idapp, params);
|
||||
};
|
||||
|
||||
module.exports.findAllIdApp = async function (idapp) {
|
||||
const myfind = { idapp };
|
||||
|
||||
return await Product.find(myfind);
|
||||
};
|
||||
|
||||
module.exports.getAllProducts = function (query, sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.getProductByDepartment = function (query,sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.getProductByCategory = function (query,sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.getProductByTitle = function (query,sort, callback) {
|
||||
Product.find(query, null, sort, callback)
|
||||
}
|
||||
|
||||
module.exports.filterProductByDepartment = function (department, callback) {
|
||||
let regexp = new RegExp(`${department}`, 'i')
|
||||
var query = { department: { $regex: regexp } };
|
||||
Product.find(query, callback)
|
||||
}
|
||||
|
||||
module.exports.filterProductByCategory = function (category, callback) {
|
||||
let regexp = new RegExp(`${category}`, 'i')
|
||||
var query = { category: { $regex: regexp } };
|
||||
Product.find(query, callback);
|
||||
}
|
||||
|
||||
module.exports.filterProductByTitle = function (title, callback) {
|
||||
let regexp = new RegExp(`${title}`, 'i')
|
||||
var query = { title: { $regex: regexp } };
|
||||
Product.find(query, callback);
|
||||
}
|
||||
|
||||
module.exports.getProductByID = function (id, callback) {
|
||||
Product.findById(id, callback);
|
||||
}
|
||||
|
||||
// const Product = mongoose.model('Product', ProductSchema);
|
||||
|
||||
// module.exports = { Product };
|
||||
@@ -165,6 +165,9 @@ const UserSchema = new mongoose.Schema({
|
||||
subaccount: {
|
||||
type: Boolean
|
||||
},
|
||||
cart: {
|
||||
type: Object
|
||||
},
|
||||
profile: {
|
||||
img: {
|
||||
type: String
|
||||
|
||||
40
src/server/models/variant.js
Normal file
40
src/server/models/variant.js
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
|
||||
var variantSchema = mongoose.Schema({
|
||||
productID: {
|
||||
type: String
|
||||
},
|
||||
imagePath: {
|
||||
type: String
|
||||
},
|
||||
color: {
|
||||
type: String
|
||||
},
|
||||
size: {
|
||||
type: String
|
||||
},
|
||||
quantity: {
|
||||
type: Number
|
||||
},
|
||||
title: {
|
||||
type: String
|
||||
},
|
||||
price: {
|
||||
type: Number
|
||||
}
|
||||
});
|
||||
|
||||
var Variant = module.exports = mongoose.model('Variant', variantSchema);
|
||||
|
||||
module.exports.getVariantByID = function(id, callback){
|
||||
Variant.findById(id, callback);
|
||||
}
|
||||
|
||||
module.exports.getVariantProductByID = function(id, callback){
|
||||
var query = {productID: id};
|
||||
Variant.find(query, callback);
|
||||
}
|
||||
module.exports.getAllVariants = function(callback){
|
||||
Variant.find(callback)
|
||||
}
|
||||
67
src/server/modules/Cart.js
Normal file
67
src/server/modules/Cart.js
Normal file
@@ -0,0 +1,67 @@
|
||||
const cartModel = require('../models/cart')
|
||||
|
||||
class Cart {
|
||||
constructor(oldCart) {
|
||||
this.items = oldCart.items || {};
|
||||
this.totalQty = oldCart.totalQty || 0;
|
||||
this.totalPrice = oldCart.totalPrice || 0;
|
||||
this.userId = oldCart.userId || "";
|
||||
}
|
||||
|
||||
add(item, id) {
|
||||
let storedItem = this.items[id];
|
||||
if (!storedItem) {
|
||||
storedItem = this.items[id] = { item: item, qty: 0, price: 0 };
|
||||
}
|
||||
storedItem.qty++;
|
||||
storedItem.price = parseFloat((storedItem.item.price * storedItem.qty).toFixed(2));
|
||||
this.items[id]=storedItem
|
||||
this.totalQty++;
|
||||
this.totalPrice += storedItem.item.price;
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
return this
|
||||
}
|
||||
|
||||
generateModel(){
|
||||
let newCart = new cartModel({
|
||||
items: this.items,
|
||||
totalQty: this.totalQty,
|
||||
totalPrice: this.totalPrice,
|
||||
userId: this.userId
|
||||
})
|
||||
return newCart
|
||||
}
|
||||
|
||||
decreaseQty(id) {
|
||||
this.items[id].qty--;
|
||||
this.items[id].price -= this.items[id].item.price;
|
||||
this.items[id].price = parseFloat(this.items[id].price.toFixed(2))
|
||||
this.totalQty--;
|
||||
this.totalPrice -= this.items[id].item.price
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
if (this.items[id].qty <= 0) {
|
||||
delete this.items[id];
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
increaseQty(id) {
|
||||
this.items[id].qty++;
|
||||
this.items[id].price += this.items[id].item.price;
|
||||
this.items[id].price = parseFloat(this.items[id].price.toFixed(2))
|
||||
this.totalQty++;
|
||||
this.totalPrice += this.items[id].item.price
|
||||
this.totalPrice = parseFloat(this.totalPrice.toFixed(2))
|
||||
return this
|
||||
}
|
||||
|
||||
generateArray() {
|
||||
let arr = [];
|
||||
for (let id in this.items) {
|
||||
arr.push(this.items[id])
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Cart
|
||||
10
src/server/modules/ErrorHandler.js
Normal file
10
src/server/modules/ErrorHandler.js
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
class TypedError extends Error{
|
||||
constructor(args,status,type,error){
|
||||
super(args)
|
||||
this.status=status
|
||||
this.type=type
|
||||
this.error = error
|
||||
}
|
||||
}
|
||||
module.exports=TypedError
|
||||
@@ -51,6 +51,7 @@ const { Settings } = require('../models/settings');
|
||||
const { SendMsg } = require('../models/sendmsg');
|
||||
const { Permission } = require('../models/permission');
|
||||
const { MsgTemplate } = require('../models/msg_template');
|
||||
const Product = require('../models/product');
|
||||
|
||||
|
||||
const tools = require('../tools/general');
|
||||
@@ -192,6 +193,8 @@ function getTableByTableName(tablename) {
|
||||
mytable = Booking;
|
||||
else if (tablename === 'operators')
|
||||
mytable = Operator;
|
||||
else if (tablename === 'products')
|
||||
mytable = Product;
|
||||
else if (tablename === 'sendmsgs')
|
||||
mytable = SendMsg;
|
||||
else if (tablename === 'wheres')
|
||||
|
||||
60
src/server/router/products_router.js
Executable file
60
src/server/router/products_router.js
Executable file
@@ -0,0 +1,60 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const tools = require('../tools/general');
|
||||
|
||||
var server_constants = require('../tools/server_constants');
|
||||
|
||||
var { Project } = require('../models/project');
|
||||
|
||||
var { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
var mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
const _ = require('lodash');
|
||||
|
||||
const { ObjectID } = require('mongodb');
|
||||
|
||||
const Product = require('../models/product');
|
||||
const Variant = require('../models/variant');
|
||||
|
||||
/*const Department = require('../models/Department')
|
||||
const Category = require('../models/Category')
|
||||
const TypedError = require('../modules/ErrorHandler')
|
||||
const paypal_config = require('../configs/paypal-config')
|
||||
const paypal = require('paypal-rest-sdk')
|
||||
*/
|
||||
|
||||
const CartClass = require('../modules/Cart')
|
||||
const Cart = require('../models/cart');
|
||||
|
||||
//GET /products
|
||||
router.get('/', async function (req, res, next) {
|
||||
const idapp = req.query.idapp;
|
||||
|
||||
var products = await Product.findAllIdApp(idapp);
|
||||
|
||||
if (products)
|
||||
res.send({ code: server_constants.RIS_CODE_OK, products });
|
||||
else
|
||||
res.status(400).send(e);
|
||||
|
||||
/*
|
||||
const { query, order } = tools.categorizeQueryString(req.query)
|
||||
Product.getAllProducts(query, order, function (e, products) {
|
||||
if (e) {
|
||||
e.status = 406; return next(e);
|
||||
}
|
||||
if (products.length < 1) {
|
||||
// return res.status(404).json({ message: "products not found" })
|
||||
return [];
|
||||
}
|
||||
res.json({ products: products })
|
||||
})
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@@ -27,6 +27,12 @@ const reg = require('../reg/registration');
|
||||
|
||||
const { authenticate } = require('../middleware/authenticate');
|
||||
|
||||
const Cart = require('../models/cart');
|
||||
const CartClass = require('../modules/Cart')
|
||||
const Product = require('../models/product')
|
||||
const Variant = require('../models/variant')
|
||||
const TypedError = require('../modules/ErrorHandler')
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const Subscription = mongoose.model('subscribers');
|
||||
|
||||
@@ -793,5 +799,140 @@ router.post('/dbop', authenticate, async (req, res) => {
|
||||
|
||||
});
|
||||
|
||||
//GET cart
|
||||
router.get('/:userId/cart', authenticate, function (req, res, next) {
|
||||
let userId = req.params.userId
|
||||
Cart.getCartByUserId(userId, function (err, cart) {
|
||||
if (err) return next(err)
|
||||
if (cart.length < 1) {
|
||||
let err = new TypedError('cart error', 404, 'not_found', { message: "create a cart first" })
|
||||
return next(err)
|
||||
}
|
||||
return res.json({ cart: cart[0] })
|
||||
})
|
||||
})
|
||||
|
||||
//POST cart
|
||||
router.post('/:userId/cart', authenticate, function (req, res, next) {
|
||||
let userId = req.params.userId
|
||||
let { productId, increase, decrease } = req.body
|
||||
|
||||
Cart.getCartByUserId(userId, function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c[0] || { userId })
|
||||
// no cart save empty cart to database then return response
|
||||
if (c.length < 1 && !productId) {
|
||||
return Cart.createCart(oldCart.generateModel(), function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
return res.status(201).json({ cart: resultCart })
|
||||
})
|
||||
}
|
||||
Product.findById(productId, function (e, product) {
|
||||
if (e) {
|
||||
e.status = 406;
|
||||
return next(e);
|
||||
}
|
||||
if (product) {
|
||||
if (decrease) {
|
||||
oldCart.decreaseQty(product.id);
|
||||
} else if (increase) {
|
||||
oldCart.increaseQty(product.id);
|
||||
} else {
|
||||
oldCart.add(product, product.id);
|
||||
}
|
||||
let newCart = oldCart.generateModel()
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
newCart,
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
return res.status(200).json({ cart: result })
|
||||
})
|
||||
} else {
|
||||
// apply variant
|
||||
Variant.getVariantByID(productId, function (e, variant) {
|
||||
if (e) {
|
||||
e.status = 406;
|
||||
return next(e);
|
||||
}
|
||||
if (variant) {
|
||||
Product.getProductByID(variant.productID, function (e, p) {
|
||||
let color = (variant.color) ? "- " + variant.color : "";
|
||||
let size = (variant.size) ? "- " + variant.size : "";
|
||||
variant.title = p.title + " " + color + size
|
||||
variant.price = p.price
|
||||
if (decrease) {
|
||||
oldCart.decreaseQty(variant.id);
|
||||
} else if (increase) {
|
||||
oldCart.increaseQty(variant.id);
|
||||
} else {
|
||||
oldCart.add(variant, variant.id);
|
||||
}
|
||||
let newCart = oldCart.generateModel()
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
newCart,
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
res.status(200).json({ cart: result })
|
||||
})
|
||||
})
|
||||
}
|
||||
// no product and no variant find
|
||||
else {
|
||||
let err = new TypedError('/cart', 400, 'invalid_field', {
|
||||
message: "invalid request body"
|
||||
})
|
||||
return next(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
//PUT cart
|
||||
router.put('/:userId/cart', authenticate, function (req, res, next) {
|
||||
let userId = req.params.userId
|
||||
let requestProduct = req.body
|
||||
let { productId, color, size } = requestProduct.product
|
||||
|
||||
Cart.getCartByUserId(userId, function (err, c) {
|
||||
if (err) return next(err)
|
||||
let oldCart = new CartClass(c[0] || {})
|
||||
Product.getProductByID(productId, function (err, p) {
|
||||
if (err) return next(err)
|
||||
let newCart = oldCart.add(p, productId, { color, size })
|
||||
|
||||
//exist cart in databse
|
||||
if (c.length > 0) {
|
||||
Cart.updateCartByUserId(
|
||||
userId,
|
||||
{
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
},
|
||||
function (err, result) {
|
||||
if (err) return next(err)
|
||||
res.json(result)
|
||||
})
|
||||
} else {
|
||||
//no cart in database
|
||||
newCart = new Cart({
|
||||
items: newCart.items,
|
||||
totalQty: newCart.totalQty,
|
||||
totalPrice: newCart.totalPrice,
|
||||
userId: userId
|
||||
})
|
||||
Cart.createCart(newCart, function (err, resultCart) {
|
||||
if (err) return next(err)
|
||||
res.status(201).json(resultCart)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -61,6 +61,7 @@ const projects_router = require('./router/projects_router');
|
||||
const users_router = require('./router/users_router');
|
||||
const site_router = require('./router/site_router');
|
||||
const admin_router = require('./router/admin_router');
|
||||
const products_router = require('./router/products_router');
|
||||
|
||||
|
||||
const { ListaIngresso } = require('./models/listaingresso');
|
||||
@@ -128,6 +129,7 @@ app.use('/projects', projects_router);
|
||||
app.use('/users', users_router);
|
||||
app.use('/site', site_router);
|
||||
app.use('/admin', admin_router);
|
||||
app.use('/products', products_router);
|
||||
|
||||
// catch 404 and forward to error handler
|
||||
// app.use(function (req, res, next) {
|
||||
|
||||
@@ -174,6 +174,7 @@ const Menu = {
|
||||
SI: emoji.get('thumbsup') + ' SI',
|
||||
NO: emoji.get('thumbsdown') + ' NO',
|
||||
ESCI_DA_CHAT: emoji.get('incoming_envelope') + ' Esci dalla Conversazione',
|
||||
NUOVOSITO: 'https://ayni.gifteconomy.app'
|
||||
},
|
||||
es: {
|
||||
ACCEDI: emo.PERSON + ' Entra',
|
||||
@@ -283,6 +284,15 @@ const MenuPerAdmin = {
|
||||
enUs: { menu: [[Menu.enUs.LAVAGNA, Menu.enUs.LINK_CONDIVIDERE], [Menu.enUs.ZOOM, Menu.enUs.ASSISTENZA], [Menu.LANG, Menu.ADMIN]] },
|
||||
};
|
||||
|
||||
const MenuRedirigi = {
|
||||
it: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
es: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
fr: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
si: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
pt: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
enUs: { menu: [[Menu.it.NUOVOSITO]] },
|
||||
};
|
||||
|
||||
const MenuLang = {
|
||||
it: { menu: [[Menu.LANG_IT, Menu.LANG_EN], [Menu.LANG_ES, Menu.LANG_FR], [Menu.LANG_SI, Menu.LANG_PT, Menu.it.INDIETRO]] },
|
||||
};
|
||||
@@ -1342,6 +1352,8 @@ class Telegram {
|
||||
|
||||
if (this.isSelMenu(msg, msg.text, 'LAVAGNA') || MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) {
|
||||
await this.menuLavagna(msg);
|
||||
}else if (msg.text === Menu.it.NUOVOSITO) {
|
||||
await this.sendMsg(msg.chat.id, Menu.it.NUOVOSITO);
|
||||
} else if (msg.text === Menu.MIANAVE || (cmd2 === strNave) || MsgBot.MIANAVE.find((rec) => msg.text.indexOf(rec) > -1)) {
|
||||
await this.menuNave(msg)
|
||||
} else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) {
|
||||
@@ -1576,7 +1588,7 @@ class Telegram {
|
||||
if (arrstringa.length > 1) {
|
||||
let last = arrstringa.slice(-1)[0];
|
||||
if (!isNaN(last)) {
|
||||
ind_order_to_check = last;
|
||||
// ind_order_to_check = last;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2350,10 +2362,17 @@ class Telegram {
|
||||
|
||||
async getKeyboard(id, menu, lang) {
|
||||
let keyb = MenuStandard;
|
||||
|
||||
if (this.idapp === tools.AYNI) {
|
||||
keyb = MenuRedirigi
|
||||
}
|
||||
// Check if you are Admin
|
||||
const ismanager = await User.isAdminByIdTeleg(this.idapp, id);
|
||||
if (ismanager && menu !== MenuChat)
|
||||
keyb = MenuPerAdmin;
|
||||
if (this.idapp === tools.AYNI) {
|
||||
keyb = MenuRedirigi
|
||||
}
|
||||
if (menu) {
|
||||
keyb = menu
|
||||
}
|
||||
|
||||
@@ -54,12 +54,12 @@ textlang = {
|
||||
"Effettuata una Nuova Registrazione": "Effettuata una Nuova Registrazione",
|
||||
"partecipanti": "partecipanti",
|
||||
'TESTO_ASSISTENZA': "<strong><a href=\"%s\">👉 Per entrare nel Sito AYNI</a></strong>\n\n" +
|
||||
"👉 <strong><a href=\"https://ayni.gifteconomy.app/requestresetpwd\">Hai dimenticato la password?</a></strong>\n\n" +
|
||||
"👉 Entra nel Canale d'Informazione per Importanti Avvisi!\n<strong><a href=\"%s\">Canale AYNI-BIBLIO</a></strong>\n\n" +
|
||||
"👉 <strong>Chat AYNI - EMPOWER</strong>: Entra ⛩ nella nostra Community chat\n%s\n\n" +
|
||||
"👉 <strong>PER AIUTO</strong>: Leggi le Domande più Frequenti:\n%s\n<b>Oppure chiedi prima al tuo Invitante!</b>\n\n" +
|
||||
"SOLO se non trovi la risposta che ti serve puoi accedere alla Chat di Supporto <strong>'AYNI - HELP'</strong>\n<strong>Da Lunedì al Venerdí (9:00 - 19:00)</strong>\n%s\n" +
|
||||
"1 - Fai la tua <strong>domanda</strong> e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto <strong>Esci dalla chat</strong>.\nPotrai rientrare ogni qualvolta ne avrai la necessità.",
|
||||
"👉 <strong><a href=\"https://ayni.gifteconomy.app/requestresetpwd\">Hai dimenticato la password?</a></strong>\n\n" +
|
||||
"👉 Entra nel Canale d'Informazione per Importanti Avvisi!\n<strong><a href=\"%s\">Canale AYNI-BIBLIO</a></strong>\n\n" +
|
||||
"👉 <strong>Chat AYNI - EMPOWER</strong>: Entra ⛩ nella nostra Community chat\n%s\n\n" +
|
||||
"👉 <strong>PER AIUTO</strong>: Leggi le Domande più Frequenti:\n%s\n<b>Oppure chiedi prima al tuo Invitante!</b>\n\n" +
|
||||
"SOLO se non trovi la risposta che ti serve puoi accedere alla Chat di Supporto <strong>'AYNI - HELP'</strong>\n<strong>Da Lunedì al Venerdí (9:00 - 19:00)</strong>\n%s\n" +
|
||||
"1 - Fai la tua <strong>domanda</strong> e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto <strong>Esci dalla chat</strong>.\nPotrai rientrare ogni qualvolta ne avrai la necessità.",
|
||||
'BENVENUTO': "Benvenuto",
|
||||
'TUE_NAVI': "Ecco le tue Navi programmate",
|
||||
'HAI_I_7_REQUISITI': 'PRIMI PASSI OK!\nHai i Primi 7 Requisiti per Entrare nella Lista d\'Imbarco!',
|
||||
@@ -125,13 +125,13 @@ textlang = {
|
||||
"Effettuata una Nuova Registrazione": "Izpelji novo Registracijo",
|
||||
"partecipanti": "Udeleženci",
|
||||
'TESTO_ASSISTENZA': "Za vstop na spletno stran:\n%s\n\n" +
|
||||
"Si pozabil geslo za vstop na stran?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Klepet AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Klepet AYNI - EMPOWER: Vstopi ⛩ v našo Skupnost klepet:\n%s\n\n" +
|
||||
"Canal News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Klepet za Pomoč in Suport: 'AYNI - HELP'\n%s\n" +
|
||||
"1 - Postavi svoje vprašanje in prosi za asistenco.\n2 - KO si sprejel pomoč, izstopi iz klepeta.\n " +
|
||||
"Vstopil boš lahko vedno, ko boš potreboval pomoč.",
|
||||
"Si pozabil geslo za vstop na stran?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Klepet AYNI BOT (questa):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Klepet AYNI - EMPOWER: Vstopi ⛩ v našo Skupnost klepet:\n%s\n\n" +
|
||||
"Canal News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Klepet za Pomoč in Suport: 'AYNI - HELP'\n%s\n" +
|
||||
"1 - Postavi svoje vprašanje in prosi za asistenco.\n2 - KO si sprejel pomoč, izstopi iz klepeta.\n " +
|
||||
"Vstopil boš lahko vedno, ko boš potreboval pomoč.",
|
||||
'BENVENUTO': "Dobrodošel",
|
||||
'TUE_NAVI': "Tvoje programirane Ladje",
|
||||
'HAI_I_7_REQUISITI': 'PRVI KORAKI OK!\nIzpolnjuješ Prvih 7 Zahtev za vstop na Listo d\'Vkrcanje!',
|
||||
@@ -194,11 +194,11 @@ textlang = {
|
||||
"Effettuata una Nuova Registrazione": "Se ha realizado un nuevo registro",
|
||||
"partecipanti": "participantes",
|
||||
'TESTO_ASSISTENZA': "Para entrar en el sitio de AYNI:\n%s\n\n" +
|
||||
"¿Olvidó su contraseña para acceder al sitio?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (este):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Entra en ⛩ en nuestra comunidad de chat:\n%s\n\n" +
|
||||
"Chat de ayuda y soporte: 'AYNI - HELP'\nDe lunes a viernes (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Haga su pregunta y pida ayuda.\n2 - Después de que consigas ayuda, sal de la sala de chat.\nPuedes volver cuando necesites ayuda..",
|
||||
"¿Olvidó su contraseña para acceder al sitio?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (este):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Entra en ⛩ en nuestra comunidad de chat:\n%s\n\n" +
|
||||
"Chat de ayuda y soporte: 'AYNI - HELP'\nDe lunes a viernes (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Haga su pregunta y pida ayuda.\n2 - Después de que consigas ayuda, sal de la sala de chat.\nPuedes volver cuando necesites ayuda..",
|
||||
'BENVENUTO': "Bienvenido",
|
||||
'TUE_NAVI': "Aquí están sus naves programadas",
|
||||
'HAI_I_7_REQUISITI': '¡LOS PRIMEROS PASOS ESTÁN BIEN!\nTiene los primeros 7 requisitos para entrar en la lista de embarque!',
|
||||
@@ -258,11 +258,11 @@ textlang = {
|
||||
enUs: {
|
||||
"partecipanti": "participants",
|
||||
'TESTO_ASSISTENZA': "To enter the AYNI Site:\n%s\n\nForgot your password to access the site?\n" +
|
||||
"https://ayni.gifteconomy.app/requestresetpwd\nChat AYNI BOT (this one):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Enter ⛩ into our chat community:\n%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Help and Support Chat: 'AYNI - HELP'.\nMonday to Friday (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Ask your question and ask for assistance.\n2 - After receiving help, exit the chat.\nYou can come back whenever you need help.",
|
||||
"https://ayni.gifteconomy.app/requestresetpwd\nChat AYNI BOT (this one):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Enter ⛩ into our chat community:\n%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Help and Support Chat: 'AYNI - HELP'.\nMonday to Friday (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Ask your question and ask for assistance.\n2 - After receiving help, exit the chat.\nYou can come back whenever you need help.",
|
||||
'BENVENUTO': "Welcome",
|
||||
'TUE_NAVI': "Here are your programmed ships",
|
||||
'HAI_I_7_REQUISITI': 'FIRST STEPS OK!\nYou have the First 7 Requirements to Enter the Boarding List!',
|
||||
@@ -325,12 +325,12 @@ textlang = {
|
||||
"Effettuata una Nuova Registrazione": "Un nouvel enregistrement a été effectué",
|
||||
"partecipanti": "participants",
|
||||
'TESTO_ASSISTENZA': "Pour entrer sur le site AYNI:\n%s\n\n" +
|
||||
"Vous avez oublié votre mot de passe pour accéder au site ?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (ce):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER : Entrez ⛩ dans notre Community chat:\n%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Chat d’Aide et de Support: 'AYNI - HELP'\nDu lundi au Vendredi (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Posez votre question et demandez d’être assisté.\n2 - Après avoir reçu l’aide, quittez le groupe.\nVous pourrez y entrer chaque fois qu’il vous sera nécessaire.",
|
||||
"Vous avez oublié votre mot de passe pour accéder au site ?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (ce):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER : Entrez ⛩ dans notre Community chat:\n%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Chat d’Aide et de Support: 'AYNI - HELP'\nDu lundi au Vendredi (9:00 - 19:00)\n%s\n" +
|
||||
"1 - Posez votre question et demandez d’être assisté.\n2 - Après avoir reçu l’aide, quittez le groupe.\nVous pourrez y entrer chaque fois qu’il vous sera nécessaire.",
|
||||
'BENVENUTO': "Bienvenue",
|
||||
'TUE_NAVI': "Voici vos navires programmés",
|
||||
'HAI_I_7_REQUISITI': 'PREMIÈRES ÉTAPES OK!\nvous avez les 7 premiers Requis pour Entrer dans la liste d\'embarquement!',
|
||||
@@ -393,12 +393,12 @@ textlang = {
|
||||
"Effettuata una Nuova Registrazione": "Foi efectuado um novo registo",
|
||||
"partecipanti": "participantes",
|
||||
'TESTO_ASSISTENZA': "Para entrar no site do AYNI:\n%s\n\n" +
|
||||
"Esqueceu sua senha para acessar o site?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (isto):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Entrar em ⛩ na nossa comunidade de chat:%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Chat de Ajuda e Suporte: 'AYNI - HELP'.\nDe segunda a Sexta (9:00 - 19:00 ITALY)\n%s\n" +
|
||||
"1 - Faça a sua pergunta e peça ajuda.\n2 - Depois de receber ajuda, saia do chat.\nPode voltar sempre que precisar de o fazer..",
|
||||
"Esqueceu sua senha para acessar o site?\nhttps://ayni.gifteconomy.app/requestresetpwd\n\n" +
|
||||
"Chat AYNI BOT (isto):\nhttps://t.me/notevoleaynibot\n\n" +
|
||||
"Chat AYNI - EMPOWER: Entrar em ⛩ na nossa comunidade de chat:%s\n\n" +
|
||||
"Canale News AYNI-BIBLIO:\n%s\n\n" +
|
||||
"Chat de Ajuda e Suporte: 'AYNI - HELP'.\nDe segunda a Sexta (9:00 - 19:00 ITALY)\n%s\n" +
|
||||
"1 - Faça a sua pergunta e peça ajuda.\n2 - Depois de receber ajuda, saia do chat.\nPode voltar sempre que precisar de o fazer..",
|
||||
'BENVENUTO': "Bem-vindo",
|
||||
'TUE_NAVI': "Aqui estão os seus navios programados",
|
||||
'HAI_I_7_REQUISITI': 'PRIMEIROS PASSOS OK!\nVocê tem os 7 primeiros requisitos para entrar na lista de embarque!',
|
||||
@@ -1569,8 +1569,7 @@ module.exports = {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
try {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
mkdirpath(path.dirname(dirPath));
|
||||
mkdirpath(dirPath);
|
||||
}
|
||||
@@ -1775,5 +1774,46 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
categorizeQueryString(queryObj) {
|
||||
let query = {}
|
||||
let order = {}
|
||||
//extract query, order, filter value
|
||||
for (const i in queryObj) {
|
||||
if (queryObj[i]) {
|
||||
// extract order
|
||||
if (i === 'order') {
|
||||
order['sort'] = queryObj[i]
|
||||
continue
|
||||
}
|
||||
// extract range
|
||||
if (i === 'range') {
|
||||
let range_arr = []
|
||||
let query_arr = []
|
||||
// multi ranges
|
||||
if (queryObj[i].constructor === Array) {
|
||||
for (const r of queryObj[i]) {
|
||||
range_arr = r.split('-')
|
||||
query_arr.push({
|
||||
price: { $gt: range_arr[0], $lt: range_arr[1] }
|
||||
})
|
||||
}
|
||||
}
|
||||
// one range
|
||||
if (queryObj[i].constructor === String) {
|
||||
range_arr = queryObj[i].split('-')
|
||||
query_arr.push({
|
||||
price: { $gt: range_arr[0], $lt: range_arr[1] }
|
||||
})
|
||||
}
|
||||
Object.assign(query, { $or: query_arr })
|
||||
delete query[i]
|
||||
continue
|
||||
}
|
||||
query[i] = queryObj[i]
|
||||
}
|
||||
}
|
||||
return { query, order }
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user