Skip to content

Commit

Permalink
mend
Browse files Browse the repository at this point in the history
  • Loading branch information
ChachoPacho committed Oct 15, 2021
1 parent 87a8a86 commit f8ca37c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
js/
node_modules/
build/
public/js/
2 changes: 1 addition & 1 deletion app/client/class/Router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default class Router {
return (
"?" +
Object.keys(params)
.map((key) => `${key}=params[key]`)
.map((key) => `${key}=${params[key]}`)
.join("&")
);
}
Expand Down
3 changes: 2 additions & 1 deletion app/client/scripts/sendSearchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
//}
}
4 changes: 3 additions & 1 deletion app/server/classes/ProductsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion build/client/class/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion build/client/scripts/sendSearchRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
//}
}
Expand Down
5 changes: 4 additions & 1 deletion build/server/classes/ProductsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion public/js/app.min.js

Large diffs are not rendered by default.

0 comments on commit f8ca37c

Please sign in to comment.