more consise queries

Former-commit-id: c71f7e45cba96c48888fadf1d5c3ab7345a61510
This commit is contained in:
Ben
2022-04-13 19:07:44 +01:00
parent e9f812290c
commit 27416940c6
2 changed files with 14 additions and 1 deletions

View File

@@ -12,7 +12,7 @@ class ProductList extends Component {
const products = await fetch(route).then(response => response.json());
this.setState({
...this.getState,
products: products.data,
products,
current_page: products.page.current_page,
last_page: products.page.last_page,
total: products.page.total,

View File

@@ -16,6 +16,18 @@ function ValidateQuery(query) {
};
}
async function GetSet(setId) {
await Database.Query('BEGIN TRANSACTION;');
const dbres = await Database.Query(`
SELECT id, name, price, new_price AS "discount", inv.stock
FROM lego_set
LEFT JOIN lego_set_inventory AS inv ON inv.set_id = lego_set.id
WHERE id = $1::int;
`);
console.log(dbres);
await Database.Query('END TRANSACTION;');
}
async function GetSets(page, resPerPage) {
// query for the set
await Database.Query('BEGIN TRANSACTION;');
@@ -44,5 +56,6 @@ async function GetSets(page, resPerPage) {
module.exports = {
ValidateQuery,
GetSet,
GetSets,
};