diff --git a/emails/registration_cnm/enUs/html.pug b/emails/registration_cnm/enUs/html.pug new file mode 100755 index 0000000..5dd333b --- /dev/null +++ b/emails/registration_cnm/enUs/html.pug @@ -0,0 +1,38 @@ +p Welcome #{name} to the portal #{nomeapp}! +p Your access data to remember are: +span Username:  + strong #{username}
+span Forgot your Password? :  + strong Find it here
+span Email:  + strong #{emailto}
+p To confirm the registration click on the button, or click here #{strlinkreg}: +div.divbtn + button.btn.btn-lg Verify Registration + + +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; + + } diff --git a/emails/registration_cnm/enUs/subject.pug b/emails/registration_cnm/enUs/subject.pug new file mode 100755 index 0000000..b65f1d4 --- /dev/null +++ b/emails/registration_cnm/enUs/subject.pug @@ -0,0 +1 @@ +=`Confirm Registration to ${nomeapp}` diff --git a/emails/registration_cnm/esEs/html.pug b/emails/registration_cnm/esEs/html.pug new file mode 100755 index 0000000..2ef9213 --- /dev/null +++ b/emails/registration_cnm/esEs/html.pug @@ -0,0 +1,37 @@ +p ¡Bienvenido #{name} al portal #{nomeapp}! +p Sus datos de acceso a recordar son: +Nombre Usuario:  + strong #{username}
+span ¿Olvidaste tu contraseña? :  + strong Encuéntrelo aquí
+span Email:  + strong #{emailto}
+p Para confirmar el registro haz clic en el botón: +div.divbtn + button.btn.btn-lg Verificar registro + +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; + + } diff --git a/emails/registration_cnm/esEs/subject.pug b/emails/registration_cnm/esEs/subject.pug new file mode 100755 index 0000000..0249b3d --- /dev/null +++ b/emails/registration_cnm/esEs/subject.pug @@ -0,0 +1 @@ +=`Confirmar registro a ${nomeapp}` diff --git a/emails/registration_cnm/it/html.pug b/emails/registration_cnm/it/html.pug new file mode 100755 index 0000000..c170004 --- /dev/null +++ b/emails/registration_cnm/it/html.pug @@ -0,0 +1,37 @@ +p Benvenuto #{name} nel portale di #{nomeapp}! +p I tuoi dati di accesso da ricordare sono: +span Username:  + strong #{username}
+span hai dimenticato la Password? :  + strong Trovala qui
+span Email:  + strong #{emailto}
+p Per confermare la registrazione clicca sul bottone, oppure qui: #{strlinkreg}: +div.divbtn + button.btn.btn-lg Verifica Registrazione + +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; + + } diff --git a/emails/registration_cnm/it/subject.pug b/emails/registration_cnm/it/subject.pug new file mode 100755 index 0000000..19c2e8a --- /dev/null +++ b/emails/registration_cnm/it/subject.pug @@ -0,0 +1 @@ +=`Confermare la Registrazione a ${nomeapp}` diff --git a/emails/registration_cnm/it/textold.pug b/emails/registration_cnm/it/textold.pug new file mode 100755 index 0000000..7c751a2 --- /dev/null +++ b/emails/registration_cnm/it/textold.pug @@ -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. diff --git a/src/server/config/config.js b/src/server/config/config.js index 9250c42..432d280 100755 --- a/src/server/config/config.js +++ b/src/server/config/config.js @@ -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', diff --git a/src/server/models/cart.js b/src/server/models/cart.js new file mode 100755 index 0000000..0ffe2d1 --- /dev/null +++ b/src/server/models/cart.js @@ -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); diff --git a/src/server/models/category.js b/src/server/models/category.js new file mode 100755 index 0000000..bbe85cd --- /dev/null +++ b/src/server/models/category.js @@ -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); diff --git a/src/server/models/product.js b/src/server/models/product.js new file mode 100755 index 0000000..36c9283 --- /dev/null +++ b/src/server/models/product.js @@ -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 }; diff --git a/src/server/models/user.js b/src/server/models/user.js index 429efbc..52990cb 100755 --- a/src/server/models/user.js +++ b/src/server/models/user.js @@ -165,6 +165,9 @@ const UserSchema = new mongoose.Schema({ subaccount: { type: Boolean }, + cart: { + type: Object + }, profile: { img: { type: String diff --git a/src/server/models/variant.js b/src/server/models/variant.js new file mode 100644 index 0000000..66b8739 --- /dev/null +++ b/src/server/models/variant.js @@ -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) +} \ No newline at end of file diff --git a/src/server/modules/Cart.js b/src/server/modules/Cart.js new file mode 100644 index 0000000..7fbc640 --- /dev/null +++ b/src/server/modules/Cart.js @@ -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 diff --git a/src/server/modules/ErrorHandler.js b/src/server/modules/ErrorHandler.js new file mode 100644 index 0000000..c584b72 --- /dev/null +++ b/src/server/modules/ErrorHandler.js @@ -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 \ No newline at end of file diff --git a/src/server/router/index_router.js b/src/server/router/index_router.js index 7cc8cf7..793b842 100755 --- a/src/server/router/index_router.js +++ b/src/server/router/index_router.js @@ -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') diff --git a/src/server/router/products_router.js b/src/server/router/products_router.js new file mode 100755 index 0000000..b9c4b18 --- /dev/null +++ b/src/server/router/products_router.js @@ -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; diff --git a/src/server/router/users_router.js b/src/server/router/users_router.js index c90d31d..29a83c6 100755 --- a/src/server/router/users_router.js +++ b/src/server/router/users_router.js @@ -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; diff --git a/src/server/server.js b/src/server/server.js index 10b81d0..9af8fd8 100755 --- a/src/server/server.js +++ b/src/server/server.js @@ -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) { diff --git a/src/server/telegram/telegrambot.js b/src/server/telegram/telegrambot.js index 3259cb0..52812a1 100755 --- a/src/server/telegram/telegrambot.js +++ b/src/server/telegram/telegrambot.js @@ -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 } diff --git a/src/server/tools/general.js b/src/server/tools/general.js index 39790aa..743fd51 100755 --- a/src/server/tools/general.js +++ b/src/server/tools/general.js @@ -54,12 +54,12 @@ textlang = { "Effettuata una Nuova Registrazione": "Effettuata una Nuova Registrazione", "partecipanti": "partecipanti", 'TESTO_ASSISTENZA': "👉 Per entrare nel Sito AYNI\n\n" + - "👉 Hai dimenticato la password?\n\n" + - "👉 Entra nel Canale d'Informazione per Importanti Avvisi!\nCanale AYNI-BIBLIO\n\n" + - "👉 Chat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat\n%s\n\n" + - "👉 PER AIUTO: Leggi le Domande più Frequenti:\n%s\nOppure chiedi prima al tuo Invitante!\n\n" + - "SOLO se non trovi la risposta che ti serve puoi accedere alla Chat di Supporto 'AYNI - HELP'\nDa Lunedì al Venerdí (9:00 - 19:00)\n%s\n" + - "1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto Esci dalla chat.\nPotrai rientrare ogni qualvolta ne avrai la necessità.", + "👉 Hai dimenticato la password?\n\n" + + "👉 Entra nel Canale d'Informazione per Importanti Avvisi!\nCanale AYNI-BIBLIO\n\n" + + "👉 Chat AYNI - EMPOWER: Entra ⛩ nella nostra Community chat\n%s\n\n" + + "👉 PER AIUTO: Leggi le Domande più Frequenti:\n%s\nOppure chiedi prima al tuo Invitante!\n\n" + + "SOLO se non trovi la risposta che ti serve puoi accedere alla Chat di Supporto 'AYNI - HELP'\nDa Lunedì al Venerdí (9:00 - 19:00)\n%s\n" + + "1 - Fai la tua domanda e chiedi assistenza.\n2 - Dopo aver ricevuto aiuto Esci dalla chat.\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 } + }, + };