Fixed small bugs

This commit is contained in:
Niklas Fondberg
2021-04-08 23:27:55 +02:00
parent 3c648cee29
commit a296ead1ca
7 changed files with 78 additions and 84 deletions
+13 -17
View File
@@ -55,6 +55,13 @@ export class ProductAPI extends SQLDataSource {
});
}
createProductFromRow(row: any) {
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}
async getProducts(
limit: Maybe<number>,
visible: Maybe<boolean>,
@@ -63,28 +70,17 @@ export class ProductAPI extends SQLDataSource {
limit = limit ?? 100;
const query = sql.products(limit, visible, browsable);
return await this.knex.raw(query).then((data) =>
data.rows.map((row) => {
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}),
);
return await this.knex
.raw(query)
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
}
async getProduct(id: number): Promise<Maybe<Product>> {
const query = sql.product(id);
const res = await this.knex.raw(query).then((data) =>
data.rows.map((row) => {
console.log(row);
row.blacklisting = this.getBlacklisting(row);
row.printProducts = this.getPrintProducts(row);
row.designerId = row.designerid;
return row;
}),
);
const res = await this.knex
.raw(query)
.then((data) => data.rows.map((row) => this.createProductFromRow(row)));
return res.find(Boolean);
}
}