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',
|
idapp: '10',
|
||||||
name: 'Comunità Nuovo Mondo',
|
name: 'Comunità Nuovo Mondo',
|
||||||
adminemail: 'comunitanuovomondo@gmail.com',
|
adminemail: 'cnmrimini@gmail.com',
|
||||||
manageremail: '',
|
manageremail: '',
|
||||||
replyTo: '',
|
replyTo: '',
|
||||||
host: 'https://comunitanuovomondo.app',
|
host: 'https://comunitanuovomondo.app',
|
||||||
portapp: '0',
|
portapp: '0',
|
||||||
dir: '/var/www/comunitanuovomondo.app',
|
dir: '/var/www/comunitanuovomondo.app',
|
||||||
email_from: 'comunitanuovomondo@gmail.com',
|
email_from: 'cnmrimini@gmail.com',
|
||||||
email_pwd: 'c6f63e7aba9393c73f56e338a7fe5283a73949363662d26bd375dd05b6f6f37ebkw4vINQ0O/4d8JN71aNH3UsyndeFRgyyMvJMVl4iOk=',
|
email_pwd: '385e9bdfbfd8dd13505fbbc65ff6728b5fa836594054aadf9c7eb55b6b46100adUeazC8qEt2YEOkOFYWPvw==',
|
||||||
telegram_key:'1202788747:AAErwzIsD7k-3Yj5AX6ci3p7ELMuyASq4vA',
|
telegram_key:'1202788747:AAErwzIsD7k-3Yj5AX6ci3p7ELMuyASq4vA',
|
||||||
telegram_bot_name: 'comunitanuovomondo_bot',
|
telegram_bot_name: 'comunitanuovomondo_bot',
|
||||||
pathreg_add:'_cnm',
|
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: {
|
subaccount: {
|
||||||
type: Boolean
|
type: Boolean
|
||||||
},
|
},
|
||||||
|
cart: {
|
||||||
|
type: Object
|
||||||
|
},
|
||||||
profile: {
|
profile: {
|
||||||
img: {
|
img: {
|
||||||
type: String
|
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 { SendMsg } = require('../models/sendmsg');
|
||||||
const { Permission } = require('../models/permission');
|
const { Permission } = require('../models/permission');
|
||||||
const { MsgTemplate } = require('../models/msg_template');
|
const { MsgTemplate } = require('../models/msg_template');
|
||||||
|
const Product = require('../models/product');
|
||||||
|
|
||||||
|
|
||||||
const tools = require('../tools/general');
|
const tools = require('../tools/general');
|
||||||
@@ -192,6 +193,8 @@ function getTableByTableName(tablename) {
|
|||||||
mytable = Booking;
|
mytable = Booking;
|
||||||
else if (tablename === 'operators')
|
else if (tablename === 'operators')
|
||||||
mytable = Operator;
|
mytable = Operator;
|
||||||
|
else if (tablename === 'products')
|
||||||
|
mytable = Product;
|
||||||
else if (tablename === 'sendmsgs')
|
else if (tablename === 'sendmsgs')
|
||||||
mytable = SendMsg;
|
mytable = SendMsg;
|
||||||
else if (tablename === 'wheres')
|
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 { 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 mongoose = require('mongoose');
|
||||||
const Subscription = mongoose.model('subscribers');
|
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;
|
module.exports = router;
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ const projects_router = require('./router/projects_router');
|
|||||||
const users_router = require('./router/users_router');
|
const users_router = require('./router/users_router');
|
||||||
const site_router = require('./router/site_router');
|
const site_router = require('./router/site_router');
|
||||||
const admin_router = require('./router/admin_router');
|
const admin_router = require('./router/admin_router');
|
||||||
|
const products_router = require('./router/products_router');
|
||||||
|
|
||||||
|
|
||||||
const { ListaIngresso } = require('./models/listaingresso');
|
const { ListaIngresso } = require('./models/listaingresso');
|
||||||
@@ -128,6 +129,7 @@ app.use('/projects', projects_router);
|
|||||||
app.use('/users', users_router);
|
app.use('/users', users_router);
|
||||||
app.use('/site', site_router);
|
app.use('/site', site_router);
|
||||||
app.use('/admin', admin_router);
|
app.use('/admin', admin_router);
|
||||||
|
app.use('/products', products_router);
|
||||||
|
|
||||||
// catch 404 and forward to error handler
|
// catch 404 and forward to error handler
|
||||||
// app.use(function (req, res, next) {
|
// app.use(function (req, res, next) {
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ const Menu = {
|
|||||||
SI: emoji.get('thumbsup') + ' SI',
|
SI: emoji.get('thumbsup') + ' SI',
|
||||||
NO: emoji.get('thumbsdown') + ' NO',
|
NO: emoji.get('thumbsdown') + ' NO',
|
||||||
ESCI_DA_CHAT: emoji.get('incoming_envelope') + ' Esci dalla Conversazione',
|
ESCI_DA_CHAT: emoji.get('incoming_envelope') + ' Esci dalla Conversazione',
|
||||||
|
NUOVOSITO: 'https://ayni.gifteconomy.app'
|
||||||
},
|
},
|
||||||
es: {
|
es: {
|
||||||
ACCEDI: emo.PERSON + ' Entra',
|
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]] },
|
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 = {
|
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]] },
|
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)) {
|
if (this.isSelMenu(msg, msg.text, 'LAVAGNA') || MsgBot.LAVAGNA.find((rec) => msg.text.indexOf(rec) > -1)) {
|
||||||
await this.menuLavagna(msg);
|
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)) {
|
} else if (msg.text === Menu.MIANAVE || (cmd2 === strNave) || MsgBot.MIANAVE.find((rec) => msg.text.indexOf(rec) > -1)) {
|
||||||
await this.menuNave(msg)
|
await this.menuNave(msg)
|
||||||
} else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) {
|
} else if (this.isSelMenu(msg, msg.text, 'ACCEDI')) {
|
||||||
@@ -1576,7 +1588,7 @@ class Telegram {
|
|||||||
if (arrstringa.length > 1) {
|
if (arrstringa.length > 1) {
|
||||||
let last = arrstringa.slice(-1)[0];
|
let last = arrstringa.slice(-1)[0];
|
||||||
if (!isNaN(last)) {
|
if (!isNaN(last)) {
|
||||||
ind_order_to_check = last;
|
// ind_order_to_check = last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2350,10 +2362,17 @@ class Telegram {
|
|||||||
|
|
||||||
async getKeyboard(id, menu, lang) {
|
async getKeyboard(id, menu, lang) {
|
||||||
let keyb = MenuStandard;
|
let keyb = MenuStandard;
|
||||||
|
|
||||||
|
if (this.idapp === tools.AYNI) {
|
||||||
|
keyb = MenuRedirigi
|
||||||
|
}
|
||||||
// Check if you are Admin
|
// Check if you are Admin
|
||||||
const ismanager = await User.isAdminByIdTeleg(this.idapp, id);
|
const ismanager = await User.isAdminByIdTeleg(this.idapp, id);
|
||||||
if (ismanager && menu !== MenuChat)
|
if (ismanager && menu !== MenuChat)
|
||||||
keyb = MenuPerAdmin;
|
keyb = MenuPerAdmin;
|
||||||
|
if (this.idapp === tools.AYNI) {
|
||||||
|
keyb = MenuRedirigi
|
||||||
|
}
|
||||||
if (menu) {
|
if (menu) {
|
||||||
keyb = menu
|
keyb = menu
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1569,8 +1569,7 @@ module.exports = {
|
|||||||
if (!fs.existsSync(dirPath)) {
|
if (!fs.existsSync(dirPath)) {
|
||||||
try {
|
try {
|
||||||
fs.mkdirSync(dirPath, { recursive: true });
|
fs.mkdirSync(dirPath, { recursive: true });
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
mkdirpath(path.dirname(dirPath));
|
mkdirpath(path.dirname(dirPath));
|
||||||
mkdirpath(dirPath);
|
mkdirpath(dirPath);
|
||||||
}
|
}
|
||||||
@@ -1775,5 +1774,46 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
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