From fb9aa51bccd1c7fc38ca7681bb39a23da53eba1a Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:37:18 -0300 Subject: [PATCH 01/37] Users view added --- views/users.ejs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 views/users.ejs diff --git a/views/users.ejs b/views/users.ejs new file mode 100644 index 0000000..e9041c1 --- /dev/null +++ b/views/users.ejs @@ -0,0 +1,42 @@ +<%- include('partials/header') %> +
+
+
+

Inicia Sesión

+
+
+
Correo Electrónico:
+ +
+
+
Contraseña:
+ +
+ Iniciar Sesión +
+
+
+ +
+
+

Regístate

+
+
+
Correo Electrónico:
+ +
+
+
Contraseña:
+ +
+
+
Repite la Contraseña:
+ +
+ Registrarse +
+
+
+
+ +<%- include('partials/footer') %> \ No newline at end of file From 1808250c22e90572d008c62f1e7556ff044cd448 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:38:00 -0300 Subject: [PATCH 02/37] New Database Tables --- database/config.json | 5 +++++ database/favorites.json | 4 ++++ database/users.json | 6 ++++++ 3 files changed, 15 insertions(+) create mode 100644 database/config.json create mode 100644 database/favorites.json create mode 100644 database/users.json diff --git a/database/config.json b/database/config.json new file mode 100644 index 0000000..4c7c80a --- /dev/null +++ b/database/config.json @@ -0,0 +1,5 @@ +{ + "users": { + "maxID": 1 + } +} \ No newline at end of file diff --git a/database/favorites.json b/database/favorites.json new file mode 100644 index 0000000..ef4dbe2 --- /dev/null +++ b/database/favorites.json @@ -0,0 +1,4 @@ +[{ + "id": 1, + "favoritesProducts": [] +}] \ No newline at end of file diff --git a/database/users.json b/database/users.json new file mode 100644 index 0000000..b75c5cc --- /dev/null +++ b/database/users.json @@ -0,0 +1,6 @@ +[{ + "id": 1, + "email": "gonzalobordon02@hotmail.com", + "password": "123" + } +] \ No newline at end of file From 97a24a16a1bab152eeed11eabf025a449bf6ed66 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:38:31 -0300 Subject: [PATCH 03/37] TSC transpirate --- build/client/class/API.js | 22 ++-- build/client/class/App.js | 10 ++ build/client/class/Favorites.js | 55 +++++++-- build/client/class/Users.js | 113 ++++++++++++++++++ build/client/handlers/loginHandler.js | 60 ++++++++++ build/client/handlers/registerHandler.js | 64 ++++++++++ build/client/interfaces/User.js | 2 + build/client/listeners/favoritesListener.js | 26 ++-- .../client/listeners/loginRegisterListener.js | 18 +++ build/server/classes/Config.js | 35 ++++++ build/server/classes/DataBase.js | 59 +++++++++ build/server/classes/Filter.js | 13 ++ build/server/classes/ProductsAPI.js | 26 +++- build/server/classes/UsersAPI.js | 62 ++++++++++ .../components/ProductsCardComponent.js | 2 +- build/server/controllers/cart.get.js | 4 + build/server/controllers/index.get.js | 4 + build/server/controllers/product.get.js | 14 +++ build/server/controllers/products.get.js | 19 +++ build/server/controllers/products.post.js | 10 ++ build/server/controllers/productsIDs.post.js | 10 ++ build/server/controllers/users.get.js | 4 + build/server/controllers/users.post.js | 17 +++ build/server/controllers/users.put.js | 17 +++ build/server/interfaces/User.js | 2 + build/server/routes.js | 47 ++++---- build/server/routes/product.controller.js | 4 +- build/server/routes/users.controller.js | 4 + 28 files changed, 665 insertions(+), 58 deletions(-) create mode 100644 build/client/class/Users.js create mode 100644 build/client/handlers/loginHandler.js create mode 100644 build/client/handlers/registerHandler.js create mode 100644 build/client/interfaces/User.js create mode 100644 build/client/listeners/loginRegisterListener.js create mode 100644 build/server/classes/Config.js create mode 100644 build/server/classes/DataBase.js create mode 100644 build/server/classes/Filter.js create mode 100644 build/server/classes/UsersAPI.js create mode 100644 build/server/controllers/cart.get.js create mode 100644 build/server/controllers/index.get.js create mode 100644 build/server/controllers/product.get.js create mode 100644 build/server/controllers/products.get.js create mode 100644 build/server/controllers/products.post.js create mode 100644 build/server/controllers/productsIDs.post.js create mode 100644 build/server/controllers/users.get.js create mode 100644 build/server/controllers/users.post.js create mode 100644 build/server/controllers/users.put.js create mode 100644 build/server/interfaces/User.js create mode 100644 build/server/routes/users.controller.js diff --git a/build/client/class/API.js b/build/client/class/API.js index e8129f8..f4b4b6c 100644 --- a/build/client/class/API.js +++ b/build/client/class/API.js @@ -44,20 +44,28 @@ var apiErrorHandler_1 = __importDefault(require("../errors/apiErrorHandler")); var API = /** @class */ (function () { function API() { } - API.fetchAPI = function (url, data) { + API.fetchAPI = function (url, data, method) { + if (method === void 0) { method = "POST"; } return __awaiter(this, void 0, void 0, function () { + var response, responseJson; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fetch(url, { - method: "POST", + method: method, headers: { "Content-Type": "application/json", }, - body: JSON.stringify(data) - }) - .then(function (e) { return e.json(); }) - .then(function (res) { return (Object.keys(res).length === 0 ? config_1.API_ERROR : res); })]; - case 1: return [2 /*return*/, _a.sent()]; + body: JSON.stringify(data), + })]; + case 1: + response = _a.sent(); + return [4 /*yield*/, response.json()]; + case 2: + responseJson = _a.sent(); + if (response.ok) { + return [2 /*return*/, Object.keys(responseJson).length === 0 ? config_1.API_ERROR : responseJson]; + } + return [2 /*return*/, responseJson.message]; } }); }); diff --git a/build/client/class/App.js b/build/client/class/App.js index 4dee013..86a798f 100644 --- a/build/client/class/App.js +++ b/build/client/class/App.js @@ -11,22 +11,26 @@ var searchsListener_1 = __importDefault(require("../listeners/searchsListener")) var shopListener_1 = __importDefault(require("../listeners/shopListener")); // CLASSES var Favorites_1 = __importDefault(require("./Favorites")); +var Users_1 = __importDefault(require("./Users")); var Cart_1 = __importDefault(require("./Cart")); var UI_1 = __importDefault(require("./UI")); // SCRIPTS var updateQuantityProducts_1 = __importDefault(require("../scripts/updateQuantityProducts")); var loadTable_1 = __importDefault(require("../scripts/loadTable")); var config_1 = require("../config"); +var loginRegisterListener_1 = __importDefault(require("../listeners/loginRegisterListener")); var App = /** @class */ (function () { function App(HTML_APP) { this.PREPARE = { products: "productsPrepare", product: "productPrepare", cart: "cartPrepare", + users: "usersPrepare" }; this.ui = new UI_1.default(HTML_APP); this.cart = new Cart_1.default(); this.favorites = new Favorites_1.default(); + this.users = new Users_1.default(); } /** * Loads and runs the needed listeners. @@ -60,6 +64,12 @@ var App = /** @class */ (function () { (0, closeCartListener_1.default)(this.cart); (0, loadTable_1.default)(this.cart); }; + /** + * Loads all listeners for Users. + */ + App.prototype.usersPrepare = function () { + (0, loginRegisterListener_1.default)(); + }; return App; }()); exports.default = App; diff --git a/build/client/class/Favorites.js b/build/client/class/Favorites.js index 019dd69..10d8b54 100644 --- a/build/client/class/Favorites.js +++ b/build/client/class/Favorites.js @@ -14,6 +14,31 @@ var __extends = (this && this.__extends) || (function () { d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -26,20 +51,27 @@ var Favorites = /** @class */ (function (_super) { return _super.call(this, config_1.SS_FAVORITES, []) || this; } Favorites.prototype.addToFavorites = function (productID) { - var favoritesArray = this.getStorage(); - favoritesArray.push(productID); - this.updateStorage(favoritesArray); + var favoritesSet = new Set(this.getStorage()).add(productID); + this.updateFavorites(favoritesSet); }; - Favorites.prototype.removeProduct = function (productID) { - var favoritesArray = this.getStorage(); - this.updateStorage(favoritesArray.splice(favoritesArray.indexOf(productID), 1)); + Favorites.prototype.removeFromFavorite = function (productID) { + var favoritesSet = new Set(this.getStorage()); + favoritesSet.delete(productID); + this.updateFavorites(favoritesSet); + }; + Favorites.prototype.handleFavorite = function (productID) { + var favoritesSet = new Set(this.getStorage()); + if (favoritesSet.has(productID)) { + favoritesSet.delete(productID); + return; + } + favoritesSet.add(productID); }; /** * @return if the Cart is empty or not. */ Favorites.prototype.isEmpty = function () { - var cartResponse = this.getStorage(); - return cartResponse.length === 0; + return this.getStorage().length === 0; }; /** * @return favorites products. @@ -54,6 +86,13 @@ var Favorites = /** @class */ (function (_super) { return this.getStorage().includes(id); ; }; + /** + * Update the Favorites Products Storage. + */ + Favorites.prototype.updateFavorites = function (favoritesSet) { + var favoritesArray = __spreadArray([], __read(favoritesSet), false); + this.updateStorage(favoritesArray); + }; return Favorites; }(Storage_1.default)); exports.default = Favorites; diff --git a/build/client/class/Users.js b/build/client/class/Users.js new file mode 100644 index 0000000..0256cf4 --- /dev/null +++ b/build/client/class/Users.js @@ -0,0 +1,113 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var API_1 = __importDefault(require("./API")); +var Router_1 = __importDefault(require("./Router")); +var Storage_1 = __importDefault(require("./Storage")); +var Users = /** @class */ (function (_super) { + __extends(Users, _super); + function Users() { + return _super.call(this, "user", { + id: null, + email: "", + password: "", + }) || this; + } + Users.prototype.loginUser = function (email, password) { + return __awaiter(this, void 0, void 0, function () { + var response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, API_1.default.fetchAPI(Router_1.default.createURL("/users"), { email: email, password: password })]; + case 1: + response = _a.sent(); + if (API_1.default.isApiError(response)) { + return [2 /*return*/, response.message]; + } + this.updateStorage({ + id: response.id, + email: email, + password: password + }); + return [2 /*return*/]; + } + }); + }); + }; + Users.prototype.registerUser = function (email, password) { + return __awaiter(this, void 0, void 0, function () { + var response; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, API_1.default.fetchAPI(Router_1.default.createURL("/users"), { email: email, password: password }, "PUT")]; + case 1: + response = _a.sent(); + if (API_1.default.isApiError(response)) { + return [2 /*return*/, response.message]; + } + this.updateStorage({ + id: response.id, + email: email, + password: password + }); + return [2 /*return*/]; + } + }); + }); + }; + return Users; +}(Storage_1.default)); +exports.default = Users; diff --git a/build/client/handlers/loginHandler.js b/build/client/handlers/loginHandler.js new file mode 100644 index 0000000..97131e9 --- /dev/null +++ b/build/client/handlers/loginHandler.js @@ -0,0 +1,60 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var main_1 = __importDefault(require("../main")); +// HTML +function loginHandler() { + return __awaiter(this, void 0, void 0, function () { + var LOGIN_FORM, _a, email, password, response; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + LOGIN_FORM = new FormData(document.getElementById("js-loginForm")); + _a = Object.fromEntries(LOGIN_FORM.entries()), email = _a.email, password = _a.password; + return [4 /*yield*/, main_1.default.users.loginUser(email, password)]; + case 1: + response = _b.sent(); + return [2 /*return*/, alert(response ? response : "Logueado con Éxito")]; + } + }); + }); +} +exports.default = loginHandler; diff --git a/build/client/handlers/registerHandler.js b/build/client/handlers/registerHandler.js new file mode 100644 index 0000000..ed9a10e --- /dev/null +++ b/build/client/handlers/registerHandler.js @@ -0,0 +1,64 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __generator = (this && this.__generator) || function (thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var main_1 = __importDefault(require("../main")); +// HTML +var REGISTER_FORM = new FormData(document.getElementById("js-registerForm")); +function registerHandler() { + return __awaiter(this, void 0, void 0, function () { + var _a, email, password, passwordRepeat, response; + return __generator(this, function (_b) { + switch (_b.label) { + case 0: + _a = Object.fromEntries(REGISTER_FORM.entries()), email = _a.email, password = _a.password, passwordRepeat = _a.passwordRepeat; + if (!(password === passwordRepeat)) return [3 /*break*/, 2]; + return [4 /*yield*/, main_1.default.users.registerUser(email, password)]; + case 1: + response = _b.sent(); + return [2 /*return*/, alert(response ? response : "Registrado con Éxito")]; + case 2: + alert("Las contraseñas no coinciden."); + return [2 /*return*/]; + } + }); + }); +} +exports.default = registerHandler; diff --git a/build/client/interfaces/User.js b/build/client/interfaces/User.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/client/interfaces/User.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/listeners/favoritesListener.js b/build/client/listeners/favoritesListener.js index 966c5ad..272aa96 100644 --- a/build/client/listeners/favoritesListener.js +++ b/build/client/listeners/favoritesListener.js @@ -1,9 +1,19 @@ "use strict"; -// import searchInputHandler from "../handlers/searchInputHandler"; -// // HTML -// const FAVORITES_ICON: HTMLElement = document.getElementsByClassName("favorites-icon"); -// // EVENTS -// const SEARCH_INPUT_S_EVENT: string = "keyup"; -// export default function favoritesListener(): void { -// (FAVORITES_ICON as HTMLElement).addEventListener(SEARCH_INPUT_S_EVENT, searchInputHandler); -// } +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var main_1 = __importDefault(require("../main")); +// HTML +var FAVORITES_ICONS = document.getElementsByClassName("favorites-icon"); +// EVENTS +var SEARCH_INPUT_S_EVENT = "keyup"; +function favoritesListener() { + Array.from(FAVORITES_ICONS).forEach(function (favorites_icon) { + favorites_icon.addEventListener(SEARCH_INPUT_S_EVENT, function (e) { + var productID = +favorites_icon.dataset.id; + main_1.default.favorites.handleFavorite(productID); + }); + }); +} +exports.default = favoritesListener; diff --git a/build/client/listeners/loginRegisterListener.js b/build/client/listeners/loginRegisterListener.js new file mode 100644 index 0000000..6e9a3b7 --- /dev/null +++ b/build/client/listeners/loginRegisterListener.js @@ -0,0 +1,18 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var loginHandler_1 = __importDefault(require("../handlers/loginHandler")); +var registerHandler_1 = __importDefault(require("../handlers/registerHandler")); +// HTML +var LOGIN_FORM_BTN = document.getElementById("js-loginFormBTN"); +var REGISTER_FORM = document.getElementById("js-registerForm"); +// EVENTS +var REGISTER_FORM_BTN_EVENT = "click"; +var LOGIN_FORM_BTN_EVENT = "click"; +function loginRegisterListener() { + LOGIN_FORM_BTN.addEventListener(LOGIN_FORM_BTN_EVENT, loginHandler_1.default); + REGISTER_FORM.addEventListener(REGISTER_FORM_BTN_EVENT, registerHandler_1.default); +} +exports.default = loginRegisterListener; diff --git a/build/server/classes/Config.js b/build/server/classes/Config.js new file mode 100644 index 0000000..830228a --- /dev/null +++ b/build/server/classes/Config.js @@ -0,0 +1,35 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var DataBase_1 = __importDefault(require("./DataBase")); +var ProductsAPI = /** @class */ (function (_super) { + __extends(ProductsAPI, _super); + function ProductsAPI() { + return _super.call(this, "config") || this; + } + ProductsAPI.prototype.getConfig = function (configEntry) { + return; + }; + ProductsAPI.prototype.setConfig = function (configEntry, configData) { + //return this.getProductsByIds(this.body.IDList); + }; + return ProductsAPI; +}(DataBase_1.default)); +exports.default = ProductsAPI; diff --git a/build/server/classes/DataBase.js b/build/server/classes/DataBase.js new file mode 100644 index 0000000..17ae035 --- /dev/null +++ b/build/server/classes/DataBase.js @@ -0,0 +1,59 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var Filter_1 = __importDefault(require("./Filter")); +var fs = require("fs"); +var DATABASE_DIR = require("../config").DATABASE_DIR; +var DataBase = /** @class */ (function (_super) { + __extends(DataBase, _super); + function DataBase(tableName) { + var _this = _super.call(this) || this; + _this.tableNames = ["config", "products", "users", "favorites"]; + _this.table = _this.returnTable(tableName); + return _this; + } + DataBase.prototype.getTable = function () { + return this.table; + }; + DataBase.prototype.setTable = function (tableName, tableData) { + fs.writeFileSync(this.getTablePath(tableName), JSON.stringify(tableData)); + }; + DataBase.prototype.returnTable = function (tableName) { + if (this.tableNames.includes(tableName)) { + return JSON.parse(fs.readFileSync(this.getTablePath(tableName), "utf8")); + } + }; + DataBase.prototype.getConfig = function (configEntry) { + return this.returnConfig()[configEntry]; + }; + DataBase.prototype.setConfig = function (configEntry, configData) { + var config = this.returnConfig(); + config[configEntry] = configData; + this.setTable("config", config); + }; + DataBase.prototype.getTablePath = function (tableName) { + return DATABASE_DIR + "/" + tableName + ".json"; + }; + DataBase.prototype.returnConfig = function () { + return this.returnTable(this.getTablePath("config")); + }; + return DataBase; +}(Filter_1.default)); +exports.default = DataBase; diff --git a/build/server/classes/Filter.js b/build/server/classes/Filter.js new file mode 100644 index 0000000..a978995 --- /dev/null +++ b/build/server/classes/Filter.js @@ -0,0 +1,13 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var Filter = /** @class */ (function () { + function Filter() { + } + Filter.prototype.inRange = function (elem, min, max) { + if (min === void 0) { min = null; } + if (max === void 0) { max = null; } + return (min ? elem >= min : true) && (max ? elem <= max : true); + }; + return Filter; +}()); +exports.default = Filter; diff --git a/build/server/classes/ProductsAPI.js b/build/server/classes/ProductsAPI.js index bdf91f7..d30b2f3 100644 --- a/build/server/classes/ProductsAPI.js +++ b/build/server/classes/ProductsAPI.js @@ -18,20 +18,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var API_1 = __importDefault(require("./API")); +var DataBase_1 = __importDefault(require("./DataBase")); var ProductsAPI = /** @class */ (function (_super) { __extends(ProductsAPI, _super); function ProductsAPI(req) { - var _this = _super.call(this) || this; + var _this = _super.call(this, "products") || this; _this.params = {}; _this.body = {}; _this.params = req.params; _this.body = req.body; + _this.products = _this.getTable(); return _this; } ProductsAPI.prototype.getProducts = function () { - var _a = this.params, page = _a.page, search = _a.search, min = _a.min, max = _a.max; - var products = API_1.default.getProducts(search, min, max); + var _this = this; + var _a = this.params, page = _a.page, min = _a.min, max = _a.max; + var search = this.body.search; + var SEARCH_REGEX = new RegExp(search); + var products = this.products.filter(function (product) { + return SEARCH_REGEX.test(product.title.toLowerCase()) && + _this.inRange(product.price, min, max); + }); var maxPage = Math.ceil(products.length / 10); var currentPage = +page || 1; var firstProductIndex = (currentPage - 1) * 10; @@ -42,8 +49,15 @@ var ProductsAPI = /** @class */ (function (_super) { }; }; ProductsAPI.prototype.getProductsById = function () { - return API_1.default.getProductsByIds(this.body.IDList); + var _this = this; + return this.products.filter(function (product) { + return _this.body.IDList.includes(String(product.id)); + }); + }; + ProductsAPI.prototype.getProduct = function () { + var id = this.params.id; + return this.products.find(function (product) { return product.id === id; }); }; return ProductsAPI; -}(API_1.default)); +}(DataBase_1.default)); exports.default = ProductsAPI; diff --git a/build/server/classes/UsersAPI.js b/build/server/classes/UsersAPI.js new file mode 100644 index 0000000..ff2dc0a --- /dev/null +++ b/build/server/classes/UsersAPI.js @@ -0,0 +1,62 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var DataBase_1 = __importDefault(require("./DataBase")); +var UsersAPI = /** @class */ (function (_super) { + __extends(UsersAPI, _super); + function UsersAPI(req) { + var _this = _super.call(this, "users") || this; + _this.body = {}; + _this.body = req.body; + _this.users = _this.getTable(); + return _this; + } + UsersAPI.prototype.getUser = function (email) { + return this.users.find(function (user) { return user.email === email; }); + }; + UsersAPI.prototype.existUser = function (email) { + return !!this.getUser(email); + }; + UsersAPI.prototype.setUser = function () { + var _a = this.body, email = _a.email, password = _a.password; + if (this.existUser(email)) { + return; + } + var config = this.getConfig("users"); + config.maxID += 1; + this.setConfig("users", config); + this.users.push({ + email: email, + password: password, + id: config.maxID, + }); + return config.maxID; + }; + UsersAPI.prototype.validateUser = function () { + console.log(this.body); + var _a = this.body, email = _a.email, password = _a.password; + var user = this.getUser(email); + if (user && user.password === password) { + return user.id; + } + }; + return UsersAPI; +}(DataBase_1.default)); +exports.default = UsersAPI; diff --git a/build/server/components/ProductsCardComponent.js b/build/server/components/ProductsCardComponent.js index f285bcc..3bd232b 100644 --- a/build/server/components/ProductsCardComponent.js +++ b/build/server/components/ProductsCardComponent.js @@ -2,6 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); function ProductsCardComponent(_a, isFavorite) { var image = _a.image, id = _a.id, price = _a.price, title = _a.title; - return /* html */ "\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
" + title + "
\n
$" + price + "
\n
\n Comprar\n
\n "; + return /* html */ "\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
" + title + "
\n
$" + price + "
\n
\n Comprar\n
\n "; } exports.default = ProductsCardComponent; diff --git a/build/server/controllers/cart.get.js b/build/server/controllers/cart.get.js new file mode 100644 index 0000000..c71d170 --- /dev/null +++ b/build/server/controllers/cart.get.js @@ -0,0 +1,4 @@ +"use strict"; +module.exports = function indexGet(req, res) { + res.render('cart'); +}; diff --git a/build/server/controllers/index.get.js b/build/server/controllers/index.get.js new file mode 100644 index 0000000..b807b7b --- /dev/null +++ b/build/server/controllers/index.get.js @@ -0,0 +1,4 @@ +"use strict"; +module.exports = function indexGet(req, res) { + res.render('index'); +}; diff --git a/build/server/controllers/product.get.js b/build/server/controllers/product.get.js new file mode 100644 index 0000000..cb98bce --- /dev/null +++ b/build/server/controllers/product.get.js @@ -0,0 +1,14 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); +var ProductSpecsComponent_1 = __importDefault(require("../components/ProductSpecsComponent")); +module.exports = function productGet(req, res) { + var product = new ProductsAPI_1.default(req).getProduct(); + var config = product; + config.productSpecs = (0, ProductSpecsComponent_1.default)(product.caracts); + config.isFavorite = true; + res.render("product", config); +}; diff --git a/build/server/controllers/products.get.js b/build/server/controllers/products.get.js new file mode 100644 index 0000000..a167637 --- /dev/null +++ b/build/server/controllers/products.get.js @@ -0,0 +1,19 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); +var ProductsCardComponent_1 = __importDefault(require("../components/ProductsCardComponent")); +var PaginatorComponent_1 = __importDefault(require("../components/PaginatorComponent")); +module.exports = function productsGet(req, res) { + var _a = new ProductsAPI_1.default(req).getProducts(), products = _a.products, page = _a.page, maxPage = _a.maxPage; + var productsHTML = products + .map(function (product) { return (0, ProductsCardComponent_1.default)(product, true); }) + .join(""); + var paginatorHTML = (0, PaginatorComponent_1.default)(page, maxPage); + res.render("products", { + productsHTML: productsHTML, + paginatorHTML: paginatorHTML, + }); +}; diff --git a/build/server/controllers/products.post.js b/build/server/controllers/products.post.js new file mode 100644 index 0000000..bada7d3 --- /dev/null +++ b/build/server/controllers/products.post.js @@ -0,0 +1,10 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); +module.exports = function productsPost(req, res) { + var response = new ProductsAPI_1.default(req).getProducts(); + res.json(response); +}; diff --git a/build/server/controllers/productsIDs.post.js b/build/server/controllers/productsIDs.post.js new file mode 100644 index 0000000..437c152 --- /dev/null +++ b/build/server/controllers/productsIDs.post.js @@ -0,0 +1,10 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); +module.exports = function productsIDsPost(req, res) { + var response = new ProductsAPI_1.default(req).getProductsById(); + res.json(response); +}; diff --git a/build/server/controllers/users.get.js b/build/server/controllers/users.get.js new file mode 100644 index 0000000..382878d --- /dev/null +++ b/build/server/controllers/users.get.js @@ -0,0 +1,4 @@ +"use strict"; +module.exports = function usersGet(req, res) { + res.render('users'); +}; diff --git a/build/server/controllers/users.post.js b/build/server/controllers/users.post.js new file mode 100644 index 0000000..ec17136 --- /dev/null +++ b/build/server/controllers/users.post.js @@ -0,0 +1,17 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var UsersAPI_1 = __importDefault(require("../classes/UsersAPI")); +module.exports = function usersPost(req, res) { + var idUser = new UsersAPI_1.default(req).validateUser(); + if (idUser) { + return res.json({ + id: idUser, + }); + } + res.status(401).json({ + message: "Credenciales Inválidas", + }); +}; diff --git a/build/server/controllers/users.put.js b/build/server/controllers/users.put.js new file mode 100644 index 0000000..c8f336a --- /dev/null +++ b/build/server/controllers/users.put.js @@ -0,0 +1,17 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +var UsersAPI_1 = __importDefault(require("../classes/UsersAPI")); +module.exports = function usersPost(req, res) { + var idUser = new UsersAPI_1.default(req).setUser(); + if (idUser) { + return res.json({ + id: idUser, + }); + } + res.status(401).send({ + message: "Usuario Existente", + }); +}; diff --git a/build/server/interfaces/User.js b/build/server/interfaces/User.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/build/server/interfaces/User.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/routes.js b/build/server/routes.js index e228633..f905729 100644 --- a/build/server/routes.js +++ b/build/server/routes.js @@ -1,34 +1,29 @@ "use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("./classes/ProductsAPI")); var Router = require("express").Router; var router = Router(); // CONTROLLERS -var productsController = require("./routes/products.controller"); -var productController = require("./routes/product.controller"); -var indexController = require("./routes/index.controller"); -var cartController = require("./routes/cart.controller"); -router.get("/", indexController); -router.get("/products/:page", productsController); -router.get("/products", productsController); -router.get("/product/:id", productController); -router.get("/cart", cartController); +var productsGet = require("./controllers/products.get"); +var productGet = require("./controllers/product.get"); +var indexGet = require("./controllers/index.get"); +var usersGet = require("./controllers/users.get"); +var cartGet = require("./controllers/cart.get"); +var productsIDsPost = require("./controllers/productsIDs.post"); +var productsPost = require("./controllers/products.post"); +var usersPost = require("./controllers/users.post"); +var usersPut = require("./controllers/users.put"); +router.get("/", indexGet); +router.get("/products/:page", productsGet); +router.get("/products", productsGet); +router.get("/product/:id", productGet); +router.get("/users", usersGet); +router.get("/cart", cartGet); // POST -router.post("/products/ids", function (req, res) { - var response = new ProductsAPI_1.default(req).getProductsById(); - res.json(response); -}); -router.post("/products/:page", function (req, res) { - var response = new ProductsAPI_1.default(req).getProducts(); - res.json(response); -}); -router.post("/products", function (req, res) { - var response = new ProductsAPI_1.default(req).getProducts(); - res.json(response); -}); +router.post("/products/ids", productsIDsPost); +router.post("/products/:page", productsPost); +router.post("/products", productsPost); +router.post("/users", usersPost); +// PUT +router.put("/users", usersPut); router.use(function (req, res) { res.status(404).render("404"); }); diff --git a/build/server/routes/product.controller.js b/build/server/routes/product.controller.js index fdb75b4..4013a50 100644 --- a/build/server/routes/product.controller.js +++ b/build/server/routes/product.controller.js @@ -3,10 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var API_1 = __importDefault(require("../classes/API")); +var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); var ProductSpecsComponent_1 = __importDefault(require("../components/ProductSpecsComponent")); module.exports = function productController(req, res) { - var product = API_1.default.getProduct(+req.params.id); + var product = new ProductsAPI_1.default(req).getProduct(); var config = product; config.productSpecs = (0, ProductSpecsComponent_1.default)(product.caracts); config.isFavorite = true; diff --git a/build/server/routes/users.controller.js b/build/server/routes/users.controller.js new file mode 100644 index 0000000..fe43060 --- /dev/null +++ b/build/server/routes/users.controller.js @@ -0,0 +1,4 @@ +"use strict"; +module.exports = function indexController(req, res) { + res.render('users'); +}; From e0a0bb37fb9ee741c5b974f7d735a2c879a29873 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:39:55 -0300 Subject: [PATCH 04/37] routes dir rename to controllers --- app/server/controllers/cart.get.ts | 3 +++ app/server/controllers/index.get.ts | 3 +++ .../product.get.ts} | 6 +++--- .../products.get.ts} | 2 +- app/server/controllers/products.post.ts | 6 ++++++ app/server/controllers/productsIDs.post.ts | 6 ++++++ app/server/controllers/users.get.ts | 3 +++ app/server/controllers/users.post.ts | 13 +++++++++++++ app/server/controllers/users.put.ts | 13 +++++++++++++ app/server/routes/cart.controller.ts | 3 --- app/server/routes/index.controller.ts | 3 --- 11 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 app/server/controllers/cart.get.ts create mode 100644 app/server/controllers/index.get.ts rename app/server/{routes/product.controller.ts => controllers/product.get.ts} (62%) rename app/server/{routes/products.controller.ts => controllers/products.get.ts} (90%) create mode 100644 app/server/controllers/products.post.ts create mode 100644 app/server/controllers/productsIDs.post.ts create mode 100644 app/server/controllers/users.get.ts create mode 100644 app/server/controllers/users.post.ts create mode 100644 app/server/controllers/users.put.ts delete mode 100644 app/server/routes/cart.controller.ts delete mode 100644 app/server/routes/index.controller.ts diff --git a/app/server/controllers/cart.get.ts b/app/server/controllers/cart.get.ts new file mode 100644 index 0000000..d2a58f5 --- /dev/null +++ b/app/server/controllers/cart.get.ts @@ -0,0 +1,3 @@ +module.exports = function indexGet(req: any, res: any) { + res.render('cart'); +} \ No newline at end of file diff --git a/app/server/controllers/index.get.ts b/app/server/controllers/index.get.ts new file mode 100644 index 0000000..f148037 --- /dev/null +++ b/app/server/controllers/index.get.ts @@ -0,0 +1,3 @@ +module.exports = function indexGet(req: any, res: any) { + res.render('index'); +} \ No newline at end of file diff --git a/app/server/routes/product.controller.ts b/app/server/controllers/product.get.ts similarity index 62% rename from app/server/routes/product.controller.ts rename to app/server/controllers/product.get.ts index 14946d7..38df3e2 100644 --- a/app/server/routes/product.controller.ts +++ b/app/server/controllers/product.get.ts @@ -1,11 +1,11 @@ import Product from "../interfaces/Product"; -import API from "../classes/API"; +import ProductsAPI from "../classes/ProductsAPI"; import ProductSpecsComponent from "../components/ProductSpecsComponent"; -module.exports = function productController(req: any, res: any) { - const product: Product = API.getProduct(+req.params.id); +module.exports = function productGet(req: any, res: any) { + const product: Product = new ProductsAPI(req).getProduct(); const config: any = product; config.productSpecs = ProductSpecsComponent(product.caracts); diff --git a/app/server/routes/products.controller.ts b/app/server/controllers/products.get.ts similarity index 90% rename from app/server/routes/products.controller.ts rename to app/server/controllers/products.get.ts index 10f4af9..a290eba 100644 --- a/app/server/routes/products.controller.ts +++ b/app/server/controllers/products.get.ts @@ -7,7 +7,7 @@ import ProductsAPI from "../classes/ProductsAPI"; import ProductsCardComponent from "../components/ProductsCardComponent"; import PaginatorComponent from "../components/PaginatorComponent"; -module.exports = function productsController(req: any, res: any) { +module.exports = function productsGet(req: any, res: any) { const { products, page, maxPage } = new ProductsAPI(req).getProducts(); const productsHTML: htmlString = products diff --git a/app/server/controllers/products.post.ts b/app/server/controllers/products.post.ts new file mode 100644 index 0000000..28cca6d --- /dev/null +++ b/app/server/controllers/products.post.ts @@ -0,0 +1,6 @@ +import ProductsAPI from "../classes/ProductsAPI"; + +module.exports = function productsPost(req: any, res: any) { + const response = new ProductsAPI(req).getProducts() + res.json(response); +} \ No newline at end of file diff --git a/app/server/controllers/productsIDs.post.ts b/app/server/controllers/productsIDs.post.ts new file mode 100644 index 0000000..ff1df34 --- /dev/null +++ b/app/server/controllers/productsIDs.post.ts @@ -0,0 +1,6 @@ +import ProductsAPI from "../classes/ProductsAPI"; + +module.exports = function productsIDsPost(req: any, res: any) { + const response = new ProductsAPI(req).getProductsById() + res.json(response); +} \ No newline at end of file diff --git a/app/server/controllers/users.get.ts b/app/server/controllers/users.get.ts new file mode 100644 index 0000000..7131c04 --- /dev/null +++ b/app/server/controllers/users.get.ts @@ -0,0 +1,3 @@ +module.exports = function usersGet(req: any, res: any) { + res.render('users'); +} \ No newline at end of file diff --git a/app/server/controllers/users.post.ts b/app/server/controllers/users.post.ts new file mode 100644 index 0000000..c080735 --- /dev/null +++ b/app/server/controllers/users.post.ts @@ -0,0 +1,13 @@ +import UsersAPI from "../classes/UsersAPI"; + +module.exports = function usersPost(req: any, res: any) { + const idUser: number = new UsersAPI(req).validateUser(); + if (idUser) { + return res.json({ + id: idUser, + }); + } + res.status(401).json({ + message: "Credenciales Inválidas", + }); +}; diff --git a/app/server/controllers/users.put.ts b/app/server/controllers/users.put.ts new file mode 100644 index 0000000..fcfce9f --- /dev/null +++ b/app/server/controllers/users.put.ts @@ -0,0 +1,13 @@ +import UsersAPI from "../classes/UsersAPI"; + +module.exports = function usersPost(req: any, res: any) { + const idUser: number | null = new UsersAPI(req).setUser(); + if (idUser) { + return res.json({ + id: idUser, + }); + } + res.status(401).send({ + message: "Usuario Existente", + }); +}; diff --git a/app/server/routes/cart.controller.ts b/app/server/routes/cart.controller.ts deleted file mode 100644 index 0efd74e..0000000 --- a/app/server/routes/cart.controller.ts +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function indexController(req: any, res: any) { - res.render('cart'); -} \ No newline at end of file diff --git a/app/server/routes/index.controller.ts b/app/server/routes/index.controller.ts deleted file mode 100644 index 03a301e..0000000 --- a/app/server/routes/index.controller.ts +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function indexController(req: any, res: any) { - res.render('index'); -} \ No newline at end of file From f592b1a3ce9587d891bf7169217240619fa669a8 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:40:21 -0300 Subject: [PATCH 05/37] CSS --- public/css/index.css | 7 ------- public/css/style.css | 17 +++++++++++++++++ public/css/users.css | 6 ++++++ 3 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 public/css/users.css diff --git a/public/css/index.css b/public/css/index.css index 850d795..ed05a96 100644 --- a/public/css/index.css +++ b/public/css/index.css @@ -68,13 +68,6 @@ form h5 { max-width: 600px; } -.contact-card { - margin: 20px; - padding: 20px; - border: 1px solid black; - border-radius: 5px; -} - .input-group { padding-bottom: 20px; } diff --git a/public/css/style.css b/public/css/style.css index cd1146d..c987ab1 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -161,6 +161,23 @@ footer { font-weight: bold; } +.contact-card { + margin: 20px; + padding: 20px 60px; + border: 1px solid black; + border-radius: 5px; +} + +.input-group { + padding: 0px 10px; +} + + +.input-group input { + width: 100%; + padding: 5px 10px; +} + /* @media (min-width: 576px) { } diff --git a/public/css/users.css b/public/css/users.css new file mode 100644 index 0000000..08d3a88 --- /dev/null +++ b/public/css/users.css @@ -0,0 +1,6 @@ +.users-container { + display: flex; + justify-content: space-evenly; + flex-wrap: wrap; + margin-block: 50px; +} \ No newline at end of file From e545e2fb796221cf04919ba29287de39fb5b4044 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:40:47 -0300 Subject: [PATCH 06/37] bundle --- public/js/app.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/js/app.min.js b/public/js/app.min.js index 0d0cc95..16876d8 100644 --- a/public/js/app.min.js +++ b/public/js/app.min.js @@ -1 +1 @@ -(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,u){function a(t){try{c(r.next(t))}catch(t){u(t)}}function i(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,u,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function i(u){return function(i){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(t){return t+"=params[key]"})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),u=r(n(534)),a=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,u.default)(n||1,r)},t}();e.default=a},497:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var u=window.location.pathname.split("/")[1];e.CURRENT_PAGE=u,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var a={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=a,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},455:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.removeFromCart(r),n()}))}},555:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=n(539),u=r(n(483));e.default=function(t){var e=t.target;(0,u.default)(o.SEARCH_PAIR_INPUTS[e.id])}},513:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(483));e.default=function(t){13===t.keyCode&&(0,o.default)(t.target)}},331:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(260));e.default=function(t){document.getElementById("js-closeCart").addEventListener("click",(function(){t.close(),(0,o.default)()}))}},849:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(750)),u=r(n(455)),a=document.getElementsByClassName("reduceOneButton"),i=document.getElementsByClassName("increaseOneButton");e.default=function(t,e){Array.from(a).forEach((function(n){(0,u.default)(n,e,t)})),Array.from(i).forEach((function(n){(0,o.default)(n,e,t)}))}},770:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),u=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(u).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),u=r(n(513)),a=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",u.default),s.addEventListener("keyup",u.default),a.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,u){function a(t){try{c(r.next(t))}catch(t){u(t)}}function i(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,u,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function i(u){return function(i){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,u){function a(t){try{c(r.next(t))}catch(t){u(t)}}function i(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,u,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return u={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(u[Symbol.iterator]=function(){return this}),u;function i(u){return function(i){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,u=t,a=t+1;return 1===t?(++o,++u,++a):t===e&&(--o,--u,--a),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(u,e,t)+"\n "+n(a,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var u=e[r]={exports:{}};return t[r].call(u.exports,u,u.exports,n),u.exports}(266)})(); \ No newline at end of file +(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(t){return t+"=params[key]"})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file From 469956aa07363911f30df04461ac59ede2e4e2ed Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:41:27 -0300 Subject: [PATCH 07/37] API class rename to DataBase --- app/server/classes/API.ts | 43 ------------------------------- app/server/classes/DataBase.ts | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 43 deletions(-) delete mode 100644 app/server/classes/API.ts create mode 100644 app/server/classes/DataBase.ts diff --git a/app/server/classes/API.ts b/app/server/classes/API.ts deleted file mode 100644 index 83cf69c..0000000 --- a/app/server/classes/API.ts +++ /dev/null @@ -1,43 +0,0 @@ -import Product from "../interfaces/Product"; - -const fs = require("fs"); - -const { DATABASE_DIR } = require("../config"); - -const DATABASE_TABLE_PRODUCT: string = DATABASE_DIR + "/products.json"; -const PRODUCTS: Product[] = JSON.parse( - fs.readFileSync(DATABASE_TABLE_PRODUCT, "utf8") -); - -export default class API { - public static getProduct(id: number): Product { - return PRODUCTS.find((product: any) => product.id === id); - } - - public static getProducts( - search: string = "", - min: number = null, - max: number = null - ): Product[] { - const SEARCH_REGEX: RegExp = new RegExp(search); - return PRODUCTS.filter( - (product: Product) => - SEARCH_REGEX.test(product.title.toLowerCase()) && - API.inRange(product.price, min, max) - ); - } - - public static getProductsByIds(IDList: string[] = []): Product[] { - return PRODUCTS.filter((product: Product) => - IDList.includes(String(product.id)) - ); - } - - private static inRange( - elem: number, - min: number = null, - max: number = null - ): boolean { - return (min ? elem >= min : true) && (max ? elem <= max : true); - } -} diff --git a/app/server/classes/DataBase.ts b/app/server/classes/DataBase.ts new file mode 100644 index 0000000..dd937ad --- /dev/null +++ b/app/server/classes/DataBase.ts @@ -0,0 +1,47 @@ +import Filter from "./Filter"; + +const fs = require("fs"); + +const { DATABASE_DIR } = require("../config"); + +export default class DataBase extends Filter { + private table: string; + private readonly tableNames = ["config", "products", "users", "favorites"]; + + constructor(tableName: string) { + super(); + this.table = this.returnTable(tableName); + } + + protected getTable(): any { + return this.table; + } + + protected setTable(tableName: string, tableData: any): void { + fs.writeFileSync(this.getTablePath(tableName), JSON.stringify(tableData)); + } + + protected returnTable(tableName: string): any { + if (this.tableNames.includes(tableName)) { + return JSON.parse(fs.readFileSync(this.getTablePath(tableName), "utf8")); + } + } + + protected getConfig(configEntry: string): any { + return this.returnConfig()[configEntry]; + } + + protected setConfig(configEntry: string, configData: any): void { + const config = this.returnConfig(); + config[configEntry] = configData; + this.setTable("config", config); + } + + private getTablePath(tableName: string): string { + return `${DATABASE_DIR}/${tableName}.json`; + } + + private returnConfig(): any { + return this.returnTable(this.getTablePath("config")); + } +} From 4da0cb6cdc154a219792728735e9364a0146217b Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:43:05 -0300 Subject: [PATCH 08/37] Login and Register Functionalities --- app/client/handlers/loginHandler.ts | 17 ++++++++++++++++ app/client/handlers/registerHandler.ts | 20 +++++++++++++++++++ app/client/listeners/loginRegisterListener.ts | 15 ++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 app/client/handlers/loginHandler.ts create mode 100644 app/client/handlers/registerHandler.ts create mode 100644 app/client/listeners/loginRegisterListener.ts diff --git a/app/client/handlers/loginHandler.ts b/app/client/handlers/loginHandler.ts new file mode 100644 index 0000000..67b3765 --- /dev/null +++ b/app/client/handlers/loginHandler.ts @@ -0,0 +1,17 @@ +import app from "../main"; + +// HTML +const LOGIN_FORM: HTMLFormElement = document.getElementById( + "js-loginForm" +) as HTMLFormElement; + +export default async function loginHandler(): Promise { + const { email, password } = Object.fromEntries( + new FormData(LOGIN_FORM).entries() + ) as { + [index: string]: string; + }; + const response = await app.users.loginUser(email, password); + + return alert(response ? response : "Logueado con Éxito"); +} diff --git a/app/client/handlers/registerHandler.ts b/app/client/handlers/registerHandler.ts new file mode 100644 index 0000000..f019424 --- /dev/null +++ b/app/client/handlers/registerHandler.ts @@ -0,0 +1,20 @@ +import app from "../main"; + +// HTML +const REGISTER_FORM: HTMLFormElement = document.getElementById( + "js-registerForm" +) as HTMLFormElement; + +export default async function registerHandler(): Promise { + const { email, password, passwordRepeat } = Object.fromEntries( + new FormData(REGISTER_FORM).entries() + ) as { [index: string]: string }; + + if (password === passwordRepeat) { + const response = await app.users.registerUser(email, password); + + return alert(response ? response : "Registrado con Éxito"); + } + + alert("Las contraseñas no coinciden."); +} diff --git a/app/client/listeners/loginRegisterListener.ts b/app/client/listeners/loginRegisterListener.ts new file mode 100644 index 0000000..8a9fc3c --- /dev/null +++ b/app/client/listeners/loginRegisterListener.ts @@ -0,0 +1,15 @@ +import loginHandler from "../handlers/loginHandler"; +import registerHandler from "../handlers/registerHandler"; + +// HTML +const LOGIN_FORM_BTN: HTMLElement = document.getElementById("js-loginFormBTN"); +const REGISTER_FORM: HTMLElement = document.getElementById("js-registerForm"); + +// EVENTS +const REGISTER_FORM_BTN_EVENT: string = "click"; +const LOGIN_FORM_BTN_EVENT: string = "click"; + +export default function loginRegisterListener(): void { + LOGIN_FORM_BTN.addEventListener(LOGIN_FORM_BTN_EVENT, loginHandler); + REGISTER_FORM.addEventListener(REGISTER_FORM_BTN_EVENT, registerHandler); +} \ No newline at end of file From dbe84825ce64fd07cf024a752fe9b8bd196df2ce Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:43:55 -0300 Subject: [PATCH 09/37] Filters --- app/server/classes/Filter.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 app/server/classes/Filter.ts diff --git a/app/server/classes/Filter.ts b/app/server/classes/Filter.ts new file mode 100644 index 0000000..a2e5e4a --- /dev/null +++ b/app/server/classes/Filter.ts @@ -0,0 +1,9 @@ +export default class Filter { + protected inRange( + elem: number, + min: number = null, + max: number = null + ): boolean { + return (min ? elem >= min : true) && (max ? elem <= max : true); + } +} From 84c756d2bc025a38e0c31b8c8c4030d9dd66ae20 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:44:43 -0300 Subject: [PATCH 10/37] Users HREF added, CSS, and minor fixes --- views/index.ejs | 1 + views/partials/header.ejs | 1 + views/partials/nav.ejs | 1 + views/partials/side-nav.ejs | 1 + 4 files changed, 4 insertions(+) diff --git a/views/index.ejs b/views/index.ejs index 14d76ca..537a128 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -34,6 +34,7 @@
Mensaje:
+ Enviar diff --git a/views/partials/header.ejs b/views/partials/header.ejs index 9ad53d8..8d7f3da 100644 --- a/views/partials/header.ejs +++ b/views/partials/header.ejs @@ -11,6 +11,7 @@ + Web diff --git a/views/partials/nav.ejs b/views/partials/nav.ejs index 3d270f7..f459ee8 100644 --- a/views/partials/nav.ejs +++ b/views/partials/nav.ejs @@ -3,6 +3,7 @@ Inicio Sobre Nosotros From bffa0036e8ad005490883fdc705cd8bfd0e745ad Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:45:18 -0300 Subject: [PATCH 11/37] User Interface --- app/client/interfaces/User.ts | 5 +++++ app/server/interfaces/User.ts | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 app/client/interfaces/User.ts create mode 100644 app/server/interfaces/User.ts diff --git a/app/client/interfaces/User.ts b/app/client/interfaces/User.ts new file mode 100644 index 0000000..5d58d89 --- /dev/null +++ b/app/client/interfaces/User.ts @@ -0,0 +1,5 @@ +export default interface User { + id: number, + email: string, + password: string +} \ No newline at end of file diff --git a/app/server/interfaces/User.ts b/app/server/interfaces/User.ts new file mode 100644 index 0000000..5d58d89 --- /dev/null +++ b/app/server/interfaces/User.ts @@ -0,0 +1,5 @@ +export default interface User { + id: number, + email: string, + password: string +} \ No newline at end of file From c82b7adcb139fe660c4cb517dc90ec345897c8d5 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:46:17 -0300 Subject: [PATCH 12/37] Client Users support --- app/client/class/Users.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 app/client/class/Users.ts diff --git a/app/client/class/Users.ts b/app/client/class/Users.ts new file mode 100644 index 0000000..4f8a806 --- /dev/null +++ b/app/client/class/Users.ts @@ -0,0 +1,43 @@ +import User from "../interfaces/User"; + +import API from "./API"; +import Router from "./Router"; +import Storage from "./Storage"; + +export default class Users extends Storage { + constructor() { + super("user", { + id: null, + email: "", + password: "", + }); + } + + public async loginUser(email: string, password: string): Promise { + const response = await API.fetchAPI(Router.createURL("/users"), { email, password }); + if (API.isApiError(response)) { + return response.message + } + this.updateStorage({ + id: response.id, + email, + password + }) + } + + public async registerUser(email: string, password: string): Promise { + const response = await API.fetchAPI(Router.createURL("/users"), { email, password }, "PUT"); + if (API.isApiError(response)) { + return response.message + } + this.updateStorage({ + id: response.id, + email, + password + }) + } + + public isLogued(): boolean { + return !!this.getStorage().id; + } +} From 5a2c07f126372cccdf2f25052cc992dfe7e898a0 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:46:47 -0300 Subject: [PATCH 13/37] Users API support --- app/server/classes/UsersAPI.ts | 49 ++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 app/server/classes/UsersAPI.ts diff --git a/app/server/classes/UsersAPI.ts b/app/server/classes/UsersAPI.ts new file mode 100644 index 0000000..4403e50 --- /dev/null +++ b/app/server/classes/UsersAPI.ts @@ -0,0 +1,49 @@ +import User from "../interfaces/User"; +import DataBase from "./DataBase"; + +export default class UsersAPI extends DataBase { + private body: any = {}; + private users: User[]; + + constructor(req: any) { + super("users"); + this.body = req.body; + this.users = this.getTable(); + } + + private getUser(email: string): User { + return this.users.find((user: User) => user.email === email); + } + + private existUser(email: string): boolean { + return !!this.getUser(email); + } + + public setUser(): number | null { + const { email, password } = this.body; + + if (this.existUser(email)) { + return; + } + + const config = this.getConfig("users"); + config.maxID += 1; + this.setConfig("users", config); + + this.users.push({ + email, + password, + id: config.maxID, + }); + + return config.maxID; + } + + public validateUser(): number | null { + const { email, password } = this.body; + const user: User = this.getUser(email); + if (user && user.password === password) { + return user.id; + } + } +} From aeec08fe02cad7f4f3145929f299b3922b68279e Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:47:07 -0300 Subject: [PATCH 14/37] Users path added --- app/server/routes.ts | 53 +++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/app/server/routes.ts b/app/server/routes.ts index ddfbaef..a3f676c 100644 --- a/app/server/routes.ts +++ b/app/server/routes.ts @@ -1,33 +1,40 @@ -import ProductsAPI from "./classes/ProductsAPI"; - const { Router } = require("express"); const router = Router(); // CONTROLLERS -const productsController = require("./routes/products.controller"); -const productController = require("./routes/product.controller"); -const indexController = require("./routes/index.controller"); -const cartController = require("./routes/cart.controller"); +const productsGet = require("./controllers/products.get"); +const productGet = require("./controllers/product.get"); +const indexGet = require("./controllers/index.get"); +const usersGet = require("./controllers/users.get"); +const cartGet = require("./controllers/cart.get"); + +const productsIDsPost = require("./controllers/productsIDs.post"); +const productsPost = require("./controllers/products.post"); +const usersPost = require("./controllers/users.post"); + +const usersPut = require("./controllers/users.put"); + +router.get("/", indexGet); + +router.get("/products/:page", productsGet); +router.get("/products", productsGet); + +router.get("/product/:id", productGet); + +router.get("/users", usersGet); -router.get("/", indexController); -router.get("/products/:page", productsController); -router.get("/products", productsController); -router.get("/product/:id", productController); -router.get("/cart", cartController); +router.get("/cart", cartGet); // POST -router.post("/products/ids", (req: any, res: any) => { - const response = new ProductsAPI(req).getProductsById() - res.json(response); -}); -router.post("/products/:page", (req: any, res: any) => { - const response = new ProductsAPI(req).getProducts() - res.json(response); -}); -router.post("/products", (req: any, res: any) => { - const response = new ProductsAPI(req).getProducts() - res.json(response); -}); +router.post("/products/ids", productsIDsPost); +router.post("/products/:page", productsPost); +router.post("/products", productsPost); + +router.post("/users", usersPost); + + +// PUT +router.put("/users", usersPut); router.use((req: any, res: any) => { From 77dbe180c2fae1ca392609e317386012553255f6 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:47:34 -0300 Subject: [PATCH 15/37] Refactor of ProductsAPI --- app/server/classes/ProductsAPI.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/app/server/classes/ProductsAPI.ts b/app/server/classes/ProductsAPI.ts index db399a8..5623e33 100644 --- a/app/server/classes/ProductsAPI.ts +++ b/app/server/classes/ProductsAPI.ts @@ -1,15 +1,17 @@ import Product from "../interfaces/Product"; -import API from "./API"; +import DataBase from "./DataBase"; -export default class ProductsAPI extends API { +export default class ProductsAPI extends DataBase { private params: any = {}; private body: any = {}; + private products: Product[]; constructor(req: any) { - super(); + super("products"); this.params = req.params; this.body = req.body; + this.products = this.getTable(); } public getProducts(): { @@ -19,12 +21,18 @@ export default class ProductsAPI extends API { } { const { page, min, max } = this.params; const { search } = this.body; - const products: Product[] = API.getProducts(search, min, max); + const SEARCH_REGEX: RegExp = new RegExp(search); + + const products: Product[] = this.products.filter( + (product: Product) => + SEARCH_REGEX.test(product.title.toLowerCase()) && + this.inRange(product.price, min, max) + ); const maxPage: number = Math.ceil(products.length / 10); const currentPage: number = +page || 1; const firstProductIndex: number = (currentPage - 1) * 10; - + return { products: products.slice(firstProductIndex, firstProductIndex + 10), maxPage, @@ -33,6 +41,13 @@ export default class ProductsAPI extends API { } public getProductsById(): Product[] { - return API.getProductsByIds(this.body.IDList); + return this.products.filter((product: Product) => + this.body.IDList.includes(String(product.id)) + ); + } + + public getProduct(): Product { + const { id } = this.params; + return this.products.find((product: any) => product.id === id); } -} \ No newline at end of file +} From 2ed37c61d863d50482539e719069ef98aa90dc64 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:47:54 -0300 Subject: [PATCH 16/37] API more general --- app/client/class/API.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/app/client/class/API.ts b/app/client/class/API.ts index a086ddc..c949205 100644 --- a/app/client/class/API.ts +++ b/app/client/class/API.ts @@ -9,17 +9,22 @@ import apiErrorHandler from "../errors/apiErrorHandler"; export default abstract class API { public static async fetchAPI( url: string, - data?: object - ): Promise { - return await fetch(url, { - method: "POST", + data?: object, + method: string = "POST" + ): Promise { + const response = await fetch(url, { + method, headers: { "Content-Type": "application/json", }, - body: JSON.stringify(data) - }) - .then((e) => e.json()) - .then((res) => (Object.keys(res).length === 0 ? API_ERROR : res)); + body: JSON.stringify(data), + }); + const responseJson = await response.json(); + + if (response.ok) { + return Object.keys(responseJson).length === 0 ? API_ERROR : responseJson; + } + return (responseJson as any).message; } /** @@ -27,7 +32,7 @@ export default abstract class API { * @param apiResponse An API method return * @returns if the api is or not an Error */ - public static isApiError(apiResponse: Product[] | apiError | Product): boolean { + public static isApiError(apiResponse: any | apiError): boolean { if (typeof apiResponse === "string") { apiErrorHandler("Ha ocurrido un error."); return true; From 74411fa8dd94501416a7ec21727f7be07b40da84 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:48:15 -0300 Subject: [PATCH 17/37] Users Listeners support --- app/client/class/App.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/client/class/App.ts b/app/client/class/App.ts index 960325d..53171de 100644 --- a/app/client/class/App.ts +++ b/app/client/class/App.ts @@ -7,6 +7,7 @@ import shopListener from "../listeners/shopListener"; // CLASSES import Favorites from "./Favorites"; +import Users from "./Users"; import Cart from "./Cart"; import UI from "./UI"; @@ -14,10 +15,12 @@ import UI from "./UI"; import updateQuantityProducts from "../scripts/updateQuantityProducts"; import loadTable from "../scripts/loadTable"; import { CURRENT_PAGE } from "../config"; +import loginRegisterListener from "../listeners/loginRegisterListener"; export default class App { public ui: UI; public cart: Cart; + public users: Users; public favorites: Favorites; private PREPARE: { [index: string]: string; @@ -25,12 +28,14 @@ export default class App { products: "productsPrepare", product: "productPrepare", cart: "cartPrepare", + users: "usersPrepare" }; constructor(HTML_APP: HTMLElement) { this.ui = new UI(HTML_APP); this.cart = new Cart(); this.favorites = new Favorites(); + this.users = new Users(); } /** @@ -70,4 +75,11 @@ export default class App { closeCartListener(this.cart); loadTable(this.cart); } + + /** + * Loads all listeners for Users. + */ + private usersPrepare(): void { + loginRegisterListener(); + } } From 7e915f9ca3658ed00b2e85e821338c57e813a0dd Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:49:28 -0300 Subject: [PATCH 18/37] Saves only IDs now --- app/client/class/Cart.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/client/class/Cart.ts b/app/client/class/Cart.ts index 407705d..cd882bf 100644 --- a/app/client/class/Cart.ts +++ b/app/client/class/Cart.ts @@ -1,4 +1,5 @@ import CartStructure from "../interfaces/CartStructure"; +import CartProduct from "../interfaces/CartProduct"; import { cartProductsList } from "../types/cart"; @@ -6,7 +7,6 @@ import Storage from "./Storage"; import { SS_CART } from "../config"; import cartErrorHandler from "../errors/cartErrorHandler"; -import CartProduct from "../interfaces/CartProduct"; export default class Cart extends Storage { private products: any = []; From 289745b20a299a98fb711fb3eedc5868a6c804f3 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 13:49:51 -0300 Subject: [PATCH 19/37] Listen to API --- app/client/listeners/favoritesListener.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/client/listeners/favoritesListener.ts b/app/client/listeners/favoritesListener.ts index 50b3d03..bba823d 100644 --- a/app/client/listeners/favoritesListener.ts +++ b/app/client/listeners/favoritesListener.ts @@ -10,6 +10,9 @@ const SEARCH_INPUT_S_EVENT: string = "keyup"; export default function favoritesListener(): void { Array.from(FAVORITES_ICONS).forEach((favorites_icon: Element): void => { favorites_icon.addEventListener(SEARCH_INPUT_S_EVENT, (e) => { + if (!app.users.isLogued()) { + return alert("Necesitas estar Logueado!"); + } const productID: number = +(favorites_icon as HTMLElement).dataset.id; app.favorites.handleFavorite(productID); }); From e03177eca4a3d076863becd7fad9baee37254547 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 15:04:52 -0300 Subject: [PATCH 20/37] bundle --- build/client/class/Users.js | 3 +++ build/client/handlers/loginHandler.js | 6 +++--- build/client/handlers/registerHandler.js | 4 ++-- build/client/listeners/favoritesListener.js | 3 +++ build/server/classes/DataBase.js | 2 +- build/server/classes/ProductsAPI.js | 2 +- build/server/classes/UsersAPI.js | 2 +- public/js/app.min.js | 2 +- 8 files changed, 15 insertions(+), 9 deletions(-) diff --git a/build/client/class/Users.js b/build/client/class/Users.js index 0256cf4..0840ff1 100644 --- a/build/client/class/Users.js +++ b/build/client/class/Users.js @@ -108,6 +108,9 @@ var Users = /** @class */ (function (_super) { }); }); }; + Users.prototype.isLogued = function () { + return !!this.getStorage().id; + }; return Users; }(Storage_1.default)); exports.default = Users; diff --git a/build/client/handlers/loginHandler.js b/build/client/handlers/loginHandler.js index 97131e9..fca3033 100644 --- a/build/client/handlers/loginHandler.js +++ b/build/client/handlers/loginHandler.js @@ -41,14 +41,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); var main_1 = __importDefault(require("../main")); // HTML +var LOGIN_FORM = document.getElementById("js-loginForm"); function loginHandler() { return __awaiter(this, void 0, void 0, function () { - var LOGIN_FORM, _a, email, password, response; + var _a, email, password, response; return __generator(this, function (_b) { switch (_b.label) { case 0: - LOGIN_FORM = new FormData(document.getElementById("js-loginForm")); - _a = Object.fromEntries(LOGIN_FORM.entries()), email = _a.email, password = _a.password; + _a = Object.fromEntries(new FormData(LOGIN_FORM).entries()), email = _a.email, password = _a.password; return [4 /*yield*/, main_1.default.users.loginUser(email, password)]; case 1: response = _b.sent(); diff --git a/build/client/handlers/registerHandler.js b/build/client/handlers/registerHandler.js index ed9a10e..8d4021b 100644 --- a/build/client/handlers/registerHandler.js +++ b/build/client/handlers/registerHandler.js @@ -41,14 +41,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); var main_1 = __importDefault(require("../main")); // HTML -var REGISTER_FORM = new FormData(document.getElementById("js-registerForm")); +var REGISTER_FORM = document.getElementById("js-registerForm"); function registerHandler() { return __awaiter(this, void 0, void 0, function () { var _a, email, password, passwordRepeat, response; return __generator(this, function (_b) { switch (_b.label) { case 0: - _a = Object.fromEntries(REGISTER_FORM.entries()), email = _a.email, password = _a.password, passwordRepeat = _a.passwordRepeat; + _a = Object.fromEntries(new FormData(REGISTER_FORM).entries()), email = _a.email, password = _a.password, passwordRepeat = _a.passwordRepeat; if (!(password === passwordRepeat)) return [3 /*break*/, 2]; return [4 /*yield*/, main_1.default.users.registerUser(email, password)]; case 1: diff --git a/build/client/listeners/favoritesListener.js b/build/client/listeners/favoritesListener.js index 272aa96..02a4313 100644 --- a/build/client/listeners/favoritesListener.js +++ b/build/client/listeners/favoritesListener.js @@ -11,6 +11,9 @@ var SEARCH_INPUT_S_EVENT = "keyup"; function favoritesListener() { Array.from(FAVORITES_ICONS).forEach(function (favorites_icon) { favorites_icon.addEventListener(SEARCH_INPUT_S_EVENT, function (e) { + if (!main_1.default.users.isLogued()) { + return alert("Necesitas estar Logueado!"); + } var productID = +favorites_icon.dataset.id; main_1.default.favorites.handleFavorite(productID); }); diff --git a/build/server/classes/DataBase.js b/build/server/classes/DataBase.js index 17ae035..5324cbd 100644 --- a/build/server/classes/DataBase.js +++ b/build/server/classes/DataBase.js @@ -52,7 +52,7 @@ var DataBase = /** @class */ (function (_super) { return DATABASE_DIR + "/" + tableName + ".json"; }; DataBase.prototype.returnConfig = function () { - return this.returnTable(this.getTablePath("config")); + return this.returnTable("config"); }; return DataBase; }(Filter_1.default)); diff --git a/build/server/classes/ProductsAPI.js b/build/server/classes/ProductsAPI.js index d30b2f3..5a549d3 100644 --- a/build/server/classes/ProductsAPI.js +++ b/build/server/classes/ProductsAPI.js @@ -56,7 +56,7 @@ var ProductsAPI = /** @class */ (function (_super) { }; ProductsAPI.prototype.getProduct = function () { var id = this.params.id; - return this.products.find(function (product) { return product.id === id; }); + return this.products.find(function (product) { return product.id === +id; }); }; return ProductsAPI; }(DataBase_1.default)); diff --git a/build/server/classes/UsersAPI.js b/build/server/classes/UsersAPI.js index ff2dc0a..e15c25d 100644 --- a/build/server/classes/UsersAPI.js +++ b/build/server/classes/UsersAPI.js @@ -47,10 +47,10 @@ var UsersAPI = /** @class */ (function (_super) { password: password, id: config.maxID, }); + this.setTable("users", this.users); return config.maxID; }; UsersAPI.prototype.validateUser = function () { - console.log(this.body); var _a = this.body, email = _a.email, password = _a.password; var user = this.getUser(email); if (user && user.password === password) { diff --git a/public/js/app.min.js b/public/js/app.min.js index 16876d8..a8aefd6 100644 --- a/public/js/app.min.js +++ b/public/js/app.min.js @@ -1 +1 @@ -(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(t){return t+"=params[key]"})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file +(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(t){return t+"=params[key]"})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file From 6c1d380846da1192104f8bddad3b8045b6c6d0fb Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 15:05:24 -0300 Subject: [PATCH 21/37] Database Tests --- database/config.json | 6 +----- database/users.json | 13 ++++++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/database/config.json b/database/config.json index 4c7c80a..c1f210d 100644 --- a/database/config.json +++ b/database/config.json @@ -1,5 +1 @@ -{ - "users": { - "maxID": 1 - } -} \ No newline at end of file +{"users":{"maxID":3}} \ No newline at end of file diff --git a/database/users.json b/database/users.json index b75c5cc..071d408 100644 --- a/database/users.json +++ b/database/users.json @@ -1,6 +1,9 @@ [{ - "id": 1, - "email": "gonzalobordon02@hotmail.com", - "password": "123" - } -] \ No newline at end of file + "id": 1, + "email": "gonzalobordon02@hotmail.com", + "password": "123" +}, { + "email": "xdxd", + "password": "123", + "id": 3 +}] \ No newline at end of file From d7635eff54d78494faf5f7ae26da0ce9f0c4a4e8 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 15:06:02 -0300 Subject: [PATCH 22/37] Fix Errors on Register & getProduct (string -> number) --- app/server/classes/DataBase.ts | 2 +- app/server/classes/ProductsAPI.ts | 2 +- app/server/classes/UsersAPI.ts | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/server/classes/DataBase.ts b/app/server/classes/DataBase.ts index dd937ad..9f8c7af 100644 --- a/app/server/classes/DataBase.ts +++ b/app/server/classes/DataBase.ts @@ -42,6 +42,6 @@ export default class DataBase extends Filter { } private returnConfig(): any { - return this.returnTable(this.getTablePath("config")); + return this.returnTable("config"); } } diff --git a/app/server/classes/ProductsAPI.ts b/app/server/classes/ProductsAPI.ts index 5623e33..279e57c 100644 --- a/app/server/classes/ProductsAPI.ts +++ b/app/server/classes/ProductsAPI.ts @@ -48,6 +48,6 @@ export default class ProductsAPI extends DataBase { public getProduct(): Product { const { id } = this.params; - return this.products.find((product: any) => product.id === id); + return this.products.find((product: any) => product.id === +id); } } diff --git a/app/server/classes/UsersAPI.ts b/app/server/classes/UsersAPI.ts index 4403e50..32184c0 100644 --- a/app/server/classes/UsersAPI.ts +++ b/app/server/classes/UsersAPI.ts @@ -36,6 +36,8 @@ export default class UsersAPI extends DataBase { id: config.maxID, }); + this.setTable("users", this.users); + return config.maxID; } From 87a8a86add62e094a08d0d7a0cb14b870c7477c5 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 15:15:11 -0300 Subject: [PATCH 23/37] Ignore --- .gitignore | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ffc786d..c2c7421 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -/js/ -/node_modules/ \ No newline at end of file +js/ +node_modules/ +build/ +public/js/ \ No newline at end of file From f8ca37c2a34352c0b1c83d1c602d76c844000512 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Fri, 15 Oct 2021 15:15:49 -0300 Subject: [PATCH 24/37] mend --- .gitignore | 1 - app/client/class/Router.ts | 2 +- app/client/scripts/sendSearchRequest.ts | 3 ++- app/server/classes/ProductsAPI.ts | 4 +++- build/client/class/Router.js | 2 +- build/client/scripts/sendSearchRequest.js | 3 ++- build/server/classes/ProductsAPI.js | 5 ++++- public/js/app.min.js | 2 +- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index c2c7421..9083d2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -js/ node_modules/ build/ public/js/ \ No newline at end of file diff --git a/app/client/class/Router.ts b/app/client/class/Router.ts index 925d355..15f5844 100644 --- a/app/client/class/Router.ts +++ b/app/client/class/Router.ts @@ -28,7 +28,7 @@ export default class Router { return ( "?" + Object.keys(params) - .map((key) => `${key}=params[key]`) + .map((key) => `${key}=${params[key]}`) .join("&") ); } diff --git a/app/client/scripts/sendSearchRequest.ts b/app/client/scripts/sendSearchRequest.ts index ea78ccf..55b1eb4 100644 --- a/app/client/scripts/sendSearchRequest.ts +++ b/app/client/scripts/sendSearchRequest.ts @@ -5,8 +5,9 @@ export default function sendSearchRequest( input: HTMLInputElement ): void { //if (CURRENT_PAGE !== "products") { + console.log(input.value) return Router.followWithParams("/products", { - "search": input.value + search: input.value }) //} } \ No newline at end of file diff --git a/app/server/classes/ProductsAPI.ts b/app/server/classes/ProductsAPI.ts index 279e57c..c95de1a 100644 --- a/app/server/classes/ProductsAPI.ts +++ b/app/server/classes/ProductsAPI.ts @@ -5,12 +5,14 @@ import DataBase from "./DataBase"; export default class ProductsAPI extends DataBase { private params: any = {}; private body: any = {}; + private query: any = {}; private products: Product[]; constructor(req: any) { super("products"); this.params = req.params; this.body = req.body; + this.query = req.query; this.products = this.getTable(); } @@ -20,7 +22,7 @@ export default class ProductsAPI extends DataBase { page: number; } { const { page, min, max } = this.params; - const { search } = this.body; + const { search } = this.query; const SEARCH_REGEX: RegExp = new RegExp(search); const products: Product[] = this.products.filter( diff --git a/build/client/class/Router.js b/build/client/class/Router.js index c8b8cf4..a02ddd1 100644 --- a/build/client/class/Router.js +++ b/build/client/class/Router.js @@ -18,7 +18,7 @@ var Router = /** @class */ (function () { Router.stringfyParams = function (params) { return ("?" + Object.keys(params) - .map(function (key) { return key + "=params[key]"; }) + .map(function (key) { return key + "=" + params[key]; }) .join("&")); }; return Router; diff --git a/build/client/scripts/sendSearchRequest.js b/build/client/scripts/sendSearchRequest.js index 2696acd..34931dc 100644 --- a/build/client/scripts/sendSearchRequest.js +++ b/build/client/scripts/sendSearchRequest.js @@ -7,8 +7,9 @@ var Router_1 = __importDefault(require("../class/Router")); //import { CURRENT_PAGE } from "../config"; function sendSearchRequest(input) { //if (CURRENT_PAGE !== "products") { + console.log(input.value); return Router_1.default.followWithParams("/products", { - "search": input.value + search: input.value }); //} } diff --git a/build/server/classes/ProductsAPI.js b/build/server/classes/ProductsAPI.js index 5a549d3..9af2bd5 100644 --- a/build/server/classes/ProductsAPI.js +++ b/build/server/classes/ProductsAPI.js @@ -25,16 +25,19 @@ var ProductsAPI = /** @class */ (function (_super) { var _this = _super.call(this, "products") || this; _this.params = {}; _this.body = {}; + _this.query = {}; _this.params = req.params; _this.body = req.body; + _this.query = req.query; _this.products = _this.getTable(); return _this; } ProductsAPI.prototype.getProducts = function () { var _this = this; var _a = this.params, page = _a.page, min = _a.min, max = _a.max; - var search = this.body.search; + var search = this.query.search; var SEARCH_REGEX = new RegExp(search); + console.log(this.body, this.params, this.query); var products = this.products.filter(function (product) { return SEARCH_REGEX.test(product.title.toLowerCase()) && _this.inRange(product.price, min, max); diff --git a/public/js/app.min.js b/public/js/app.min.js index a8aefd6..0464cf8 100644 --- a/public/js/app.min.js +++ b/public/js/app.min.js @@ -1 +1 @@ -(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(t){return t+"=params[key]"})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file +(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(e){return e+"="+t[e]})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file From 13ff8926da14c768a679080aa5355ae56c4cb144 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:06:06 -0300 Subject: [PATCH 25/37] config --- .gitignore | 4 ++-- package.json | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 9083d2e..8a909e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules/ -build/ -public/js/ \ No newline at end of file +build/**/* +public/js/app.min.js \ No newline at end of file diff --git a/package.json b/package.json index 4ebafb5..4c40a65 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "start": "nodemon build/server/app.js" + "start": "nodemon build/server/app.js", + "runbuild": "tsc -b app/server/ && node build/server/app.js" }, "keywords": [], "author": "", From 09aec14b28d52cb06b52c58c1ea753e33c7d71aa Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:10:14 -0300 Subject: [PATCH 26/37] bundle --- build/client/class/API.js | 87 ------------- build/client/class/App.js | 75 ----------- build/client/class/Cart.js | 101 --------------- build/client/class/Favorites.js | 98 --------------- build/client/class/Router.js | 26 ---- build/client/class/Storage.js | 21 ---- build/client/class/UI.js | 29 ----- build/client/class/Users.js | 116 ------------------ build/client/components/CartEntryComponent.js | 7 -- build/client/components/CartTableComponent.js | 17 --- .../components/FavoritesEntryComponent.js | 7 -- .../components/FavoritesTableComponent.js | 12 -- build/client/components/PaginatorComponent.js | 17 --- .../components/ProductsCardComponent.js | 7 -- build/client/config.js | 30 ----- build/client/errors/apiErrorHandler.js | 7 -- build/client/errors/cartErrorHandler.js | 6 - .../handlers/increaseOneButtonHandler.js | 15 --- build/client/handlers/loginHandler.js | 60 --------- .../client/handlers/reduceOneButtonHandler.js | 15 --- build/client/handlers/registerHandler.js | 64 ---------- build/client/handlers/searchButtonHandler.js | 12 -- build/client/handlers/searchInputHandler.js | 12 -- build/client/interfaces/ApiProduct.js | 2 - build/client/interfaces/BasicProduct.js | 2 - build/client/interfaces/CartProduct.js | 2 - build/client/interfaces/CartStructure.js | 2 - build/client/interfaces/Product.js | 2 - build/client/interfaces/SearchURLParams.js | 2 - build/client/interfaces/User.js | 2 - build/client/listeners/closeCartListener.js | 19 --- build/client/listeners/favoritesListener.js | 22 ---- .../listeners/lastMomentShopListener.js | 19 --- .../client/listeners/loginRegisterListener.js | 18 --- build/client/listeners/menuHandlerListener.js | 17 --- build/client/listeners/paginatorListener.js | 19 --- build/client/listeners/searchsListener.js | 24 ---- build/client/listeners/shopListener.js | 62 ---------- build/client/main.js | 10 -- build/client/scripts/getIdProductFromTable.js | 8 -- build/client/scripts/loadTable.js | 107 ---------------- build/client/scripts/sendSearchRequest.js | 16 --- .../client/scripts/updateQuantityProducts.js | 7 -- build/client/types/api.js | 2 - build/client/types/cart.js | 2 - build/client/types/favorites.js | 2 - build/client/types/functions.js | 2 - build/client/types/html.js | 2 - build/client/types/products.js | 2 - build/client/types/search.js | 2 - build/server/api/products.api.js | 23 ---- build/server/app.js | 19 --- build/server/classes/API.js | 36 ------ build/server/classes/Config.js | 35 ------ build/server/classes/DataBase.js | 59 --------- build/server/classes/Filter.js | 13 -- build/server/classes/ProductsAPI.js | 66 ---------- build/server/classes/UsersAPI.js | 62 ---------- build/server/client/types/cart.js | 2 - build/server/client/types/html.js | 2 - build/server/components/CartEntryComponent.js | 7 -- build/server/components/CartTableComponent.js | 12 -- .../components/FavoritesEntryComponent.js | 7 -- .../components/FavoritesTableComponent.js | 12 -- build/server/components/PaginatorComponent.js | 29 ----- .../server/components/ProductSpecComponent.js | 6 - .../components/ProductSpecsComponent.js | 15 --- .../components/ProductsCardComponent.js | 7 -- build/server/config.js | 19 --- build/server/controllers/cart.get.js | 4 - build/server/controllers/index.get.js | 4 - build/server/controllers/product.get.js | 14 --- build/server/controllers/products.get.js | 19 --- build/server/controllers/products.post.js | 10 -- build/server/controllers/productsIDs.post.js | 10 -- build/server/controllers/users.get.js | 4 - build/server/controllers/users.post.js | 17 --- build/server/controllers/users.put.js | 17 --- build/server/interfaces/BasicProduct.js | 2 - build/server/interfaces/CartProduct.js | 2 - build/server/interfaces/CartStructure.js | 7 -- build/server/interfaces/Product.js | 2 - build/server/interfaces/SearchURLParams.js | 8 -- build/server/interfaces/User.js | 2 - build/server/routes.js | 30 ----- build/server/routes/cart.controller.js | 4 - build/server/routes/index.controller.js | 4 - build/server/routes/product.controller.js | 14 --- build/server/routes/products.controller.js | 19 --- build/server/routes/users.controller.js | 4 - build/server/types/api.js | 2 - build/server/types/cart.js | 2 - build/server/types/favorites.js | 2 - build/server/types/functions.js | 2 - build/server/types/html.js | 2 - build/server/types/products.js | 2 - build/server/types/search.js | 2 - 97 files changed, 1859 deletions(-) delete mode 100644 build/client/class/API.js delete mode 100644 build/client/class/App.js delete mode 100644 build/client/class/Cart.js delete mode 100644 build/client/class/Favorites.js delete mode 100644 build/client/class/Router.js delete mode 100644 build/client/class/Storage.js delete mode 100644 build/client/class/UI.js delete mode 100644 build/client/class/Users.js delete mode 100644 build/client/components/CartEntryComponent.js delete mode 100644 build/client/components/CartTableComponent.js delete mode 100644 build/client/components/FavoritesEntryComponent.js delete mode 100644 build/client/components/FavoritesTableComponent.js delete mode 100644 build/client/components/PaginatorComponent.js delete mode 100644 build/client/components/ProductsCardComponent.js delete mode 100644 build/client/config.js delete mode 100644 build/client/errors/apiErrorHandler.js delete mode 100644 build/client/errors/cartErrorHandler.js delete mode 100644 build/client/handlers/increaseOneButtonHandler.js delete mode 100644 build/client/handlers/loginHandler.js delete mode 100644 build/client/handlers/reduceOneButtonHandler.js delete mode 100644 build/client/handlers/registerHandler.js delete mode 100644 build/client/handlers/searchButtonHandler.js delete mode 100644 build/client/handlers/searchInputHandler.js delete mode 100644 build/client/interfaces/ApiProduct.js delete mode 100644 build/client/interfaces/BasicProduct.js delete mode 100644 build/client/interfaces/CartProduct.js delete mode 100644 build/client/interfaces/CartStructure.js delete mode 100644 build/client/interfaces/Product.js delete mode 100644 build/client/interfaces/SearchURLParams.js delete mode 100644 build/client/interfaces/User.js delete mode 100644 build/client/listeners/closeCartListener.js delete mode 100644 build/client/listeners/favoritesListener.js delete mode 100644 build/client/listeners/lastMomentShopListener.js delete mode 100644 build/client/listeners/loginRegisterListener.js delete mode 100644 build/client/listeners/menuHandlerListener.js delete mode 100644 build/client/listeners/paginatorListener.js delete mode 100644 build/client/listeners/searchsListener.js delete mode 100644 build/client/listeners/shopListener.js delete mode 100644 build/client/main.js delete mode 100644 build/client/scripts/getIdProductFromTable.js delete mode 100644 build/client/scripts/loadTable.js delete mode 100644 build/client/scripts/sendSearchRequest.js delete mode 100644 build/client/scripts/updateQuantityProducts.js delete mode 100644 build/client/types/api.js delete mode 100644 build/client/types/cart.js delete mode 100644 build/client/types/favorites.js delete mode 100644 build/client/types/functions.js delete mode 100644 build/client/types/html.js delete mode 100644 build/client/types/products.js delete mode 100644 build/client/types/search.js delete mode 100644 build/server/api/products.api.js delete mode 100644 build/server/app.js delete mode 100644 build/server/classes/API.js delete mode 100644 build/server/classes/Config.js delete mode 100644 build/server/classes/DataBase.js delete mode 100644 build/server/classes/Filter.js delete mode 100644 build/server/classes/ProductsAPI.js delete mode 100644 build/server/classes/UsersAPI.js delete mode 100644 build/server/client/types/cart.js delete mode 100644 build/server/client/types/html.js delete mode 100644 build/server/components/CartEntryComponent.js delete mode 100644 build/server/components/CartTableComponent.js delete mode 100644 build/server/components/FavoritesEntryComponent.js delete mode 100644 build/server/components/FavoritesTableComponent.js delete mode 100644 build/server/components/PaginatorComponent.js delete mode 100644 build/server/components/ProductSpecComponent.js delete mode 100644 build/server/components/ProductSpecsComponent.js delete mode 100644 build/server/components/ProductsCardComponent.js delete mode 100644 build/server/config.js delete mode 100644 build/server/controllers/cart.get.js delete mode 100644 build/server/controllers/index.get.js delete mode 100644 build/server/controllers/product.get.js delete mode 100644 build/server/controllers/products.get.js delete mode 100644 build/server/controllers/products.post.js delete mode 100644 build/server/controllers/productsIDs.post.js delete mode 100644 build/server/controllers/users.get.js delete mode 100644 build/server/controllers/users.post.js delete mode 100644 build/server/controllers/users.put.js delete mode 100644 build/server/interfaces/BasicProduct.js delete mode 100644 build/server/interfaces/CartProduct.js delete mode 100644 build/server/interfaces/CartStructure.js delete mode 100644 build/server/interfaces/Product.js delete mode 100644 build/server/interfaces/SearchURLParams.js delete mode 100644 build/server/interfaces/User.js delete mode 100644 build/server/routes.js delete mode 100644 build/server/routes/cart.controller.js delete mode 100644 build/server/routes/index.controller.js delete mode 100644 build/server/routes/product.controller.js delete mode 100644 build/server/routes/products.controller.js delete mode 100644 build/server/routes/users.controller.js delete mode 100644 build/server/types/api.js delete mode 100644 build/server/types/cart.js delete mode 100644 build/server/types/favorites.js delete mode 100644 build/server/types/functions.js delete mode 100644 build/server/types/html.js delete mode 100644 build/server/types/products.js delete mode 100644 build/server/types/search.js diff --git a/build/client/class/API.js b/build/client/class/API.js deleted file mode 100644 index f4b4b6c..0000000 --- a/build/client/class/API.js +++ /dev/null @@ -1,87 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -var apiErrorHandler_1 = __importDefault(require("../errors/apiErrorHandler")); -var API = /** @class */ (function () { - function API() { - } - API.fetchAPI = function (url, data, method) { - if (method === void 0) { method = "POST"; } - return __awaiter(this, void 0, void 0, function () { - var response, responseJson; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, fetch(url, { - method: method, - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify(data), - })]; - case 1: - response = _a.sent(); - return [4 /*yield*/, response.json()]; - case 2: - responseJson = _a.sent(); - if (response.ok) { - return [2 /*return*/, Object.keys(responseJson).length === 0 ? config_1.API_ERROR : responseJson]; - } - return [2 /*return*/, responseJson.message]; - } - }); - }); - }; - /** - * - * @param apiResponse An API method return - * @returns if the api is or not an Error - */ - API.isApiError = function (apiResponse) { - if (typeof apiResponse === "string") { - (0, apiErrorHandler_1.default)("Ha ocurrido un error."); - return true; - } - return false; - }; - return API; -}()); -exports.default = API; diff --git a/build/client/class/App.js b/build/client/class/App.js deleted file mode 100644 index 86a798f..0000000 --- a/build/client/class/App.js +++ /dev/null @@ -1,75 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// LISTENERES -var menuHandlerListener_1 = __importDefault(require("../listeners/menuHandlerListener")); -var closeCartListener_1 = __importDefault(require("../listeners/closeCartListener")); -var paginatorListener_1 = __importDefault(require("../listeners/paginatorListener")); -var searchsListener_1 = __importDefault(require("../listeners/searchsListener")); -var shopListener_1 = __importDefault(require("../listeners/shopListener")); -// CLASSES -var Favorites_1 = __importDefault(require("./Favorites")); -var Users_1 = __importDefault(require("./Users")); -var Cart_1 = __importDefault(require("./Cart")); -var UI_1 = __importDefault(require("./UI")); -// SCRIPTS -var updateQuantityProducts_1 = __importDefault(require("../scripts/updateQuantityProducts")); -var loadTable_1 = __importDefault(require("../scripts/loadTable")); -var config_1 = require("../config"); -var loginRegisterListener_1 = __importDefault(require("../listeners/loginRegisterListener")); -var App = /** @class */ (function () { - function App(HTML_APP) { - this.PREPARE = { - products: "productsPrepare", - product: "productPrepare", - cart: "cartPrepare", - users: "usersPrepare" - }; - this.ui = new UI_1.default(HTML_APP); - this.cart = new Cart_1.default(); - this.favorites = new Favorites_1.default(); - this.users = new Users_1.default(); - } - /** - * Loads and runs the needed listeners. - */ - App.prototype.fileLoader = function () { - var preparative = this.PREPARE[config_1.CURRENT_PAGE]; - if (preparative) { - this[preparative](); - } - (0, updateQuantityProducts_1.default)(this.cart.getQuantityProducts()); - (0, menuHandlerListener_1.default)(); - (0, searchsListener_1.default)(); - }; - /** - * Loads all listeners for Products. - */ - App.prototype.productsPrepare = function () { - (0, paginatorListener_1.default)(); - (0, shopListener_1.default)(this.cart); - }; - /** - * Loads all listeners for Product. - */ - App.prototype.productPrepare = function () { - (0, shopListener_1.default)(this.cart); - }; - /** - * Loads all listeners for Cart. - */ - App.prototype.cartPrepare = function () { - (0, closeCartListener_1.default)(this.cart); - (0, loadTable_1.default)(this.cart); - }; - /** - * Loads all listeners for Users. - */ - App.prototype.usersPrepare = function () { - (0, loginRegisterListener_1.default)(); - }; - return App; -}()); -exports.default = App; diff --git a/build/client/class/Cart.js b/build/client/class/Cart.js deleted file mode 100644 index f953260..0000000 --- a/build/client/class/Cart.js +++ /dev/null @@ -1,101 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Storage_1 = __importDefault(require("./Storage")); -var config_1 = require("../config"); -var cartErrorHandler_1 = __importDefault(require("../errors/cartErrorHandler")); -var Cart = /** @class */ (function (_super) { - __extends(Cart, _super); - function Cart() { - var _this = _super.call(this, config_1.SS_CART, { - products: {}, - quantityProducts: 0, - }) || this; - _this.products = []; - return _this; - } - Cart.prototype.addToCart = function (id) { - var _a = this.getStorage(), products = _a.products, quantityProducts = _a.quantityProducts; - if (!products[id]) { - products[id] = 0; - } - products[id] += 1; - this.updateStorage({ - products: products, - quantityProducts: quantityProducts + 1, - }); - }; - Cart.prototype.removeFromCart = function (id) { - var _a = this.getStorage(), products = _a.products, quantityProducts = _a.quantityProducts; - if (products[id] === 1) - delete products[id]; - else - products[id] -= 1; - this.updateStorage({ - products: products, - quantityProducts: quantityProducts - 1, - }); - }; - Cart.prototype.close = function () { - this.deleteStorage(); - alert("Imagina que la compra finalizó"); - }; - /** - * @return if the Cart is empty or not. - */ - Cart.prototype.isEmpty = function () { - return this.getProducts().length === 0; - }; - /** - * @return if the Cart is empty or not. - */ - Cart.prototype.isCartError = function () { - if (this.isEmpty()) { - (0, cartErrorHandler_1.default)("El carrito está vacio."); - return true; - } - return false; - }; - /** - * @return the ID's of the products on cart. - */ - Cart.prototype.getProductsIDs = function () { - var _a; - return ((_a = this.getStorage()) === null || _a === void 0 ? void 0 : _a.products) || {}; - }; - /** - * @return the ID's of the products on cart. - */ - Cart.prototype.setProducts = function (products) { - this.products = products; - }; - /** - * @return the products on cart. - */ - Cart.prototype.getProducts = function () { - return this.products; - }; - Cart.prototype.getQuantityProducts = function () { - var _a; - return ((_a = this.getStorage()) === null || _a === void 0 ? void 0 : _a.quantityProducts) || 0; - }; - return Cart; -}(Storage_1.default)); -exports.default = Cart; diff --git a/build/client/class/Favorites.js b/build/client/class/Favorites.js deleted file mode 100644 index 10d8b54..0000000 --- a/build/client/class/Favorites.js +++ /dev/null @@ -1,98 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Storage_1 = __importDefault(require("./Storage")); -var config_1 = require("../config"); -var Favorites = /** @class */ (function (_super) { - __extends(Favorites, _super); - function Favorites() { - return _super.call(this, config_1.SS_FAVORITES, []) || this; - } - Favorites.prototype.addToFavorites = function (productID) { - var favoritesSet = new Set(this.getStorage()).add(productID); - this.updateFavorites(favoritesSet); - }; - Favorites.prototype.removeFromFavorite = function (productID) { - var favoritesSet = new Set(this.getStorage()); - favoritesSet.delete(productID); - this.updateFavorites(favoritesSet); - }; - Favorites.prototype.handleFavorite = function (productID) { - var favoritesSet = new Set(this.getStorage()); - if (favoritesSet.has(productID)) { - favoritesSet.delete(productID); - return; - } - favoritesSet.add(productID); - }; - /** - * @return if the Cart is empty or not. - */ - Favorites.prototype.isEmpty = function () { - return this.getStorage().length === 0; - }; - /** - * @return favorites products. - */ - Favorites.prototype.getFavorites = function () { - return this.getStorage(); - }; - /** - * @return favorites products. - */ - Favorites.prototype.isFavorite = function (id) { - return this.getStorage().includes(id); - ; - }; - /** - * Update the Favorites Products Storage. - */ - Favorites.prototype.updateFavorites = function (favoritesSet) { - var favoritesArray = __spreadArray([], __read(favoritesSet), false); - this.updateStorage(favoritesArray); - }; - return Favorites; -}(Storage_1.default)); -exports.default = Favorites; diff --git a/build/client/class/Router.js b/build/client/class/Router.js deleted file mode 100644 index a02ddd1..0000000 --- a/build/client/class/Router.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Router = /** @class */ (function () { - function Router() { - } - Router.followWithParams = function (path, params) { - window.location.replace(window.location.origin + path + Router.stringfyParams(params)); - }; - Router.followWithCurrentParams = function (path) { - window.location.replace(window.location.origin + path + Router.getParams()); - }; - Router.getParams = function () { - return window.location.search; - }; - Router.createURL = function (path) { - return window.location.origin + path; - }; - Router.stringfyParams = function (params) { - return ("?" + - Object.keys(params) - .map(function (key) { return key + "=" + params[key]; }) - .join("&")); - }; - return Router; -}()); -exports.default = Router; diff --git a/build/client/class/Storage.js b/build/client/class/Storage.js deleted file mode 100644 index 8b72826..0000000 --- a/build/client/class/Storage.js +++ /dev/null @@ -1,21 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Storage = /** @class */ (function () { - function Storage(storageName, storageObject) { - this.storageName = storageName; - if (!sessionStorage.getItem(storageName)) { - sessionStorage.setItem(storageName, JSON.stringify(storageObject)); - } - } - Storage.prototype.updateStorage = function (storageObject) { - sessionStorage.setItem(this.storageName, JSON.stringify(storageObject)); - }; - Storage.prototype.deleteStorage = function () { - sessionStorage.removeItem(this.storageName); - }; - Storage.prototype.getStorage = function () { - return JSON.parse(sessionStorage.getItem(this.storageName)); - }; - return Storage; -}()); -exports.default = Storage; diff --git a/build/client/class/UI.js b/build/client/class/UI.js deleted file mode 100644 index 8aa3a3e..0000000 --- a/build/client/class/UI.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// COMPONENETS -var ProductsCardComponent_1 = __importDefault(require("../../server/components/ProductsCardComponent")); -var PaginatorComponent_1 = __importDefault(require("../../server/components/PaginatorComponent")); -var UI = /** @class */ (function () { - /** - * @param document where the HTMLElement will be inserted. - */ - function UI(document) { - this.document = document; - } - /** - * Render ProductsView - */ - UI.prototype.products = function (favorites, products, page, maxPage) { - var innerHTML = products - .map(function (product) { - return (0, ProductsCardComponent_1.default)(product, favorites.isFavorite(product.id)); - }) - .join(""); - (0, PaginatorComponent_1.default)(page || 1, maxPage); - }; - return UI; -}()); -exports.default = UI; diff --git a/build/client/class/Users.js b/build/client/class/Users.js deleted file mode 100644 index 0840ff1..0000000 --- a/build/client/class/Users.js +++ /dev/null @@ -1,116 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var API_1 = __importDefault(require("./API")); -var Router_1 = __importDefault(require("./Router")); -var Storage_1 = __importDefault(require("./Storage")); -var Users = /** @class */ (function (_super) { - __extends(Users, _super); - function Users() { - return _super.call(this, "user", { - id: null, - email: "", - password: "", - }) || this; - } - Users.prototype.loginUser = function (email, password) { - return __awaiter(this, void 0, void 0, function () { - var response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, API_1.default.fetchAPI(Router_1.default.createURL("/users"), { email: email, password: password })]; - case 1: - response = _a.sent(); - if (API_1.default.isApiError(response)) { - return [2 /*return*/, response.message]; - } - this.updateStorage({ - id: response.id, - email: email, - password: password - }); - return [2 /*return*/]; - } - }); - }); - }; - Users.prototype.registerUser = function (email, password) { - return __awaiter(this, void 0, void 0, function () { - var response; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, API_1.default.fetchAPI(Router_1.default.createURL("/users"), { email: email, password: password }, "PUT")]; - case 1: - response = _a.sent(); - if (API_1.default.isApiError(response)) { - return [2 /*return*/, response.message]; - } - this.updateStorage({ - id: response.id, - email: email, - password: password - }); - return [2 /*return*/]; - } - }); - }); - }; - Users.prototype.isLogued = function () { - return !!this.getStorage().id; - }; - return Users; -}(Storage_1.default)); -exports.default = Users; diff --git a/build/client/components/CartEntryComponent.js b/build/client/components/CartEntryComponent.js deleted file mode 100644 index 1f304cf..0000000 --- a/build/client/components/CartEntryComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function CartEntryComponent(_a) { - var units = _a.units, price = _a.price, total = _a.total, id = _a.id, title = _a.title; - return /* html */ "\n \n \n
-1
\n
+1
\n \n \n \n " + title + "\n \n \n " + units + "\n $" + price + "\n $" + total + "\n \n "; -} -exports.default = CartEntryComponent; diff --git a/build/client/components/CartTableComponent.js b/build/client/components/CartTableComponent.js deleted file mode 100644 index e462262..0000000 --- a/build/client/components/CartTableComponent.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var CartEntryComponent_1 = __importDefault(require("./CartEntryComponent")); -function CartTableComponent(products) { - var total = 0; - var CartTable = Object.values(products) - .map(function (product) { - total += product.total; - return (0, CartEntryComponent_1.default)(product); - }) - .join(""); - return { CartTable: CartTable, total: total }; -} -exports.default = CartTableComponent; diff --git a/build/client/components/FavoritesEntryComponent.js b/build/client/components/FavoritesEntryComponent.js deleted file mode 100644 index 24cb174..0000000 --- a/build/client/components/FavoritesEntryComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function FavoritesEntryComponent(_a) { - var price = _a.price, id = _a.id, title = _a.title, body = _a.body; - return /* html */ "\n \n \n \n " + title + "\n \n \n \n " + body + "\n $" + price + "\n F\n \n "; -} -exports.default = FavoritesEntryComponent; diff --git a/build/client/components/FavoritesTableComponent.js b/build/client/components/FavoritesTableComponent.js deleted file mode 100644 index 9d25745..0000000 --- a/build/client/components/FavoritesTableComponent.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var FavoritesEntryComponent_1 = __importDefault(require("./FavoritesEntryComponent")); -function FavoritesTableComponent(products) { - return products - .map(function (product) { return (0, FavoritesEntryComponent_1.default)(product); }) - .join(""); -} -exports.default = FavoritesTableComponent; diff --git a/build/client/components/PaginatorComponent.js b/build/client/components/PaginatorComponent.js deleted file mode 100644 index 54053d6..0000000 --- a/build/client/components/PaginatorComponent.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function PaginatorComponenet(page, maxPage, positions) { - var left = positions.left, center = positions.center, right = positions.right; - return "\n " + createExteriorPaginator(1, "<<", maxPage, (page >= 3)) + "\n " + createMidPaginator(left, maxPage, page) + "\n " + createMidPaginator(center, maxPage, page) + "\n " + createMidPaginator(right, maxPage, page) + "\n " + createExteriorPaginator(maxPage, ">>", maxPage, (page <= maxPage)) + "\n "; -} -exports.default = PaginatorComponenet; -function createMidPaginator(thisPage, maxPage, currentPage) { - return (thisPage > 0 && thisPage <= maxPage) - ? "\n \n " + thisPage + "\n \n " - : ""; -} -function createExteriorPaginator(thisPage, content, maxPage, condition) { - return (condition && maxPage > 3) - ? "\n \n " + content + "\n \n " - : ""; -} diff --git a/build/client/components/ProductsCardComponent.js b/build/client/components/ProductsCardComponent.js deleted file mode 100644 index 46e742d..0000000 --- a/build/client/components/ProductsCardComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function ProductsCardComponent(_a, isFavorite) { - var image = _a.image, id = _a.id, price = _a.price, title = _a.title; - return /* html */ "\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
" + title + "
\n
$" + price + "
\n
\n Comprar\n
\n "; -} -exports.default = ProductsCardComponent; diff --git a/build/client/config.js b/build/client/config.js deleted file mode 100644 index 680784f..0000000 --- a/build/client/config.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.SS_FAVORITES = exports.SS_CART = exports.API_ERROR = exports.API_POSTS = exports.CURRENT_PAGE = exports.DEFAULT_HTML_FILE = exports.PAGES = exports.SEARCH_PAIR_INPUTS = exports.QUANTITY_PRODUCTS_INDICATOR = void 0; -// HTML -var SEARCH_INPUT_S = document.getElementById("search-input-s"); -var SEARCH_INPUT = document.getElementById("search-input"); -var QUANTITY_PRODUCTS_INDICATOR = document.getElementById("quantityProducts"); -exports.QUANTITY_PRODUCTS_INDICATOR = QUANTITY_PRODUCTS_INDICATOR; -// GENERAL -var CURRENT_PAGE = window.location.pathname.split("/")[1]; -exports.CURRENT_PAGE = CURRENT_PAGE; -var PAGES = ["index", "cart", "products", "product", "error"]; -exports.PAGES = PAGES; -var DEFAULT_HTML_FILE = "index"; -exports.DEFAULT_HTML_FILE = DEFAULT_HTML_FILE; -var SEARCH_PAIR_INPUTS = { - "search-button-s": SEARCH_INPUT_S, - "search-button": SEARCH_INPUT -}; -exports.SEARCH_PAIR_INPUTS = SEARCH_PAIR_INPUTS; -// API -var API_POSTS = "https://jsonplaceholder.typicode.com/posts/"; -exports.API_POSTS = API_POSTS; -var API_ERROR = "ERROR"; -exports.API_ERROR = API_ERROR; -// SESSION_STORAGE -var SS_CART = "cart"; -exports.SS_CART = SS_CART; -var SS_FAVORITES = "favorites"; -exports.SS_FAVORITES = SS_FAVORITES; diff --git a/build/client/errors/apiErrorHandler.js b/build/client/errors/apiErrorHandler.js deleted file mode 100644 index da4c9ca..0000000 --- a/build/client/errors/apiErrorHandler.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function apiErrorHandler(errorMessage) { - alert(errorMessage); - //app.errorLoader(); -} -exports.default = apiErrorHandler; diff --git a/build/client/errors/cartErrorHandler.js b/build/client/errors/cartErrorHandler.js deleted file mode 100644 index d76db11..0000000 --- a/build/client/errors/cartErrorHandler.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function cartErrorHandler(errorMessage) { - alert(errorMessage); -} -exports.default = cartErrorHandler; diff --git a/build/client/handlers/increaseOneButtonHandler.js b/build/client/handlers/increaseOneButtonHandler.js deleted file mode 100644 index ded5309..0000000 --- a/build/client/handlers/increaseOneButtonHandler.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var getIdProductFromTable_1 = __importDefault(require("../scripts/getIdProductFromTable")); -var ADD_ONE_PRODUCT_BUTTON_EVENT = "click"; -function increaseOneButtonHandler(button, cart, callback) { - button.addEventListener(ADD_ONE_PRODUCT_BUTTON_EVENT, function (e) { - var ID = (0, getIdProductFromTable_1.default)(e); - cart.addToCart(ID); - callback(); - }); -} -exports.default = increaseOneButtonHandler; diff --git a/build/client/handlers/loginHandler.js b/build/client/handlers/loginHandler.js deleted file mode 100644 index fca3033..0000000 --- a/build/client/handlers/loginHandler.js +++ /dev/null @@ -1,60 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var main_1 = __importDefault(require("../main")); -// HTML -var LOGIN_FORM = document.getElementById("js-loginForm"); -function loginHandler() { - return __awaiter(this, void 0, void 0, function () { - var _a, email, password, response; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _a = Object.fromEntries(new FormData(LOGIN_FORM).entries()), email = _a.email, password = _a.password; - return [4 /*yield*/, main_1.default.users.loginUser(email, password)]; - case 1: - response = _b.sent(); - return [2 /*return*/, alert(response ? response : "Logueado con Éxito")]; - } - }); - }); -} -exports.default = loginHandler; diff --git a/build/client/handlers/reduceOneButtonHandler.js b/build/client/handlers/reduceOneButtonHandler.js deleted file mode 100644 index 2b790ff..0000000 --- a/build/client/handlers/reduceOneButtonHandler.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var getIdProductFromTable_1 = __importDefault(require("../scripts/getIdProductFromTable")); -var REMOVE_ONE_PRODUCT_BUTTON_EVENT = "click"; -function reduceOneButtonHandler(button, cart, callback) { - button.addEventListener(REMOVE_ONE_PRODUCT_BUTTON_EVENT, function (e) { - var ID = (0, getIdProductFromTable_1.default)(e); - cart.removeFromCart(ID); - callback(); - }); -} -exports.default = reduceOneButtonHandler; diff --git a/build/client/handlers/registerHandler.js b/build/client/handlers/registerHandler.js deleted file mode 100644 index 8d4021b..0000000 --- a/build/client/handlers/registerHandler.js +++ /dev/null @@ -1,64 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var main_1 = __importDefault(require("../main")); -// HTML -var REGISTER_FORM = document.getElementById("js-registerForm"); -function registerHandler() { - return __awaiter(this, void 0, void 0, function () { - var _a, email, password, passwordRepeat, response; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _a = Object.fromEntries(new FormData(REGISTER_FORM).entries()), email = _a.email, password = _a.password, passwordRepeat = _a.passwordRepeat; - if (!(password === passwordRepeat)) return [3 /*break*/, 2]; - return [4 /*yield*/, main_1.default.users.registerUser(email, password)]; - case 1: - response = _b.sent(); - return [2 /*return*/, alert(response ? response : "Registrado con Éxito")]; - case 2: - alert("Las contraseñas no coinciden."); - return [2 /*return*/]; - } - }); - }); -} -exports.default = registerHandler; diff --git a/build/client/handlers/searchButtonHandler.js b/build/client/handlers/searchButtonHandler.js deleted file mode 100644 index 219c727..0000000 --- a/build/client/handlers/searchButtonHandler.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -var sendSearchRequest_1 = __importDefault(require("../scripts/sendSearchRequest")); -function searchButtonHandler(e) { - var BUTTON = e.target; - (0, sendSearchRequest_1.default)(config_1.SEARCH_PAIR_INPUTS[BUTTON.id]); -} -exports.default = searchButtonHandler; diff --git a/build/client/handlers/searchInputHandler.js b/build/client/handlers/searchInputHandler.js deleted file mode 100644 index 97e373d..0000000 --- a/build/client/handlers/searchInputHandler.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var sendSearchRequest_1 = __importDefault(require("../scripts/sendSearchRequest")); -function searchInputHandler(e) { - if (e.keyCode === 13) { - (0, sendSearchRequest_1.default)(e.target); - } -} -exports.default = searchInputHandler; diff --git a/build/client/interfaces/ApiProduct.js b/build/client/interfaces/ApiProduct.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/ApiProduct.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/BasicProduct.js b/build/client/interfaces/BasicProduct.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/BasicProduct.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/CartProduct.js b/build/client/interfaces/CartProduct.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/CartProduct.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/CartStructure.js b/build/client/interfaces/CartStructure.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/CartStructure.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/Product.js b/build/client/interfaces/Product.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/Product.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/SearchURLParams.js b/build/client/interfaces/SearchURLParams.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/SearchURLParams.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/interfaces/User.js b/build/client/interfaces/User.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/interfaces/User.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/listeners/closeCartListener.js b/build/client/listeners/closeCartListener.js deleted file mode 100644 index dcae511..0000000 --- a/build/client/listeners/closeCartListener.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var loadTable_1 = __importDefault(require("../scripts/loadTable")); -var CLOSE_CART_EVENT = "click"; -var CLOSE_CART_ID = "js-closeCart"; -/** - * Close the Cart. - */ -function closeCartListener(cart) { - var CLOSE_CART = document.getElementById(CLOSE_CART_ID); - CLOSE_CART.addEventListener(CLOSE_CART_EVENT, function () { - cart.close(); - (0, loadTable_1.default)(); - }); -} -exports.default = closeCartListener; diff --git a/build/client/listeners/favoritesListener.js b/build/client/listeners/favoritesListener.js deleted file mode 100644 index 02a4313..0000000 --- a/build/client/listeners/favoritesListener.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var main_1 = __importDefault(require("../main")); -// HTML -var FAVORITES_ICONS = document.getElementsByClassName("favorites-icon"); -// EVENTS -var SEARCH_INPUT_S_EVENT = "keyup"; -function favoritesListener() { - Array.from(FAVORITES_ICONS).forEach(function (favorites_icon) { - favorites_icon.addEventListener(SEARCH_INPUT_S_EVENT, function (e) { - if (!main_1.default.users.isLogued()) { - return alert("Necesitas estar Logueado!"); - } - var productID = +favorites_icon.dataset.id; - main_1.default.favorites.handleFavorite(productID); - }); - }); -} -exports.default = favoritesListener; diff --git a/build/client/listeners/lastMomentShopListener.js b/build/client/listeners/lastMomentShopListener.js deleted file mode 100644 index 0ed351e..0000000 --- a/build/client/listeners/lastMomentShopListener.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var increaseOneButtonHandler_1 = __importDefault(require("../handlers/increaseOneButtonHandler")); -var reduceOneButtonHandler_1 = __importDefault(require("../handlers/reduceOneButtonHandler")); -// HTML -var REMOVE_ONE_PRODUCT_BUTTON = document.getElementsByClassName("reduceOneButton"); -var ADD_ONE_PRODUCT_BUTTON = document.getElementsByClassName("increaseOneButton"); -function lastMomentShopListener(callback, cart) { - Array.from(REMOVE_ONE_PRODUCT_BUTTON).forEach(function (reduceOneButton) { - (0, reduceOneButtonHandler_1.default)(reduceOneButton, cart, callback); - }); - Array.from(ADD_ONE_PRODUCT_BUTTON).forEach(function (increaseOneButton) { - (0, increaseOneButtonHandler_1.default)(increaseOneButton, cart, callback); - }); -} -exports.default = lastMomentShopListener; diff --git a/build/client/listeners/loginRegisterListener.js b/build/client/listeners/loginRegisterListener.js deleted file mode 100644 index 6e9a3b7..0000000 --- a/build/client/listeners/loginRegisterListener.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var loginHandler_1 = __importDefault(require("../handlers/loginHandler")); -var registerHandler_1 = __importDefault(require("../handlers/registerHandler")); -// HTML -var LOGIN_FORM_BTN = document.getElementById("js-loginFormBTN"); -var REGISTER_FORM = document.getElementById("js-registerForm"); -// EVENTS -var REGISTER_FORM_BTN_EVENT = "click"; -var LOGIN_FORM_BTN_EVENT = "click"; -function loginRegisterListener() { - LOGIN_FORM_BTN.addEventListener(LOGIN_FORM_BTN_EVENT, loginHandler_1.default); - REGISTER_FORM.addEventListener(REGISTER_FORM_BTN_EVENT, registerHandler_1.default); -} -exports.default = loginRegisterListener; diff --git a/build/client/listeners/menuHandlerListener.js b/build/client/listeners/menuHandlerListener.js deleted file mode 100644 index 8fe206c..0000000 --- a/build/client/listeners/menuHandlerListener.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -// HTML -var MENU_HANDLERS_BUTTONS = document.getElementsByClassName("openNav-button"); -var MENU_CONTAINER = document.getElementById("nav-container"); -// CSS CLASES -var MENU_CONTAINER_CLASS_SHOW = "active"; -// EVENTS -var MENU_HANDLERS_BUTTONS_EVENT = "click"; -function menuHandlerListener() { - Array.from(MENU_HANDLERS_BUTTONS).forEach(function (button) { - button.addEventListener(MENU_HANDLERS_BUTTONS_EVENT, function () { - MENU_CONTAINER.classList.toggle(MENU_CONTAINER_CLASS_SHOW); - }); - }); -} -exports.default = menuHandlerListener; diff --git a/build/client/listeners/paginatorListener.js b/build/client/listeners/paginatorListener.js deleted file mode 100644 index 9b69f8d..0000000 --- a/build/client/listeners/paginatorListener.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Router_1 = __importDefault(require("../class/Router")); -// HTML -var PAGINATOR_BUTTONS = document.getElementsByClassName("js-paginator"); -// EVENTS -var PAGINATOR_BUTTONS_EVENT = "click"; -function paginatorListener() { - Array.from(PAGINATOR_BUTTONS).forEach(function (button) { - button.addEventListener(PAGINATOR_BUTTONS_EVENT, function (e) { - var page = e.target.dataset.page; - Router_1.default.followWithCurrentParams("/products/" + page); - }); - }); -} -exports.default = paginatorListener; diff --git a/build/client/listeners/searchsListener.js b/build/client/listeners/searchsListener.js deleted file mode 100644 index 6e09e51..0000000 --- a/build/client/listeners/searchsListener.js +++ /dev/null @@ -1,24 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var searchButtonHandler_1 = __importDefault(require("../handlers/searchButtonHandler")); -var searchInputHandler_1 = __importDefault(require("../handlers/searchInputHandler")); -// HTML -var SEARCH_BUTTON_S = document.getElementById("search-button-s"); -var SEARCH_BUTTON = document.getElementById("search-button"); -var SEARCH_INPUT_S = document.getElementById("search-input-s"); -var SEARCH_INPUT = document.getElementById("search-input"); -// EVENTS -var SEARCH_BUTTON_S_EVENT = "click"; -var SEARCH_BUTTON_EVENT = "click"; -var SEARCH_INPUT_S_EVENT = "keyup"; -var SEARCH_INPUT_EVENT = "keyup"; -function searchsListener() { - SEARCH_INPUT_S.addEventListener(SEARCH_INPUT_S_EVENT, searchInputHandler_1.default); - SEARCH_INPUT.addEventListener(SEARCH_INPUT_EVENT, searchInputHandler_1.default); - SEARCH_BUTTON_S.addEventListener(SEARCH_BUTTON_S_EVENT, searchButtonHandler_1.default); - SEARCH_BUTTON.addEventListener(SEARCH_BUTTON_EVENT, searchButtonHandler_1.default); -} -exports.default = searchsListener; diff --git a/build/client/listeners/shopListener.js b/build/client/listeners/shopListener.js deleted file mode 100644 index 7bc1be1..0000000 --- a/build/client/listeners/shopListener.js +++ /dev/null @@ -1,62 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -// SCRIPTS -var updateQuantityProducts_1 = __importDefault(require("../scripts/updateQuantityProducts")); -// HTML -var SHOP_BUTTONS = document.getElementsByClassName("shopButton"); -// EVENTS -var SHOP_BUTTONS_EVENT = "click"; -function shopListener(cart) { - var _this = this; - Array.from(SHOP_BUTTONS).forEach(function (button) { - button.addEventListener(SHOP_BUTTONS_EVENT, function (e) { return __awaiter(_this, void 0, void 0, function () { - var id; - return __generator(this, function (_a) { - id = +e.target.dataset.id; - cart.addToCart(id); - (0, updateQuantityProducts_1.default)(cart.getQuantityProducts()); - return [2 /*return*/]; - }); - }); }); - }); -} -exports.default = shopListener; diff --git a/build/client/main.js b/build/client/main.js deleted file mode 100644 index 097c4a8..0000000 --- a/build/client/main.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var App_1 = __importDefault(require("./class/App")); -var HTML_APP = document.getElementById("app"); -var app = new App_1.default(HTML_APP); -app.fileLoader(); -exports.default = app; diff --git a/build/client/scripts/getIdProductFromTable.js b/build/client/scripts/getIdProductFromTable.js deleted file mode 100644 index 5d1e863..0000000 --- a/build/client/scripts/getIdProductFromTable.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function getIdProductFromTable(e) { - var stringID = e.target.parentElement.dataset - .productId; - return Number(stringID); -} -exports.default = getIdProductFromTable; diff --git a/build/client/scripts/loadTable.js b/build/client/scripts/loadTable.js deleted file mode 100644 index 72f8b90..0000000 --- a/build/client/scripts/loadTable.js +++ /dev/null @@ -1,107 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __generator = (this && this.__generator) || function (thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Router_1 = __importDefault(require("../class/Router")); -var API_1 = __importDefault(require("../class/API")); -// LISTENERS -var lastMomentShopListener_1 = __importDefault(require("../listeners/lastMomentShopListener")); -// SCRIPTS -var main_1 = __importDefault(require("../main")); -var updateQuantityProducts_1 = __importDefault(require("./updateQuantityProducts")); -var CartTableComponent_1 = __importDefault(require("../components/CartTableComponent")); -// HTML; -var tBodyCartID = "tBodyCart"; -var totalCartID = "totalCart"; -function setCartElements(tBodyCart, total) { - document.getElementById(tBodyCartID).innerHTML = tBodyCart; - document.getElementById(totalCartID).innerHTML = "$" + total; -} -function updateCart(cart) { - return __awaiter(this, void 0, void 0, function () { - var ProductsIDs, IDList, response, products; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - ProductsIDs = cart.getProductsIDs(); - IDList = Object.keys(ProductsIDs); - return [4 /*yield*/, API_1.default.fetchAPI(Router_1.default.createURL("/products/ids"), { - IDList: IDList, - })]; - case 1: - response = _a.sent(); - if (!API_1.default.isApiError(response)) { - products = response.map(function (product) { - var cartProduct = product; - cartProduct.units = ProductsIDs[product.id]; - cartProduct.total = cartProduct.price * cartProduct.units; - return cartProduct; - }); - cart.setProducts(products); - } - return [2 /*return*/]; - } - }); - }); -} -/** - * Loads the Table Body of the Cart View - */ -function loadTable(cart) { - if (cart === void 0) { cart = main_1.default.cart; } - return __awaiter(this, void 0, void 0, function () { - var products, _a, total, CartTable; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, updateCart(cart)]; - case 1: - _b.sent(); - cart.isCartError(); - products = cart.getProducts(); - _a = (0, CartTableComponent_1.default)(products), total = _a.total, CartTable = _a.CartTable; - setCartElements(CartTable, total); - (0, lastMomentShopListener_1.default)(loadTable, cart); - (0, updateQuantityProducts_1.default)(cart.getQuantityProducts()); - return [2 /*return*/]; - } - }); - }); -} -exports.default = loadTable; diff --git a/build/client/scripts/sendSearchRequest.js b/build/client/scripts/sendSearchRequest.js deleted file mode 100644 index 34931dc..0000000 --- a/build/client/scripts/sendSearchRequest.js +++ /dev/null @@ -1,16 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Router_1 = __importDefault(require("../class/Router")); -//import { CURRENT_PAGE } from "../config"; -function sendSearchRequest(input) { - //if (CURRENT_PAGE !== "products") { - console.log(input.value); - return Router_1.default.followWithParams("/products", { - search: input.value - }); - //} -} -exports.default = sendSearchRequest; diff --git a/build/client/scripts/updateQuantityProducts.js b/build/client/scripts/updateQuantityProducts.js deleted file mode 100644 index e04b104..0000000 --- a/build/client/scripts/updateQuantityProducts.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = require("../config"); -function updateQuantityProducts(q) { - config_1.QUANTITY_PRODUCTS_INDICATOR.innerHTML = String(q); -} -exports.default = updateQuantityProducts; diff --git a/build/client/types/api.js b/build/client/types/api.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/api.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/cart.js b/build/client/types/cart.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/cart.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/favorites.js b/build/client/types/favorites.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/favorites.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/functions.js b/build/client/types/functions.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/functions.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/html.js b/build/client/types/html.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/html.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/products.js b/build/client/types/products.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/products.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/client/types/search.js b/build/client/types/search.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/client/types/search.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/api/products.api.js b/build/server/api/products.api.js deleted file mode 100644 index 95cbf41..0000000 --- a/build/server/api/products.api.js +++ /dev/null @@ -1,23 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var API_1 = __importDefault(require("../classes/API")); -function productsApi(_a, body) { - var page = _a.page, search = _a.search, min = _a.min, max = _a.max; - if (body === void 0) { body = {}; } - var products = API_1.default.getProducts(search, body.IDList, min, max); - if (body) { - return { products: products }; - } - var maxPage = Math.ceil(products.length / 10); - var currentPage = +page || 1; - var firstProductIndex = (currentPage - 1) * 10; - return { - products: products.slice(firstProductIndex, firstProductIndex + 10), - maxPage: maxPage, - page: currentPage, - }; -} -exports.default = productsApi; diff --git a/build/server/app.js b/build/server/app.js deleted file mode 100644 index 5497c85..0000000 --- a/build/server/app.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var express = require('express'); -var ejs = require('ejs'); -var morgan = require('morgan'); -var ROUTES = require('./routes'); -var PUBLIC_DIR = require('./config').PUBLIC_DIR; -var app = express(); -// ["Primeros auxilios", "Diabetes", "Óptica", "Pediculosis", "Pédicos", "Suplementos Dietarios", "Suplementos Nutricionales", "Suplementos Deportivos", "Protección y Recuperación", "Fitness"]; -// settings -app.set('view engine', 'ejs'); -app.listen(4444); -// middlewares -app.use(morgan('dev')); -app.use(express.urlencoded({ extended: true })); -app.use(express.json()); -// static -app.use(express.static(PUBLIC_DIR)); -// routes -app.use(ROUTES); diff --git a/build/server/classes/API.js b/build/server/classes/API.js deleted file mode 100644 index 956b7d2..0000000 --- a/build/server/classes/API.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var fs = require("fs"); -var DATABASE_DIR = require("../config").DATABASE_DIR; -var DATABASE_TABLE_PRODUCT = DATABASE_DIR + "/products.json"; -var PRODUCTS = JSON.parse(fs.readFileSync(DATABASE_TABLE_PRODUCT, "utf8")); -var API = /** @class */ (function () { - function API() { - } - API.getProduct = function (id) { - return PRODUCTS.find(function (product) { return product.id === id; }); - }; - API.getProducts = function (search, min, max) { - if (search === void 0) { search = ""; } - if (min === void 0) { min = null; } - if (max === void 0) { max = null; } - var SEARCH_REGEX = new RegExp(search); - return PRODUCTS.filter(function (product) { - return SEARCH_REGEX.test(product.title.toLowerCase()) && - API.inRange(product.price, min, max); - }); - }; - API.getProductsByIds = function (IDList) { - if (IDList === void 0) { IDList = []; } - return PRODUCTS.filter(function (product) { - return IDList.includes(String(product.id)); - }); - }; - API.inRange = function (elem, min, max) { - if (min === void 0) { min = null; } - if (max === void 0) { max = null; } - return (min ? elem >= min : true) && (max ? elem <= max : true); - }; - return API; -}()); -exports.default = API; diff --git a/build/server/classes/Config.js b/build/server/classes/Config.js deleted file mode 100644 index 830228a..0000000 --- a/build/server/classes/Config.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataBase_1 = __importDefault(require("./DataBase")); -var ProductsAPI = /** @class */ (function (_super) { - __extends(ProductsAPI, _super); - function ProductsAPI() { - return _super.call(this, "config") || this; - } - ProductsAPI.prototype.getConfig = function (configEntry) { - return; - }; - ProductsAPI.prototype.setConfig = function (configEntry, configData) { - //return this.getProductsByIds(this.body.IDList); - }; - return ProductsAPI; -}(DataBase_1.default)); -exports.default = ProductsAPI; diff --git a/build/server/classes/DataBase.js b/build/server/classes/DataBase.js deleted file mode 100644 index 5324cbd..0000000 --- a/build/server/classes/DataBase.js +++ /dev/null @@ -1,59 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var Filter_1 = __importDefault(require("./Filter")); -var fs = require("fs"); -var DATABASE_DIR = require("../config").DATABASE_DIR; -var DataBase = /** @class */ (function (_super) { - __extends(DataBase, _super); - function DataBase(tableName) { - var _this = _super.call(this) || this; - _this.tableNames = ["config", "products", "users", "favorites"]; - _this.table = _this.returnTable(tableName); - return _this; - } - DataBase.prototype.getTable = function () { - return this.table; - }; - DataBase.prototype.setTable = function (tableName, tableData) { - fs.writeFileSync(this.getTablePath(tableName), JSON.stringify(tableData)); - }; - DataBase.prototype.returnTable = function (tableName) { - if (this.tableNames.includes(tableName)) { - return JSON.parse(fs.readFileSync(this.getTablePath(tableName), "utf8")); - } - }; - DataBase.prototype.getConfig = function (configEntry) { - return this.returnConfig()[configEntry]; - }; - DataBase.prototype.setConfig = function (configEntry, configData) { - var config = this.returnConfig(); - config[configEntry] = configData; - this.setTable("config", config); - }; - DataBase.prototype.getTablePath = function (tableName) { - return DATABASE_DIR + "/" + tableName + ".json"; - }; - DataBase.prototype.returnConfig = function () { - return this.returnTable("config"); - }; - return DataBase; -}(Filter_1.default)); -exports.default = DataBase; diff --git a/build/server/classes/Filter.js b/build/server/classes/Filter.js deleted file mode 100644 index a978995..0000000 --- a/build/server/classes/Filter.js +++ /dev/null @@ -1,13 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var Filter = /** @class */ (function () { - function Filter() { - } - Filter.prototype.inRange = function (elem, min, max) { - if (min === void 0) { min = null; } - if (max === void 0) { max = null; } - return (min ? elem >= min : true) && (max ? elem <= max : true); - }; - return Filter; -}()); -exports.default = Filter; diff --git a/build/server/classes/ProductsAPI.js b/build/server/classes/ProductsAPI.js deleted file mode 100644 index 9af2bd5..0000000 --- a/build/server/classes/ProductsAPI.js +++ /dev/null @@ -1,66 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataBase_1 = __importDefault(require("./DataBase")); -var ProductsAPI = /** @class */ (function (_super) { - __extends(ProductsAPI, _super); - function ProductsAPI(req) { - var _this = _super.call(this, "products") || this; - _this.params = {}; - _this.body = {}; - _this.query = {}; - _this.params = req.params; - _this.body = req.body; - _this.query = req.query; - _this.products = _this.getTable(); - return _this; - } - ProductsAPI.prototype.getProducts = function () { - var _this = this; - var _a = this.params, page = _a.page, min = _a.min, max = _a.max; - var search = this.query.search; - var SEARCH_REGEX = new RegExp(search); - console.log(this.body, this.params, this.query); - var products = this.products.filter(function (product) { - return SEARCH_REGEX.test(product.title.toLowerCase()) && - _this.inRange(product.price, min, max); - }); - var maxPage = Math.ceil(products.length / 10); - var currentPage = +page || 1; - var firstProductIndex = (currentPage - 1) * 10; - return { - products: products.slice(firstProductIndex, firstProductIndex + 10), - maxPage: maxPage, - page: currentPage, - }; - }; - ProductsAPI.prototype.getProductsById = function () { - var _this = this; - return this.products.filter(function (product) { - return _this.body.IDList.includes(String(product.id)); - }); - }; - ProductsAPI.prototype.getProduct = function () { - var id = this.params.id; - return this.products.find(function (product) { return product.id === +id; }); - }; - return ProductsAPI; -}(DataBase_1.default)); -exports.default = ProductsAPI; diff --git a/build/server/classes/UsersAPI.js b/build/server/classes/UsersAPI.js deleted file mode 100644 index e15c25d..0000000 --- a/build/server/classes/UsersAPI.js +++ /dev/null @@ -1,62 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var DataBase_1 = __importDefault(require("./DataBase")); -var UsersAPI = /** @class */ (function (_super) { - __extends(UsersAPI, _super); - function UsersAPI(req) { - var _this = _super.call(this, "users") || this; - _this.body = {}; - _this.body = req.body; - _this.users = _this.getTable(); - return _this; - } - UsersAPI.prototype.getUser = function (email) { - return this.users.find(function (user) { return user.email === email; }); - }; - UsersAPI.prototype.existUser = function (email) { - return !!this.getUser(email); - }; - UsersAPI.prototype.setUser = function () { - var _a = this.body, email = _a.email, password = _a.password; - if (this.existUser(email)) { - return; - } - var config = this.getConfig("users"); - config.maxID += 1; - this.setConfig("users", config); - this.users.push({ - email: email, - password: password, - id: config.maxID, - }); - this.setTable("users", this.users); - return config.maxID; - }; - UsersAPI.prototype.validateUser = function () { - var _a = this.body, email = _a.email, password = _a.password; - var user = this.getUser(email); - if (user && user.password === password) { - return user.id; - } - }; - return UsersAPI; -}(DataBase_1.default)); -exports.default = UsersAPI; diff --git a/build/server/client/types/cart.js b/build/server/client/types/cart.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/client/types/cart.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/client/types/html.js b/build/server/client/types/html.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/client/types/html.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/components/CartEntryComponent.js b/build/server/components/CartEntryComponent.js deleted file mode 100644 index 3891910..0000000 --- a/build/server/components/CartEntryComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function CartEntryComponent(_a) { - var units = _a.units, price = _a.price, total = _a.total, id = _a.id, title = _a.title; - return /* html */ "\n \n \n
-1
\n
+1
\n \n \n \n " + title + "\n \n \n " + units + "\n $" + price + "\n $" + total + "\n \n "; -} -exports.default = CartEntryComponent; diff --git a/build/server/components/CartTableComponent.js b/build/server/components/CartTableComponent.js deleted file mode 100644 index 5ffec80..0000000 --- a/build/server/components/CartTableComponent.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var CartEntryComponent_1 = __importDefault(require("./CartEntryComponent")); -function CartTableComponent(products) { - return Object.values(products) - .map(function (product) { return (0, CartEntryComponent_1.default)(product); }) - .join(""); -} -exports.default = CartTableComponent; diff --git a/build/server/components/FavoritesEntryComponent.js b/build/server/components/FavoritesEntryComponent.js deleted file mode 100644 index ef50d5c..0000000 --- a/build/server/components/FavoritesEntryComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function FavoritesEntryComponent(_a) { - var price = _a.price, id = _a.id, title = _a.title, body = _a.body; - return /* html */ "\n \n \n \n " + title + "\n \n \n \n " + body + "\n $" + price + "\n F\n \n "; -} -exports.default = FavoritesEntryComponent; diff --git a/build/server/components/FavoritesTableComponent.js b/build/server/components/FavoritesTableComponent.js deleted file mode 100644 index 9d25745..0000000 --- a/build/server/components/FavoritesTableComponent.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var FavoritesEntryComponent_1 = __importDefault(require("./FavoritesEntryComponent")); -function FavoritesTableComponent(products) { - return products - .map(function (product) { return (0, FavoritesEntryComponent_1.default)(product); }) - .join(""); -} -exports.default = FavoritesTableComponent; diff --git a/build/server/components/PaginatorComponent.js b/build/server/components/PaginatorComponent.js deleted file mode 100644 index ab57373..0000000 --- a/build/server/components/PaginatorComponent.js +++ /dev/null @@ -1,29 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function PaginatorComponenet(page, maxPage) { - var left = page - 1; - var center = page; - var right = page + 1; - if (page === 1) { - ++left; - ++center; - ++right; - } - else if (page === maxPage) { - --left; - --center; - --right; - } - return "\n " + exteriorPaginator(1, maxPage, "<<", page > 2) + "\n " + midPaginator(left, maxPage, page) + "\n " + midPaginator(center, maxPage, page) + "\n " + midPaginator(right, maxPage, page) + "\n " + exteriorPaginator(maxPage, maxPage, ">>", page < (maxPage - 1)) + "\n "; -} -exports.default = PaginatorComponenet; -function midPaginator(redirectPage, maxPage, currentPage) { - return redirectPage > 0 && redirectPage <= maxPage - ? "\n \n " + redirectPage + "\n \n " - : ""; -} -function exteriorPaginator(redirectPage, maxPage, content, condition) { - return condition && maxPage > 3 - ? "\n \n " + content + "\n \n " - : ""; -} diff --git a/build/server/components/ProductSpecComponent.js b/build/server/components/ProductSpecComponent.js deleted file mode 100644 index 27bc2b6..0000000 --- a/build/server/components/ProductSpecComponent.js +++ /dev/null @@ -1,6 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function ProductSpecComponent(specTitle, specBody) { - return /* html */ "\n
\n " + specTitle + ": " + specBody + "\n
\n "; -} -exports.default = ProductSpecComponent; diff --git a/build/server/components/ProductSpecsComponent.js b/build/server/components/ProductSpecsComponent.js deleted file mode 100644 index c502aa5..0000000 --- a/build/server/components/ProductSpecsComponent.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductSpecComponent_1 = __importDefault(require("./ProductSpecComponent")); -function ProductSpecsComponent(caracts) { - return Object.entries(caracts) - .map(function (_a) { - var key = _a[0], value = _a[1]; - return (0, ProductSpecComponent_1.default)(key, value); - }) - .join(""); -} -exports.default = ProductSpecsComponent; diff --git a/build/server/components/ProductsCardComponent.js b/build/server/components/ProductsCardComponent.js deleted file mode 100644 index 3bd232b..0000000 --- a/build/server/components/ProductsCardComponent.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -function ProductsCardComponent(_a, isFavorite) { - var image = _a.image, id = _a.id, price = _a.price, title = _a.title; - return /* html */ "\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
" + title + "
\n
$" + price + "
\n
\n Comprar\n
\n "; -} -exports.default = ProductsCardComponent; diff --git a/build/server/config.js b/build/server/config.js deleted file mode 100644 index 9eafcd3..0000000 --- a/build/server/config.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.DATABASE_DIR = exports.PUBLIC_DIR = void 0; -var path = require('path'); -var ROOT_PATH = [__dirname, '..', '..']; -var ROOT = path.join.apply(path, ROOT_PATH); -var PUBLIC_DIR = path.join.apply(path, __spreadArray(__spreadArray([], ROOT_PATH, false), ['public'], false)); -exports.PUBLIC_DIR = PUBLIC_DIR; -var DATABASE_DIR = path.join.apply(path, __spreadArray(__spreadArray([], ROOT_PATH, false), ['database'], false)); -exports.DATABASE_DIR = DATABASE_DIR; diff --git a/build/server/controllers/cart.get.js b/build/server/controllers/cart.get.js deleted file mode 100644 index c71d170..0000000 --- a/build/server/controllers/cart.get.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function indexGet(req, res) { - res.render('cart'); -}; diff --git a/build/server/controllers/index.get.js b/build/server/controllers/index.get.js deleted file mode 100644 index b807b7b..0000000 --- a/build/server/controllers/index.get.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function indexGet(req, res) { - res.render('index'); -}; diff --git a/build/server/controllers/product.get.js b/build/server/controllers/product.get.js deleted file mode 100644 index cb98bce..0000000 --- a/build/server/controllers/product.get.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -var ProductSpecsComponent_1 = __importDefault(require("../components/ProductSpecsComponent")); -module.exports = function productGet(req, res) { - var product = new ProductsAPI_1.default(req).getProduct(); - var config = product; - config.productSpecs = (0, ProductSpecsComponent_1.default)(product.caracts); - config.isFavorite = true; - res.render("product", config); -}; diff --git a/build/server/controllers/products.get.js b/build/server/controllers/products.get.js deleted file mode 100644 index a167637..0000000 --- a/build/server/controllers/products.get.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -var ProductsCardComponent_1 = __importDefault(require("../components/ProductsCardComponent")); -var PaginatorComponent_1 = __importDefault(require("../components/PaginatorComponent")); -module.exports = function productsGet(req, res) { - var _a = new ProductsAPI_1.default(req).getProducts(), products = _a.products, page = _a.page, maxPage = _a.maxPage; - var productsHTML = products - .map(function (product) { return (0, ProductsCardComponent_1.default)(product, true); }) - .join(""); - var paginatorHTML = (0, PaginatorComponent_1.default)(page, maxPage); - res.render("products", { - productsHTML: productsHTML, - paginatorHTML: paginatorHTML, - }); -}; diff --git a/build/server/controllers/products.post.js b/build/server/controllers/products.post.js deleted file mode 100644 index bada7d3..0000000 --- a/build/server/controllers/products.post.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -module.exports = function productsPost(req, res) { - var response = new ProductsAPI_1.default(req).getProducts(); - res.json(response); -}; diff --git a/build/server/controllers/productsIDs.post.js b/build/server/controllers/productsIDs.post.js deleted file mode 100644 index 437c152..0000000 --- a/build/server/controllers/productsIDs.post.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -module.exports = function productsIDsPost(req, res) { - var response = new ProductsAPI_1.default(req).getProductsById(); - res.json(response); -}; diff --git a/build/server/controllers/users.get.js b/build/server/controllers/users.get.js deleted file mode 100644 index 382878d..0000000 --- a/build/server/controllers/users.get.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function usersGet(req, res) { - res.render('users'); -}; diff --git a/build/server/controllers/users.post.js b/build/server/controllers/users.post.js deleted file mode 100644 index ec17136..0000000 --- a/build/server/controllers/users.post.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var UsersAPI_1 = __importDefault(require("../classes/UsersAPI")); -module.exports = function usersPost(req, res) { - var idUser = new UsersAPI_1.default(req).validateUser(); - if (idUser) { - return res.json({ - id: idUser, - }); - } - res.status(401).json({ - message: "Credenciales Inválidas", - }); -}; diff --git a/build/server/controllers/users.put.js b/build/server/controllers/users.put.js deleted file mode 100644 index c8f336a..0000000 --- a/build/server/controllers/users.put.js +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var UsersAPI_1 = __importDefault(require("../classes/UsersAPI")); -module.exports = function usersPost(req, res) { - var idUser = new UsersAPI_1.default(req).setUser(); - if (idUser) { - return res.json({ - id: idUser, - }); - } - res.status(401).send({ - message: "Usuario Existente", - }); -}; diff --git a/build/server/interfaces/BasicProduct.js b/build/server/interfaces/BasicProduct.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/interfaces/BasicProduct.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/interfaces/CartProduct.js b/build/server/interfaces/CartProduct.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/interfaces/CartProduct.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/interfaces/CartStructure.js b/build/server/interfaces/CartStructure.js deleted file mode 100644 index 5fd3ac6..0000000 --- a/build/server/interfaces/CartStructure.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; -// import { cartStructureProducts } from "../types/cart"; -// export default interface CartStructure { -// products: cartStructureProducts, -// quantityProducts: number, -// total: number -// } diff --git a/build/server/interfaces/Product.js b/build/server/interfaces/Product.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/interfaces/Product.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/interfaces/SearchURLParams.js b/build/server/interfaces/SearchURLParams.js deleted file mode 100644 index a411080..0000000 --- a/build/server/interfaces/SearchURLParams.js +++ /dev/null @@ -1,8 +0,0 @@ -"use strict"; -// import { htmlFileName } from "../types/search"; -// export default interface SearchURLParams { -// htmlFileName: htmlFileName, -// page: string, -// id: string, -// search: string -// } diff --git a/build/server/interfaces/User.js b/build/server/interfaces/User.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/interfaces/User.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/routes.js b/build/server/routes.js deleted file mode 100644 index f905729..0000000 --- a/build/server/routes.js +++ /dev/null @@ -1,30 +0,0 @@ -"use strict"; -var Router = require("express").Router; -var router = Router(); -// CONTROLLERS -var productsGet = require("./controllers/products.get"); -var productGet = require("./controllers/product.get"); -var indexGet = require("./controllers/index.get"); -var usersGet = require("./controllers/users.get"); -var cartGet = require("./controllers/cart.get"); -var productsIDsPost = require("./controllers/productsIDs.post"); -var productsPost = require("./controllers/products.post"); -var usersPost = require("./controllers/users.post"); -var usersPut = require("./controllers/users.put"); -router.get("/", indexGet); -router.get("/products/:page", productsGet); -router.get("/products", productsGet); -router.get("/product/:id", productGet); -router.get("/users", usersGet); -router.get("/cart", cartGet); -// POST -router.post("/products/ids", productsIDsPost); -router.post("/products/:page", productsPost); -router.post("/products", productsPost); -router.post("/users", usersPost); -// PUT -router.put("/users", usersPut); -router.use(function (req, res) { - res.status(404).render("404"); -}); -module.exports = router; diff --git a/build/server/routes/cart.controller.js b/build/server/routes/cart.controller.js deleted file mode 100644 index 39e5c31..0000000 --- a/build/server/routes/cart.controller.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function indexController(req, res) { - res.render('cart'); -}; diff --git a/build/server/routes/index.controller.js b/build/server/routes/index.controller.js deleted file mode 100644 index 3c5fe6a..0000000 --- a/build/server/routes/index.controller.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function indexController(req, res) { - res.render('index'); -}; diff --git a/build/server/routes/product.controller.js b/build/server/routes/product.controller.js deleted file mode 100644 index 4013a50..0000000 --- a/build/server/routes/product.controller.js +++ /dev/null @@ -1,14 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -var ProductSpecsComponent_1 = __importDefault(require("../components/ProductSpecsComponent")); -module.exports = function productController(req, res) { - var product = new ProductsAPI_1.default(req).getProduct(); - var config = product; - config.productSpecs = (0, ProductSpecsComponent_1.default)(product.caracts); - config.isFavorite = true; - res.render("product", config); -}; diff --git a/build/server/routes/products.controller.js b/build/server/routes/products.controller.js deleted file mode 100644 index e4f1055..0000000 --- a/build/server/routes/products.controller.js +++ /dev/null @@ -1,19 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var ProductsAPI_1 = __importDefault(require("../classes/ProductsAPI")); -var ProductsCardComponent_1 = __importDefault(require("../components/ProductsCardComponent")); -var PaginatorComponent_1 = __importDefault(require("../components/PaginatorComponent")); -module.exports = function productsController(req, res) { - var _a = new ProductsAPI_1.default(req).getProducts(), products = _a.products, page = _a.page, maxPage = _a.maxPage; - var productsHTML = products - .map(function (product) { return (0, ProductsCardComponent_1.default)(product, true); }) - .join(""); - var paginatorHTML = (0, PaginatorComponent_1.default)(page, maxPage); - res.render("products", { - productsHTML: productsHTML, - paginatorHTML: paginatorHTML, - }); -}; diff --git a/build/server/routes/users.controller.js b/build/server/routes/users.controller.js deleted file mode 100644 index fe43060..0000000 --- a/build/server/routes/users.controller.js +++ /dev/null @@ -1,4 +0,0 @@ -"use strict"; -module.exports = function indexController(req, res) { - res.render('users'); -}; diff --git a/build/server/types/api.js b/build/server/types/api.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/api.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/cart.js b/build/server/types/cart.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/cart.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/favorites.js b/build/server/types/favorites.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/favorites.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/functions.js b/build/server/types/functions.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/functions.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/html.js b/build/server/types/html.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/html.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/products.js b/build/server/types/products.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/products.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/build/server/types/search.js b/build/server/types/search.js deleted file mode 100644 index c8ad2e5..0000000 --- a/build/server/types/search.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); From f063738d8b08dbd80b96675039d2c8b5be72991b Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:11:00 -0300 Subject: [PATCH 27/37] tests --- database/config.json | 2 +- database/favorites.json | 3 +++ database/users.json | 6 +++--- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/database/config.json b/database/config.json index c1f210d..f789d97 100644 --- a/database/config.json +++ b/database/config.json @@ -1 +1 @@ -{"users":{"maxID":3}} \ No newline at end of file +{"users":{"maxID":2}} \ No newline at end of file diff --git a/database/favorites.json b/database/favorites.json index ef4dbe2..ab77c3e 100644 --- a/database/favorites.json +++ b/database/favorites.json @@ -1,4 +1,7 @@ [{ "id": 1, "favoritesProducts": [] +}, { + "id": "2", + "favoritesProducts": ["12", "11", "14", "13"] }] \ No newline at end of file diff --git a/database/users.json b/database/users.json index 071d408..65485b0 100644 --- a/database/users.json +++ b/database/users.json @@ -3,7 +3,7 @@ "email": "gonzalobordon02@hotmail.com", "password": "123" }, { - "email": "xdxd", - "password": "123", - "id": 3 + "email": "xd", + "password": "12", + "id": 2 }] \ No newline at end of file From 29f205668cced68ac8402564b32cb0687ed25d93 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:12:10 -0300 Subject: [PATCH 28/37] logued users view. Minor fix --- views/product.ejs | 2 +- views/users_logued.ejs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 views/users_logued.ejs diff --git a/views/product.ejs b/views/product.ejs index 73c3b98..c0924cb 100644 --- a/views/product.ejs +++ b/views/product.ejs @@ -4,7 +4,7 @@
-
+
diff --git a/views/users_logued.ejs b/views/users_logued.ejs new file mode 100644 index 0000000..575053d --- /dev/null +++ b/views/users_logued.ejs @@ -0,0 +1,7 @@ +<%- include('partials/header') %> + +
+

Usuario:

+
+ +<%- include('partials/footer') %> \ No newline at end of file From 7e9edd607d669a044d9e08e80666c9c03775a9df Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:14:51 -0300 Subject: [PATCH 29/37] Products Server Side --- app/server/components/ProductsCardComponent.ts | 5 ++--- app/server/controllers/product.get.ts | 1 - app/server/controllers/products.get.ts | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/server/components/ProductsCardComponent.ts b/app/server/components/ProductsCardComponent.ts index 26425d0..e3f242b 100644 --- a/app/server/components/ProductsCardComponent.ts +++ b/app/server/components/ProductsCardComponent.ts @@ -6,8 +6,7 @@ export default function ProductsCardComponent( id, price, title - }: Product, - isFavorite: boolean + }: Product ): string { return /* html */ `
@@ -16,7 +15,7 @@ export default function ProductsCardComponent( -
+
diff --git a/app/server/controllers/product.get.ts b/app/server/controllers/product.get.ts index 38df3e2..500f5c8 100644 --- a/app/server/controllers/product.get.ts +++ b/app/server/controllers/product.get.ts @@ -9,7 +9,6 @@ module.exports = function productGet(req: any, res: any) { const config: any = product; config.productSpecs = ProductSpecsComponent(product.caracts); - config.isFavorite = true; res.render("product", config); }; diff --git a/app/server/controllers/products.get.ts b/app/server/controllers/products.get.ts index a290eba..e02aadd 100644 --- a/app/server/controllers/products.get.ts +++ b/app/server/controllers/products.get.ts @@ -11,7 +11,7 @@ module.exports = function productsGet(req: any, res: any) { const { products, page, maxPage } = new ProductsAPI(req).getProducts(); const productsHTML: htmlString = products - .map((product: Product): string => ProductsCardComponent(product, true)) + .map((product: Product): string => ProductsCardComponent(product)) .join(""); const paginatorHTML: htmlString = PaginatorComponent(page, maxPage); From 5567460dd30d4f97bfdc0ac6dacdf03969cafd3a Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:16:11 -0300 Subject: [PATCH 30/37] Favorites --- app/client/class/Favorites.ts | 55 ++++------------- app/client/listeners/favoritesListener.ts | 29 ++++++--- app/server/classes/FavoritesAPI.ts | 72 +++++++++++++++++++++++ app/server/controllers/favorites.post.ts | 10 ++++ app/server/controllers/favorites.put.ts | 9 +++ app/server/interfaces/Favorites.ts | 6 ++ 6 files changed, 130 insertions(+), 51 deletions(-) create mode 100644 app/server/classes/FavoritesAPI.ts create mode 100644 app/server/controllers/favorites.post.ts create mode 100644 app/server/controllers/favorites.put.ts create mode 100644 app/server/interfaces/Favorites.ts diff --git a/app/client/class/Favorites.ts b/app/client/class/Favorites.ts index 66bf7db..59cb2e6 100644 --- a/app/client/class/Favorites.ts +++ b/app/client/class/Favorites.ts @@ -1,61 +1,28 @@ import { favoritesArray } from "../types/favorites"; import { productID } from "../types/products"; -import Storage from "./Storage"; +import Router from "./Router"; +import API from "./API"; -import { SS_FAVORITES } from "../config"; +import UsersStorage from "./UsersStorage"; -export default class Favorites extends Storage { +export default class Favorites extends UsersStorage { constructor() { - super(SS_FAVORITES, []); + super(); } - public addToFavorites(productID: productID): void { - const favoritesSet: Set = new Set(this.getStorage()).add(productID); - this.updateFavorites(favoritesSet); - } - - public removeFromFavorite(productID: number): void { - const favoritesSet: Set = new Set(this.getStorage()) - favoritesSet.delete(productID); - this.updateFavorites(favoritesSet); - } - - public handleFavorite(productID: number): void { - const favoritesSet: Set = new Set(this.getStorage()); - if (favoritesSet.has(productID)) { - favoritesSet.delete(productID); - return - } - favoritesSet.add(productID); - } - - /** - * @return if the Cart is empty or not. - */ - public isEmpty(): boolean { - return this.getStorage().length === 0; + public async toggleFavorites(productID: productID): Promise { + return await API.fetchAPI(this.getFavoritesAPI(`${productID}`), {}, "PUT"); } /** * @return favorites products. */ - public getFavorites(): favoritesArray { - return this.getStorage(); + public async getFavorites(): Promise { + return (await API.fetchAPI(this.getFavoritesAPI())).favorites; } - /** - * @return favorites products. - */ - public isFavorite(id: number): boolean { - return this.getStorage().includes(id);; - } - - /** - * Update the Favorites Products Storage. - */ - private updateFavorites(favoritesSet: Set): void { - const favoritesArray: favoritesArray = [...favoritesSet]; - this.updateStorage(favoritesArray); + private getFavoritesAPI(productID: string = ""): string { + return Router.createURL(`/favorites/${this.getUser()}/${productID}`); } } diff --git a/app/client/listeners/favoritesListener.ts b/app/client/listeners/favoritesListener.ts index bba823d..35a1cb4 100644 --- a/app/client/listeners/favoritesListener.ts +++ b/app/client/listeners/favoritesListener.ts @@ -1,20 +1,35 @@ -import app from "../main"; +import Favorites from "../class/Favorites"; +import Users from "../class/Users"; // HTML const FAVORITES_ICONS: HTMLCollectionOf = document.getElementsByClassName("favorites-icon"); // EVENTS -const SEARCH_INPUT_S_EVENT: string = "keyup"; +const FAVORITES_ICON_EVENT: string = "click"; + +export default async function favoritesListener( + users: Users, + favorites: Favorites +): Promise { + const favoritesArray = await favorites.getFavorites(); + const isLogued: boolean = users.isLogued(); -export default function favoritesListener(): void { Array.from(FAVORITES_ICONS).forEach((favorites_icon: Element): void => { - favorites_icon.addEventListener(SEARCH_INPUT_S_EVENT, (e) => { - if (!app.users.isLogued()) { + const favoriteID: number = +(favorites_icon as HTMLElement).dataset.id; + + if (favoritesArray.includes(`${favoriteID}`)) { + favorites_icon.classList.add("selected"); + } + + favorites_icon.addEventListener(FAVORITES_ICON_EVENT, () => { + if (!isLogued) { return alert("Necesitas estar Logueado!"); } const productID: number = +(favorites_icon as HTMLElement).dataset.id; - app.favorites.handleFavorite(productID); + favorites.toggleFavorites(`${productID}`); + + favorites_icon.classList.toggle("selected"); }); }); -} +} \ No newline at end of file diff --git a/app/server/classes/FavoritesAPI.ts b/app/server/classes/FavoritesAPI.ts new file mode 100644 index 0000000..fa4a4e7 --- /dev/null +++ b/app/server/classes/FavoritesAPI.ts @@ -0,0 +1,72 @@ +import Favorites from "../interfaces/Favorites"; + +import { favoritesArray } from "../types/favorites"; + +import DataBase from "./DataBase"; + +export default class FavoritesAPI extends DataBase { + private params: any = {}; + private favorites: Favorites[] = []; + + constructor(params: any) { + super("favorites"); + this.params = params; + this.favorites = this.getTable(); + } + + public toggleFavorites(): boolean { + const { id } = this.params; + const userFavorites: Favorites = this.returnFavorites(); + + const favoritesSet: Set = new Set(userFavorites.favoritesProducts); + let state: boolean; + + if (favoritesSet.has(id)) { + favoritesSet.delete(id); + state = false; + } else { + favoritesSet.add(id); + state = true; + } + + userFavorites.favoritesProducts = Array.from(favoritesSet); + this.setFavorites(userFavorites); + return state; + } + + public isFavorite(id: number): boolean { + return this.getFavorites().includes(id); + } + + public getFavorites(): favoritesArray { + return this.returnFavorites().favoritesProducts; + } + + private returnFavorites(): Favorites { + const { userID } = this.params; + return ( + this.favorites.find((userFavorites) => userFavorites.id === userID) || { + id: userID, + favoritesProducts: [], + } + ); + } + + private setFavorites(data: Favorites) { + let noChange: boolean = true; + + const favorites: Favorites[] = this.favorites.map((userFavorites) => { + if (userFavorites.id === data.id) { + userFavorites = data; + noChange = false; + } + return userFavorites; + }); + + if (noChange) { + favorites.push(data); + } + + this.setTable("favorites", favorites); + } +} diff --git a/app/server/controllers/favorites.post.ts b/app/server/controllers/favorites.post.ts new file mode 100644 index 0000000..7fa228d --- /dev/null +++ b/app/server/controllers/favorites.post.ts @@ -0,0 +1,10 @@ +import { favoritesArray } from "../types/favorites"; + +import FavoritesAPI from "../classes/FavoritesAPI"; + +module.exports = function favoritesPost(req: any, res: any) { + const favorites: favoritesArray = new FavoritesAPI(req.params).getFavorites(); + return res.json({ + favorites, + }); +}; diff --git a/app/server/controllers/favorites.put.ts b/app/server/controllers/favorites.put.ts new file mode 100644 index 0000000..11c0f40 --- /dev/null +++ b/app/server/controllers/favorites.put.ts @@ -0,0 +1,9 @@ +import FavoritesAPI from "../classes/FavoritesAPI"; + +module.exports = function favoritesPut(req: any, res: any) { + const createState: boolean = new FavoritesAPI(req.params).toggleFavorites(); + + res.json({ + createState, + }); +}; diff --git a/app/server/interfaces/Favorites.ts b/app/server/interfaces/Favorites.ts new file mode 100644 index 0000000..951f281 --- /dev/null +++ b/app/server/interfaces/Favorites.ts @@ -0,0 +1,6 @@ +import { favoritesArray } from "../types/favorites"; + +export default interface Favorites { + id: number, + favoritesProducts: favoritesArray +} \ No newline at end of file From 9e40fcca974c2528111cf485ce7bf2d1459da30c Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:17:00 -0300 Subject: [PATCH 31/37] Users Class Refactor --- app/client/class/Users.ts | 24 +++++++++++++----------- app/client/class/UsersStorage.ts | 25 +++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 app/client/class/UsersStorage.ts diff --git a/app/client/class/Users.ts b/app/client/class/Users.ts index 4f8a806..f9840f0 100644 --- a/app/client/class/Users.ts +++ b/app/client/class/Users.ts @@ -1,16 +1,10 @@ -import User from "../interfaces/User"; - import API from "./API"; import Router from "./Router"; -import Storage from "./Storage"; +import UsersStorage from "./UsersStorage"; -export default class Users extends Storage { +export default class Users extends UsersStorage { constructor() { - super("user", { - id: null, - email: "", - password: "", - }); + super(); } public async loginUser(email: string, password: string): Promise { @@ -37,7 +31,15 @@ export default class Users extends Storage { }) } - public isLogued(): boolean { - return !!this.getStorage().id; + public getEmail() { + return super.getEmail(); + } + + public getUser() { + return super.getUser(); + } + + public isLogued() { + return super.isLogued(); } } diff --git a/app/client/class/UsersStorage.ts b/app/client/class/UsersStorage.ts new file mode 100644 index 0000000..c0f0282 --- /dev/null +++ b/app/client/class/UsersStorage.ts @@ -0,0 +1,25 @@ +import User from "../interfaces/User"; + +import Storage from "./Storage"; + +export default class UsersStorage extends Storage { + constructor() { + super("user", { + id: null, + email: "", + password: "", + }); + } + + protected getUser(): number { + return +this.getStorage().id; + } + + protected getEmail(): string { + return this.getStorage().email; + } + + protected isLogued(): boolean { + return !!this.getStorage().id; + } +} From bbfa85112cb3c96d2469cb8187df7d0f5e972a8b Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:17:33 -0300 Subject: [PATCH 32/37] bundle --- public/js/app.min.js | 1 - 1 file changed, 1 deletion(-) delete mode 100644 public/js/app.min.js diff --git a/public/js/app.min.js b/public/js/app.min.js deleted file mode 100644 index 0464cf8..0000000 --- a/public/js/app.min.js +++ /dev/null @@ -1 +0,0 @@ -(()=>{"use strict";var t={24:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0)&&!(r=a.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=a.return)&&n.call(a)}finally{if(o)throw o.error}}return u},u=this&&this.__spreadArray||function(t,e,n){if(n||2===arguments.length)for(var r,o=0,a=e.length;o{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(){}return t.followWithParams=function(e,n){window.location.replace(window.location.origin+e+t.stringfyParams(n))},t.followWithCurrentParams=function(e){window.location.replace(window.location.origin+e+t.getParams())},t.getParams=function(){return window.location.search},t.createURL=function(t){return window.location.origin+t},t.stringfyParams=function(t){return"?"+Object.keys(t).map((function(e){return e+"="+t[e]})).join("&")},t}();e.default=n},983:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t,e){this.storageName=t,sessionStorage.getItem(t)||sessionStorage.setItem(t,JSON.stringify(e))}return t.prototype.updateStorage=function(t){sessionStorage.setItem(this.storageName,JSON.stringify(t))},t.prototype.deleteStorage=function(){sessionStorage.removeItem(this.storageName)},t.prototype.getStorage=function(){return JSON.parse(sessionStorage.getItem(this.storageName))},t}();e.default=n},930:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(236)),a=r(n(534)),u=function(){function t(t){this.document=t}return t.prototype.products=function(t,e,n,r){e.map((function(e){return(0,o.default)(e,t.isFavorite(e.id))})).join(""),(0,a.default)(n||1,r)},t}();e.default=u},603:function(t,e,n){var r,o=this&&this.__extends||(r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},r(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),a=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},u=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.units,n=t.price,r=t.total,o=t.id;return'\n \n \n
-1
\n
+1
\n \n \n \n '+t.title+'\n \n \n '+e+'\n $'+n+'\n $'+r+"\n \n "}},596:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(497));e.default=function(t){var e=0;return{CartTable:Object.values(t).map((function(t){return e+=t.total,(0,o.default)(t)})).join(""),total:e}}},539:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.SS_FAVORITES=e.SS_CART=e.API_ERROR=e.API_POSTS=e.CURRENT_PAGE=e.DEFAULT_HTML_FILE=e.PAGES=e.SEARCH_PAIR_INPUTS=e.QUANTITY_PRODUCTS_INDICATOR=void 0;var n=document.getElementById("search-input-s"),r=document.getElementById("search-input"),o=document.getElementById("quantityProducts");e.QUANTITY_PRODUCTS_INDICATOR=o;var a=window.location.pathname.split("/")[1];e.CURRENT_PAGE=a,e.PAGES=["index","cart","products","product","error"],e.DEFAULT_HTML_FILE="index";var u={"search-button-s":n,"search-button":r};e.SEARCH_PAIR_INPUTS=u,e.API_POSTS="https://jsonplaceholder.typicode.com/posts/",e.API_ERROR="ERROR",e.SS_CART="cart",e.SS_FAVORITES="favorites"},677:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},2:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){alert(t)}},750:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(503));e.default=function(t,e,n){t.addEventListener("click",(function(t){var r=(0,o.default)(t);e.addToCart(r),n()}))}},931:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var n=document.getElementsByClassName("openNav-button"),r=document.getElementById("nav-container");e.default=function(){Array.from(n).forEach((function(t){t.addEventListener("click",(function(){r.classList.toggle("active")}))}))}},764:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(632)),a=document.getElementsByClassName("js-paginator");e.default=function(){Array.from(a).forEach((function(t){t.addEventListener("click",(function(t){var e=t.target.dataset.page;o.default.followWithCurrentParams("/products/"+e)}))}))}},290:function(t,e,n){var r=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});var o=r(n(555)),a=r(n(513)),u=document.getElementById("search-button-s"),i=document.getElementById("search-button"),c=document.getElementById("search-input-s"),s=document.getElementById("search-input");e.default=function(){c.addEventListener("keyup",a.default),s.addEventListener("keyup",a.default),u.addEventListener("click",o.default),i.addEventListener("click",o.default)}},170:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){var e=t.target.parentElement.dataset.productId;return Number(e)}},260:function(t,e,n){var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(o,a){function u(t){try{c(r.next(t))}catch(t){a(t)}}function i(t){try{c(r.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,i)}c((r=r.apply(t,e||[])).next())}))},o=this&&this.__generator||function(t,e){var n,r,o,a,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]{Object.defineProperty(e,"__esModule",{value:!0});var r=n(539);e.default=function(t){r.QUANTITY_PRODUCTS_INDICATOR.innerHTML=String(t)}},534:(t,e)=>{function n(t,e,n){return t>0&&t<=e?'\n \n '+t+"\n \n ":""}function r(t,e,n,r){return r&&e>3?'\n \n '+n+"\n \n ":""}Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var o=t-1,a=t,u=t+1;return 1===t?(++o,++a,++u):t===e&&(--o,--a,--u),"\n "+r(1,e,"<<",t>2)+"\n "+n(o,e,t)+"\n "+n(a,e,t)+"\n "+n(u,e,t)+"\n "+r(e,e,">>",t{Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t,e){var n=t.image,r=t.id,o=t.price;return'\n
\n
\n
\n \n \n \n
\n ★\n
\n
\n
\n
\n
'+t.title+"
\n
$"+o+'
\n
\n Comprar\n
\n '}}},e={};!function n(r){var o=e[r];if(void 0!==o)return o.exports;var a=e[r]={exports:{}};return t[r].call(a.exports,a,a.exports,n),a.exports}(266)})(); \ No newline at end of file From 338e487eb4c850d0a30d03a97270a9110b3698e0 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:18:34 -0300 Subject: [PATCH 33/37] Routes --- app/client/class/Router.ts | 39 +++++++++++++++++------------ app/server/controllers/users.get.ts | 4 +++ app/server/routes.ts | 6 +++++ 3 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/client/class/Router.ts b/app/client/class/Router.ts index 15f5844..9b08563 100644 --- a/app/client/class/Router.ts +++ b/app/client/class/Router.ts @@ -1,22 +1,21 @@ +import { htmlFileName } from "../types/search"; + export default class Router { - public static followWithParams( - path: string, - params: any - ): void { - window.location.replace( - window.location.origin + path + Router.stringfyParams(params) - ); + public static follow(path: string): void { + window.location.replace(window.location.origin + path); } - public static followWithCurrentParams( - path: string - ): void { + public static followWithQuery(path: string, query: any): void { window.location.replace( - window.location.origin + path + Router.getParams() + window.location.origin + path + Router.stringfyQuery(query) ); } - public static getParams(): string { + public static followWithCurrentQuery(path: string): void { + window.location.replace(window.location.origin + path + Router.getQuery()); + } + + public static getQuery(): string { return window.location.search; } @@ -24,12 +23,20 @@ export default class Router { return window.location.origin + path; } - private static stringfyParams(params: any): string { + public static getPage(): htmlFileName { + return window.location.pathname.split("/")[1] as htmlFileName; + } + + public static getParam(nParam: number): string { + return window.location.pathname.split("/")[nParam + 1]; + } + + private static stringfyQuery(query: any): string { return ( "?" + - Object.keys(params) - .map((key) => `${key}=${params[key]}`) + Object.keys(query) + .map((key) => `${key}=${query[key]}`) .join("&") ); } -} \ No newline at end of file +} diff --git a/app/server/controllers/users.get.ts b/app/server/controllers/users.get.ts index 7131c04..4fe49e7 100644 --- a/app/server/controllers/users.get.ts +++ b/app/server/controllers/users.get.ts @@ -1,3 +1,7 @@ module.exports = function usersGet(req: any, res: any) { + if (req.params.userID) { + + return res.render('users_logued'); + } res.render('users'); } \ No newline at end of file diff --git a/app/server/routes.ts b/app/server/routes.ts index a3f676c..ae1e2b9 100644 --- a/app/server/routes.ts +++ b/app/server/routes.ts @@ -9,9 +9,11 @@ const usersGet = require("./controllers/users.get"); const cartGet = require("./controllers/cart.get"); const productsIDsPost = require("./controllers/productsIDs.post"); +const favoritesPost = require("./controllers/favorites.post"); const productsPost = require("./controllers/products.post"); const usersPost = require("./controllers/users.post"); +const favoritesPut = require("./controllers/favorites.put"); const usersPut = require("./controllers/users.put"); router.get("/", indexGet); @@ -21,6 +23,7 @@ router.get("/products", productsGet); router.get("/product/:id", productGet); +router.get("/users/:userID", usersGet); router.get("/users", usersGet); router.get("/cart", cartGet); @@ -32,10 +35,13 @@ router.post("/products", productsPost); router.post("/users", usersPost); +router.post("/favorites/:userID", favoritesPost); // PUT router.put("/users", usersPut); +router.put("/favorites/:userID/:id", favoritesPut); + router.use((req: any, res: any) => { res.status(404).render("404"); From aa5ce8780002732b31ee6256090854f9d710e3d0 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:19:40 -0300 Subject: [PATCH 34/37] Users View --- app/client/class/API.ts | 21 +++++++++++++++++ app/client/class/App.ts | 23 ++++++++++++++----- app/client/handlers/loginHandler.ts | 6 ++++- app/client/handlers/registerHandler.ts | 11 ++++++--- app/client/listeners/loginRegisterListener.ts | 4 ++-- app/client/scripts/sendSearchRequest.ts | 2 +- 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/app/client/class/API.ts b/app/client/class/API.ts index c949205..d4f0e67 100644 --- a/app/client/class/API.ts +++ b/app/client/class/API.ts @@ -27,6 +27,27 @@ export default abstract class API { return (responseJson as any).message; } + public static async fetchRedirectAPI( + url: string, + data?: object, + method: string = "POST" + ): Promise { + const response = await fetch(url, { + method, + headers: { + "Content-Type": "application/json", + }, + redirect: "follow", + body: JSON.stringify(data), + }); + const responseJson = await response.json(); + + if (response.ok) { + return Object.keys(responseJson).length === 0 ? API_ERROR : responseJson; + } + return (responseJson as any).message; + } + /** * * @param apiResponse An API method return diff --git a/app/client/class/App.ts b/app/client/class/App.ts index 53171de..ffc65b0 100644 --- a/app/client/class/App.ts +++ b/app/client/class/App.ts @@ -1,4 +1,5 @@ // LISTENERES +import loginRegisterListener from "../listeners/loginRegisterListener"; import menuHandlerListener from "../listeners/menuHandlerListener"; import closeCartListener from "../listeners/closeCartListener"; import paginatorListener from "../listeners/paginatorListener"; @@ -7,15 +8,17 @@ import shopListener from "../listeners/shopListener"; // CLASSES import Favorites from "./Favorites"; +import Router from "./Router"; import Users from "./Users"; import Cart from "./Cart"; import UI from "./UI"; // SCRIPTS import updateQuantityProducts from "../scripts/updateQuantityProducts"; +import loadUsers from "../scripts/loadUsers"; import loadTable from "../scripts/loadTable"; import { CURRENT_PAGE } from "../config"; -import loginRegisterListener from "../listeners/loginRegisterListener"; +import favoritesListener from "../listeners/favoritesListener"; export default class App { public ui: UI; @@ -34,8 +37,8 @@ export default class App { constructor(HTML_APP: HTMLElement) { this.ui = new UI(HTML_APP); this.cart = new Cart(); - this.favorites = new Favorites(); this.users = new Users(); + this.favorites = new Favorites(); } /** @@ -57,14 +60,15 @@ export default class App { * Loads all listeners for Products. */ private productsPrepare(): void { + this.productPrepare(); paginatorListener(); - shopListener(this.cart); } /** * Loads all listeners for Product. */ private productPrepare(): void { + favoritesListener(this.users, this.favorites); shopListener(this.cart); } @@ -76,10 +80,17 @@ export default class App { loadTable(this.cart); } - /** + /** * Loads all listeners for Users. */ - private usersPrepare(): void { - loginRegisterListener(); + private async usersPrepare(): Promise { + if (this.users.isLogued()) { + if (!Router.getParam(1)) { + return Router.follow(`/users/${this.users.getUser()}`); + } + return await loadUsers(this.users, this.favorites); } + + loginRegisterListener(); + } } diff --git a/app/client/handlers/loginHandler.ts b/app/client/handlers/loginHandler.ts index 67b3765..c5dcac1 100644 --- a/app/client/handlers/loginHandler.ts +++ b/app/client/handlers/loginHandler.ts @@ -13,5 +13,9 @@ export default async function loginHandler(): Promise { }; const response = await app.users.loginUser(email, password); - return alert(response ? response : "Logueado con Éxito"); + if (response) { + return alert(response); + } + + return alert("Logueado con Éxito"); } diff --git a/app/client/handlers/registerHandler.ts b/app/client/handlers/registerHandler.ts index f019424..7b6386d 100644 --- a/app/client/handlers/registerHandler.ts +++ b/app/client/handlers/registerHandler.ts @@ -10,11 +10,16 @@ export default async function registerHandler(): Promise { new FormData(REGISTER_FORM).entries() ) as { [index: string]: string }; - if (password === passwordRepeat) { + if (email && password === passwordRepeat) { const response = await app.users.registerUser(email, password); - return alert(response ? response : "Registrado con Éxito"); + console.log(response) + if (response) { + return alert(response); + } + + return alert("Registrado con Éxito"); } - alert("Las contraseñas no coinciden."); + return alert("Las contraseñas no coinciden."); } diff --git a/app/client/listeners/loginRegisterListener.ts b/app/client/listeners/loginRegisterListener.ts index 8a9fc3c..1e7fee0 100644 --- a/app/client/listeners/loginRegisterListener.ts +++ b/app/client/listeners/loginRegisterListener.ts @@ -3,7 +3,7 @@ import registerHandler from "../handlers/registerHandler"; // HTML const LOGIN_FORM_BTN: HTMLElement = document.getElementById("js-loginFormBTN"); -const REGISTER_FORM: HTMLElement = document.getElementById("js-registerForm"); +const REGISTER_FORM_BTN: HTMLElement = document.getElementById("js-registerFormBTN"); // EVENTS const REGISTER_FORM_BTN_EVENT: string = "click"; @@ -11,5 +11,5 @@ const LOGIN_FORM_BTN_EVENT: string = "click"; export default function loginRegisterListener(): void { LOGIN_FORM_BTN.addEventListener(LOGIN_FORM_BTN_EVENT, loginHandler); - REGISTER_FORM.addEventListener(REGISTER_FORM_BTN_EVENT, registerHandler); + REGISTER_FORM_BTN.addEventListener(REGISTER_FORM_BTN_EVENT, registerHandler); } \ No newline at end of file diff --git a/app/client/scripts/sendSearchRequest.ts b/app/client/scripts/sendSearchRequest.ts index 55b1eb4..2e8c294 100644 --- a/app/client/scripts/sendSearchRequest.ts +++ b/app/client/scripts/sendSearchRequest.ts @@ -6,7 +6,7 @@ export default function sendSearchRequest( ): void { //if (CURRENT_PAGE !== "products") { console.log(input.value) - return Router.followWithParams("/products", { + return Router.followWithQuery("/products", { search: input.value }) //} From b97eba0e210040a83035dd8c40831e02d4e482c5 Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:19:58 -0300 Subject: [PATCH 35/37] Users View --- app/client/scripts/loadUsers.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 app/client/scripts/loadUsers.ts diff --git a/app/client/scripts/loadUsers.ts b/app/client/scripts/loadUsers.ts new file mode 100644 index 0000000..917a2c0 --- /dev/null +++ b/app/client/scripts/loadUsers.ts @@ -0,0 +1,17 @@ +import { favoritesArray } from "../types/favorites"; + +import Favorites from "../class/Favorites"; +import Users from "../class/Users"; + +// HTML; +const USER_EMAIL: HTMLElement = document.getElementById("user-email"); + +/** + * Loads the Table Body of the Cart View + */ +export default async function loadUsers(users: Users, favorites: Favorites): Promise { + USER_EMAIL.innerHTML = users.getEmail(); + + const favoritesArray: favoritesArray = await favorites.getFavorites(); + console.log(favoritesArray) +} From d4b7bf79cda4f94f5624c8a2135aa5a410b37d8b Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:20:39 -0300 Subject: [PATCH 36/37] Paginator --- app/client/class/UI.ts | 6 ++---- app/client/listeners/paginatorListener.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/client/class/UI.ts b/app/client/class/UI.ts index ca9f7e9..2217403 100644 --- a/app/client/class/UI.ts +++ b/app/client/class/UI.ts @@ -31,10 +31,8 @@ export default class UI { maxPage: number ): void { const innerHTML: string = products - .map((product: Product): string => - ProductsCardComponent(product, favorites.isFavorite(product.id)) - ) + .map((product: Product): string => ProductsCardComponent(product)) .join(""); - PaginatorComponenet(page || 1, maxPage) + PaginatorComponenet(page || 1, maxPage); } } diff --git a/app/client/listeners/paginatorListener.ts b/app/client/listeners/paginatorListener.ts index 7d338e1..7672b15 100644 --- a/app/client/listeners/paginatorListener.ts +++ b/app/client/listeners/paginatorListener.ts @@ -14,7 +14,7 @@ export default function paginatorListener(): void { (e: Event): void => { const page: string = (e.target as HTMLElement).dataset.page; - Router.followWithCurrentParams(`/products/${page}`); + Router.followWithCurrentQuery(`/products/${page}`); } ); }); From c97ace1b1aebff355c756aecc40dcb664f51f00d Mon Sep 17 00:00:00 2001 From: chachopacho Date: Tue, 19 Oct 2021 12:20:56 -0300 Subject: [PATCH 37/37] config --- app/client/config.ts | 4 +++- app/client/types/products.ts | 2 +- app/client/types/search.ts | 2 +- app/server/tsconfig.json | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/client/config.ts b/app/client/config.ts index ae25043..97f6c72 100644 --- a/app/client/config.ts +++ b/app/client/config.ts @@ -1,13 +1,15 @@ import { apiError, apiURL } from "./types/api"; import { htmlFileName } from "./types/search"; +import Router from "./class/Router"; + // HTML const SEARCH_INPUT_S: HTMLElement = document.getElementById("search-input-s"); const SEARCH_INPUT: HTMLElement = document.getElementById("search-input"); const QUANTITY_PRODUCTS_INDICATOR: HTMLElement = document.getElementById("quantityProducts") // GENERAL -const CURRENT_PAGE: htmlFileName = window.location.pathname.split("/")[1] as htmlFileName; +const CURRENT_PAGE: htmlFileName = Router.getPage(); const PAGES: htmlFileName[] = ["index", "cart", "products", "product", "error"]; const DEFAULT_HTML_FILE: htmlFileName = "index"; const SEARCH_PAIR_INPUTS: { diff --git a/app/client/types/products.ts b/app/client/types/products.ts index 6ce0d5b..e422eaf 100644 --- a/app/client/types/products.ts +++ b/app/client/types/products.ts @@ -1,4 +1,4 @@ -type productID = number; +type productID = string; export { productID diff --git a/app/client/types/search.ts b/app/client/types/search.ts index d731435..09b538c 100644 --- a/app/client/types/search.ts +++ b/app/client/types/search.ts @@ -5,7 +5,7 @@ type searchURLSetter = { search?: string } type searchParam = "htmlFileName" | "page" | "cod" | "search"; -type htmlFileName = "index" | "cart" | "product" | "products" | "error"; +type htmlFileName = "index" | "cart" | "product" | "products" | "error" | "users"; export { searchURLSetter, diff --git a/app/server/tsconfig.json b/app/server/tsconfig.json index dbba8ab..ac35a9c 100644 --- a/app/server/tsconfig.json +++ b/app/server/tsconfig.json @@ -52,7 +52,7 @@ // "noEmit": true, /* Disable emitting files from a compilation. */ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */ - // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */