diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..6496d37 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: node_js +node_js: + - "stable" +cache: npm + +install: + - npm ci + +script: + - CI='' npm run + +deploy: + provider: heroku + api_key: $HEROKU_API_KEY + app: e-commerce-uwunsaac-backend + skip-cleanup: true diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..28a51d5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "compile-hero.disable-compile-files-on-did-save-code": false +} \ No newline at end of file diff --git a/README.md b/README.md index 7253c8c..e464b8a 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,7 @@ -# Full stack ecommerce online store application +# Aplicación fullstack de un catálogo para venta de productos online -#### front-end codes [click here](https://github.com/levelopers/Ecommerce-Reactjs) +#### Código de front-end [aquí](https://github.com/UwUnsaac/Ecommerce-Reactjs) -#### api documentation: [swaggerHub](https://app.swaggerhub.com/apis-docs/levelopers2/Ecommerce/1.0.0) - -#### populate data: run `node ./seed` (make sure you fill up `mongo-config` file with mongodb url) - - - -
- data model -

- -![react-native-store relational model diagram](https://user-images.githubusercontent.com/38830527/92665263-1c4cb880-f2d4-11ea-85a4-201c41517123.png) - -

-
+#### Llenado de datos base: run `node ./seed` (Asegúrese de llenar de manera correcta el archivo `mongo-config` con el enlace correspondiente a su base de datos) diff --git a/configs/dist/mongo-config.dev.js b/configs/dist/mongo-config.dev.js new file mode 100644 index 0000000..0a004d7 --- /dev/null +++ b/configs/dist/mongo-config.dev.js @@ -0,0 +1,7 @@ +"use strict"; + +//const direccion="mongodb://localhost:27017/[DataEComerce][DataCollection]"; +//const direccion="mongodb+srv://admin:@cluster0.ikple.mongodb.net/test" +var direccion = "mongodb+srv://unsaac:unsaac123@primero.6gh6z.mongodb.net/EcommerceUnsaacBD?retryWrites=true&w=majority"; //const direccion="mongodb+srv://unsaac:unsaac123@primero.6gh6z.mongodb.net/EcommerceUnsaac?retryWrites=true&w=majority" + +module.exports = direccion; \ No newline at end of file diff --git a/configs/mongo-config.js b/configs/mongo-config.js index 2d70368..40b9dc7 100644 --- a/configs/mongo-config.js +++ b/configs/mongo-config.js @@ -1,4 +1,4 @@ -//const direccion="mongodb://localhost:27017/DataEComerceNode"; +//const direccion="mongodb://localhost:27017/[DataEComerce][DataCollection]"; //const direccion="mongodb+srv://admin:@cluster0.ikple.mongodb.net/test" const direccion ="mongodb+srv://unsaac:unsaac123@primero.6gh6z.mongodb.net/EcommerceUnsaacBD?retryWrites=true&w=majority" //const direccion="mongodb+srv://unsaac:unsaac123@primero.6gh6z.mongodb.net/EcommerceUnsaac?retryWrites=true&w=majority" diff --git a/models/Category.js b/models/Category.js index 9b853c0..56a0911 100644 --- a/models/Category.js +++ b/models/Category.js @@ -14,6 +14,12 @@ var categorySchema = mongoose.Schema({ var Category = module.exports = mongoose.model('Categories', categorySchema); +///////////////////////////////// +/*module.exports.createCategory = function (newCategory, callback){ + newCategory.save(callback); + }*/ + + // These are functions to get data from the database. You can even reach the information // without calling this functions but I just want to show you how you can add some functions // to your model file to get specific data. diff --git a/models/Product.js b/models/Product.js index 92f33c0..58b29d4 100644 --- a/models/Product.js +++ b/models/Product.js @@ -10,11 +10,8 @@ var productSchema = mongoose.Schema({ description: { type: String }, - department: { - type: String - }, category: { - type: String + type: Array }, price: { type: Number @@ -25,16 +22,28 @@ var productSchema = mongoose.Schema({ size: { type: String }, - quantity: { - type: Number + cellphone: { + type: String }, date: { type: Number + }, + pregunta1: { + type: Array + }, + pregunta2: { + type: Array } }); var Product = module.exports = mongoose.model('Product', productSchema); +///////////////////////////////// +module.exports.createProduct = function (newProduct, callback){ + newProduct.save(callback); +} + + module.exports.getAllProducts = function (query, sort, callback) { Product.find(query, null, sort, callback) } diff --git a/models/Variant.js b/models/Variant.js index 66b8739..7400d51 100644 --- a/models/Variant.js +++ b/models/Variant.js @@ -14,9 +14,6 @@ var variantSchema = mongoose.Schema({ size: { type: String }, - quantity: { - type: Number - }, title: { type: String }, diff --git a/modules/Cart.js b/modules/Cart.js index f092f76..714f067 100644 --- a/modules/Cart.js +++ b/modules/Cart.js @@ -13,7 +13,7 @@ class Cart { if (!storedItem) { storedItem = this.items[id] = { item: item, qty: 0, price: 0 }; } - storedItem.qty++; + storedItem.qty=1; storedItem.price = parseFloat((storedItem.item.price * storedItem.qty).toFixed(2)); this.items[id]=storedItem this.totalQty++; @@ -46,7 +46,7 @@ class Cart { } increaseQty(id) { - this.items[id].qty++; + this.items[id].qty=1; this.items[id].price += this.items[id].item.price; this.items[id].price = parseFloat(this.items[id].price.toFixed(2)) this.totalQty++; diff --git a/modules/dist/Cart.dev.js b/modules/dist/Cart.dev.js new file mode 100644 index 0000000..d6a6f89 --- /dev/null +++ b/modules/dist/Cart.dev.js @@ -0,0 +1,98 @@ +"use strict"; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } + +function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + +var cartModel = require('../models/Cart'); + +var Cart = +/*#__PURE__*/ +function () { + function Cart(oldCart) { + _classCallCheck(this, Cart); + + this.items = oldCart.items || {}; + this.totalQty = oldCart.totalQty || 0; + this.totalPrice = oldCart.totalPrice || 0; + this.userId = oldCart.userId || ""; + } + + _createClass(Cart, [{ + key: "add", + value: function add(item, id) { + var 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; + } + }, { + key: "generateModel", + value: function generateModel() { + var newCart = new cartModel({ + items: this.items, + totalQty: this.totalQty, + totalPrice: this.totalPrice, + userId: this.userId + }); + return newCart; + } + }, { + key: "decreaseQty", + value: function 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; + } + }, { + key: "increaseQty", + value: function 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; + } + }, { + key: "generateArray", + value: function generateArray() { + var arr = []; + + for (var id in this.items) { + arr.push(this.items[id]); + } + + return arr; + } + }]); + + return Cart; +}(); + +module.exports = Cart; \ No newline at end of file diff --git a/routes/dist/index.dev.js b/routes/dist/index.dev.js new file mode 100644 index 0000000..f82c9b1 --- /dev/null +++ b/routes/dist/index.dev.js @@ -0,0 +1,526 @@ +"use strict"; + +var express = require('express'); + +var router = express.Router(); + +var ensureAuthenticated = require('../modules/ensureAuthenticated'); + +var Product = require('../models/Product'); + +var Variant = require('../models/Variant'); + +var Department = require('../models/Department'); + +var Category = require('../models/Category'); + +var TypedError = require('../modules/ErrorHandler'); + +var Cart = require('../models/Cart'); + +var CartClass = require('../modules/Cart'); + +var paypal_config = require('../configs/paypal-config'); + +var paypal = require('paypal-rest-sdk'); + +var mongoose = require('mongoose'); + +var mongoConfig = require('../configs/mongo-config'); + +mongoose.connect(mongoConfig, { + useNewUrlParser: true, + useCreateIndex: true +}); //GET /products + +router.get('/products', function (req, res, next) { + var _categorizeQueryStrin = categorizeQueryString(req.query), + query = _categorizeQueryStrin.query, + order = _categorizeQueryStrin.order; + + 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" + }); + } + + res.json({ + products: products + }); + }); +}); //POST /products + +router.post('/ingresoproducts', function (req, res, next) { + var _req$body = req.body, + imagePath = _req$body.imagePath, + title = _req$body.title, + description = _req$body.description, + price = _req$body.price, + color = _req$body.color, + size = _req$body.size, + array_tags = _req$body.array_tags, + Pregunta1 = _req$body.Pregunta1, + Pregunta2 = _req$body.Pregunta2, + cellphone = _req$body.cellphone; + req.checkBody('imagePath', 'imagePath is required').notEmpty(); + req.checkBody('title', 'title is required').notEmpty(); + req.checkBody('description', 'description is required').notEmpty(); + req.checkBody('price', 'price is required').notEmpty(); + req.checkBody('color', 'color is required').notEmpty(); + req.checkBody('size', 'size is required').notEmpty(); + req.checkBody('categoria', 'category is required').notEmpty(); + req.checkBody('pregunta1', 'pregunta1 is required').notEmpty(); + req.checkBody('pregunta2', 'pregunta2 is required').notEmpty(); + var date = 5; + + for (var i = 0; i < array_tags.length; i++) { + array_tags[i] = array_tags[i].toLocaleLowerCase(); + } + + if (array_tags.indexOf(color.toLocaleLowerCase()) === -1) { + array_tags.push(color.toLocaleLowerCase()); + } + + var newProduct = new Product({ + imagePath: imagePath, + title: title.toLocaleLowerCase(), + description: description, + category: array_tags, + price: price, + color: color.toLocaleLowerCase(), + size: size, + cellphone: cellphone, + date: date, + pregunta1: Pregunta1, + pregunta2: Pregunta2 + }); + /*for (let i = 0; i < array_tags.length; i++) { + var newCatego = new category({ + categoryName: array_tags[i] + }); + newCatego.save(function (e, r) { + if (i === categories.length - 1) { + exit(); + } + }); + }*/ + + Product.createProduct(newProduct, function (err, user) { + if (err) return next(err); + res.json({ + message: 'user created' + }); + }); +}); //GET /products/:id + +router.get('/products/:id', function (req, res, next) { + var productId = req.params.id; + Product.getProductByID(productId, function (e, item) { + if (e) { + e.status = 404; + return next(e); + } else { + res.json({ + product: item + }); + } + }); +}); //GET /variants + +router.get('/variants', function (req, res, next) { + var productId = req.query.productId; + + if (productId) { + Variant.getVariantProductByID(productId, function (err, variants) { + if (err) return next(err); + return res.json({ + variants: variants + }); + }); + } else { + Variant.getAllVariants(function (e, variants) { + if (e) { + if (err) return next(err); + } else { + return res.json({ + variants: variants + }); + } + }); + } +}); //GET /variants/:id + +router.get('/variants/:id', ensureAuthenticated, function (req, res, next) { + var id = req.params.id; + + if (id) { + Variant.getVariantByID(id, function (err, variants) { + if (err) return next(err); + res.json({ + variants: variants + }); + }); + } +}); //GET /departments + +router.get('/departments', function (req, res, next) { + Department.getAllDepartments(req.query, function (err, d) { + if (err) return next(err); + res.status(200).json({ + departments: d + }); + }); +}); //GET /categories + +router.get('/categories', function (req, res, next) { + Category.getAllCategories(function (err, c) { + if (err) return next(err); + res.json({ + categories: c + }); + }); +}); //GET /search? + +router.get('/search', function (req, res, next) { + var _categorizeQueryStrin2 = categorizeQueryString(req.query), + query = _categorizeQueryStrin2.query, + order = _categorizeQueryStrin2.order; + + query['department'] = query['query']; + delete query['query']; + Product.getProductByDepartment(query, order, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + return res.json({ + products: p + }); + } else { + query['category'] = query['department']; + delete query['department']; + Product.getProductByCategory(query, order, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + return res.json({ + products: p + }); + } else { + query['title'] = query['category']; + delete query['category']; + Product.getProductByTitle(query, order, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + return res.json({ + products: p + }); + } else { + query['id'] = query['title']; + delete query['title']; + Product.getProductByID(query.id, function (err, p) { + var error = new TypedError('search', 404, 'not_found', { + message: "no product exist" + }); + + if (err) { + return next(error); + } + + if (p) { + return res.json({ + products: p + }); + } else { + return next(error); + } + }); + } + }); + } + }); + } + }); +}); // GET filter + +router.get('/filter', function (req, res, next) { + var result = {}; + var query = req.query.query; + Product.filterProductByDepartment(query, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + result['department'] = generateFilterResultArray(p, 'department'); + } + + Product.filterProductByCategory(query, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + result['category'] = generateFilterResultArray(p, 'category'); + } + + Product.filterProductByTitle(query, function (err, p) { + if (err) return next(err); + + if (p.length > 0) { + result['title'] = generateFilterResultArray(p, 'title'); + } + + if (Object.keys(result).length > 0) { + return res.json({ + filter: result + }); + } else { + var error = new TypedError('search', 404, 'not_found', { + message: "no product exist" + }); + return next(error); + } + }); + }); + }); +}); //GET /checkout + +router.get('/checkout/:cartId', ensureAuthenticated, function (req, res, next) { + var cartId = req.params.cartId; //aea + //const frontURL = 'https://zack-ecommerce-reactjs.herokuapp.com' + //const frontURL = 'http://localhost:3000' + + var frontURL = "https://ecommerce-react-unsaac1.herokuapp.com/"; + Cart.getCartById(cartId, function (err, c) { + if (err) return next(err); + + if (!c) { + var _err = new TypedError('/checkout', 400, 'invalid_field', { + message: 'cart not found' + }); + + return next(_err); + } + + var items_arr = new CartClass(c).generateArray(); + var paypal_list = []; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = items_arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var i = _step.value; + paypal_list.push({ + "name": i.item.title, + "price": i.item.price, + "currency": "CAD", + "quantity": i.qty + }); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator["return"] != null) { + _iterator["return"](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + var create_payment_json = { + "intent": "sale", + "payer": { + "payment_method": "paypal" + }, + "redirect_urls": { + "return_url": frontURL + '/success_page', + "cancel_url": frontURL + '/cancel_page' + }, + "transactions": [{ + "item_list": { + "items": paypal_list + }, + "amount": { + "currency": "CAD", + "total": c.totalPrice + }, + "description": "This is the payment description." + }] + }; + paypal.configure(paypal_config); + paypal.payment.create(create_payment_json, function (error, payment) { + if (error) { + console.log(JSON.stringify(error)); + return next(error); + } else { + console.log(payment); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = payment.links[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var link = _step2.value; + + if (link.rel === 'approval_url') { + res.json(link.href); + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { + _iterator2["return"](); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + }); + }); +}); //GET /payment/success + +router.get('/payment/success', ensureAuthenticated, function (req, res, next) { + var paymentId = req.query.paymentId; + var payerId = { + payer_id: req.query.PayerID + }; + paypal.payment.execute(paymentId, payerId, function (error, payment) { + if (error) { + console.error(JSON.stringify(error)); + return next(error); + } else { + if (payment.state == 'approved') { + console.log('payment completed successfully'); + console.log(payment); + res.json({ + payment: payment + }); + } else { + console.log('payment not successful'); + } + } + }); +}); + +function generateFilterResultArray(products, targetProp) { + var result_set = new Set(); + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = products[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var p = _step3.value; + result_set.add(p[targetProp]); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3["return"] != null) { + _iterator3["return"](); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return Array.from(result_set); +} + +function categorizeQueryString(queryObj) { + var query = {}; + var order = {}; //extract query, order, filter value + + for (var i in queryObj) { + if (queryObj[i]) { + // extract order + if (i === 'order') { + order['sort'] = queryObj[i]; + continue; + } // extract range + + + if (i === 'range') { + var range_arr = []; + var query_arr = []; // multi ranges + + if (queryObj[i].constructor === Array) { + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = queryObj[i][Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var r = _step4.value; + range_arr = r.split('-'); + query_arr.push({ + price: { + $gt: range_arr[0], + $lt: range_arr[1] + } + }); + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4["return"] != null) { + _iterator4["return"](); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + } // 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: query, + order: order + }; +} + +module.exports = router; \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 89c34e9..c8bf32b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -10,7 +10,9 @@ const Cart = require('../models/Cart'); const CartClass = require('../modules/Cart') const paypal_config = require('../configs/paypal-config') const paypal = require('paypal-rest-sdk') - +var mongoose = require('mongoose'); +const mongoConfig = require('../configs/mongo-config') +mongoose.connect(mongoConfig, { useNewUrlParser: true, useCreateIndex: true, }); //GET /products router.get('/products', function (req, res, next) { @@ -26,6 +28,63 @@ router.get('/products', function (req, res, next) { }) }); +//POST /products +router.post('/ingresoproducts', function (req, res, next) { + + const { imagePath, title, description, price, color, size, array_tags,Pregunta1, Pregunta2, cellphone } = req.body + req.checkBody('imagePath', 'imagePath is required').notEmpty(); + req.checkBody('title', 'title is required').notEmpty(); + req.checkBody('description', 'description is required').notEmpty(); + req.checkBody('price', 'price is required').notEmpty(); + req.checkBody('color', 'color is required').notEmpty(); + req.checkBody('size', 'size is required').notEmpty(); + req.checkBody('categoria', 'category is required').notEmpty(); + req.checkBody('pregunta1', 'pregunta1 is required').notEmpty(); + req.checkBody('pregunta2', 'pregunta2 is required').notEmpty(); + + const date = 5; + + for (let i = 0; i < array_tags.length; i++){ + array_tags[i]=array_tags[i].toLocaleLowerCase(); + + if (array_tags.indexOf(color.toLocaleLowerCase())===-1){ + array_tags.push(color.toLocaleLowerCase()); + } + + var newProduct = new Product({ + imagePath: imagePath, + title: title.toLocaleLowerCase(), + description: description, + category: array_tags, + price: price, + color: color.toLocaleLowerCase(), + size: size, + cellphone:cellphone, + date: date, + pregunta1: Pregunta1, + pregunta2: Pregunta2, + }); + + /*for (let i = 0; i < array_tags.length; i++) { + + var newCatego = new category({ + categoryName: array_tags[i] + }); + + newCatego.save(function (e, r) { + if (i === categories.length - 1) { + exit(); + } + }); + }*/ + + + Product.createProduct(newProduct, function (err, user) { + if (err) return next(err); + res.json({ message: 'user created' }) + }); +}); + //GET /products/:id router.get('/products/:id', function (req, res, next) { let productId = req.params.id; @@ -164,9 +223,9 @@ router.get('/filter', function (req, res, next) { //GET /checkout router.get('/checkout/:cartId', ensureAuthenticated, function (req, res, next) { const cartId = req.params.cartId - //const frontURL = 'https://zack-ecommerce-reactjs.herokuapp.com' + //d //const frontURL = 'http://localhost:3000' - const frontURL="https://ecommerce-react-unsaac1.herokuapp.com/" ; + const frontURL="https://e-commerce-uwunsaac.herokuapp.com/" ; Cart.getCartById(cartId, function (err, c) { if (err) return next(err) if (!c) { diff --git a/seed/index.js b/seed/index.js index 9f898d5..586aa86 100644 --- a/seed/index.js +++ b/seed/index.js @@ -41,7 +41,7 @@ for (let i = 0; i < categories.length; i++) { }); } -var departments = +/*var departments = [ new Department({ departmentName: 'Mujeres', @@ -64,7 +64,7 @@ for (let i = 0; i < departments.length; i++) { exit(); } }); -} +}*/ var products = [ @@ -76,8 +76,6 @@ var products = price: 35.95, color: 'Gray', size: 'XS,S,M', - quantity: 10, - department: 'Mujeres', category: 'Basicos', date: 1581397200000 }), @@ -89,8 +87,6 @@ var products = price: 29.99, color: 'Black', size: 'XS,S,XL', - quantity: 15, - department: 'Mujeres', category: 'Basicos', date: 1597885814264 }), @@ -102,8 +98,6 @@ var products = price: 25.99, color: 'White', size: 'XS', - quantity: 90, - department: 'Mujeres', category: 'Basicos', date: 1581397200000 }), @@ -115,8 +109,6 @@ var products = price: 79.99, color: 'Black', size: 'S,M,L', - quantity: 4, - department: 'Mujeres', category: 'Chaqueta', date: 1581397200000 }), @@ -128,8 +120,6 @@ var products = price: 79.99, color: 'Orange', size: 'M,L', - quantity: 5, - department: 'Varones', category: 'Prendas de punto', date: 1597885814264 }), @@ -141,8 +131,6 @@ var products = price: 79.99, color: 'Dark Blue', size: 'M,L', - quantity: 80, - department: 'Varones', category: 'Jeans', date: 1597885814264 }), @@ -154,8 +142,6 @@ var products = price: 45.99, color: 'Light Blue', size: 'XS,S,M', - quantity: 8, - department: 'Varones', category: 'Jeans', date: 1581397200000 }), @@ -167,8 +153,6 @@ var products = price: 99.99, color: 'Brown', size: 'XS,M,XL', - quantity: 12, - department: 'Varones', category: 'Campera', date: 1581397200000 }), @@ -180,8 +164,6 @@ var products = price: 16.90, color: 'OYSTER WHITE', size: 'XS,M', - quantity: 23, - department: 'Niños', category: 'Niña', date: 1597962874736 }), @@ -193,8 +175,6 @@ var products = price: 45.90, color: 'BLACK ', size: 'XS', - quantity: 23, - department: 'Niños', category: 'Niño', date: 1597962874736 }), @@ -208,72 +188,12 @@ for (let i = 0; i < products.length; i++) { }); } -var variants = - [ - new Variant({ - productID: '5bedf31cc14d7822b39d9d43', - imagePath: 'https://static.zara.net/photos///2018/I/0/1/p/7568/644/710/2/w/1920/7568644710_1_1_1.jpg?ts=1541151891840', - color: 'Beige', - size: 'S,L', - quantity: 5, - }), - new Variant({ - productID: '5bedf3b9c14d7822b39d9d45', - imagePath: 'https://static.zara.net/photos///2018/I/0/1/p/5644/641/735/2/w/1920/5644641735_2_5_1.jpg?ts=1540395590656', - color: 'Copper', - size: 'S,L,XL', - quantity: 12, - }), - new Variant({ - productID: '5bedf448c14d7822b39d9d47', - imagePath: 'https://static.zara.net/photos///2018/I/0/1/p/7568/469/605/2/w/1920/7568469605_2_1_1.jpg?ts=1540394095062', - color: 'Maroon', - size: 'XS,M,L', - quantity: 4, - }), - new Variant({ - productID: '5bedf448c14d7822b39d9d47', - imagePath: 'https://static.zara.net/photos///2018/I/0/1/p/7568/469/822/2/w/1920/7568469822_2_1_1.jpg?ts=1540394193241', - color: 'Charcool', - size: 'XS,L,XL', - quantity: 5, - }), - new Variant({ - productID: '5bedf5eec14d7822b39d9d4e', - imagePath: 'https://static.zara.net/photos///2018/I/0/2/p/1775/300/806/2/w/1920/1775300806_2_1_1.jpg?ts=1539690394197', - color: 'Stone', - size: 'S,XL', - quantity: 35, - }), - new Variant({ - productID: '5bedf720c14d7822b39d9d52', - imagePath: 'https://static.zara.net/photos///2018/I/0/2/p/5575/380/407/2/c-269-0-2048-3072/w/1920/5575380407_1_1_1.jpg?ts=1527602989905', - color: 'Dark Blue', - size: 'M,XL', - quantity: 5, - }), - new Variant({ - productID: '5f3efb0d034bec1b28de7238', - imagePath: 'https://static.zara.net/photos///2020/I/0/3/p/0257/700/800/102/w/560/0257700800_2_10_1.jpg?ts=1596028794110', - color: 'BLACK', - size: 'M,XL', - quantity: 5, - }) - - ]; -for (let i = 0; i < variants.length; i++) { - variants[i].save(function (e, r) { - if (i === variants.length - 1) { - exit(); - } - }); -} var newUser = new User({ - username: 'admin@admin.com', - password: 'admin', - fullname: 'Cuneyt Celebican', + username: '171914@unsaac.edu.pe', + password: 'alex2020', + fullname: 'Alex', admin: true }); User.createUser(newUser, function (err, user) {