3124: added listprice to printproduct and public access to product and designers (#138)

This commit is contained in:
Arwid Thornström
2022-12-19 09:29:47 +01:00
committed by GitHub
parent 28d643003e
commit 62b93a3656
9 changed files with 69 additions and 8 deletions
+4 -1
View File
@@ -10,7 +10,10 @@ export class DesignerAPI extends BaseSQLDataSource {
}
async getDesignerById(id: number): Promise<Designer> {
ScopeAccess.validate(this.user).all([Scopes.DESIGNERS_READ]);
ScopeAccess.validate(this.user).some([
Scopes.DESIGNERS_READ,
Scopes.DESIGNERS_PUBLIC_READ,
]);
return (
this.knex
.select('*')
+27 -2
View File
@@ -220,7 +220,10 @@ export class ProductAPI extends BaseSQLDataSource {
}
async getProducts(input: ProductsFilterInput): Promise<Array<Product>> {
ScopeAccess.validate(this.user).some([Scopes.PRODUCTS_READ]);
ScopeAccess.validate(this.user).some([
Scopes.PRODUCTS_READ,
Scopes.PRODUCTS_PUBLIC_READ,
]);
const query = sql.products(input);
return this.knex
@@ -229,7 +232,10 @@ export class ProductAPI extends BaseSQLDataSource {
}
async getProduct(id: number): Promise<Maybe<Product>> {
ScopeAccess.validate(this.user).some([Scopes.PRODUCTS_READ]);
ScopeAccess.validate(this.user).some([
Scopes.PRODUCTS_READ,
Scopes.PRODUCTS_PUBLIC_READ,
]);
const query = sql.product();
const res = await this.knex.raw(query, [id]).then((data) =>
@@ -241,6 +247,25 @@ export class ProductAPI extends BaseSQLDataSource {
return res.find(Boolean);
}
async getListPrice(
printId: number,
marketId: number,
): Promise<Maybe<number>> {
ScopeAccess.validate(this.user).some([
Scopes.PRODUCTS_READ,
Scopes.PRODUCTS_PUBLIC_READ,
]);
const query = sql.getProductListPrice();
try {
const res = await this.knex.raw(query, [marketId, printId]);
return res.rows[0].listprice;
} catch (error) {
throw new GraphQLError('No listprice found', {
extensions: { code: ApolloServerErrorCode.BAD_USER_INPUT },
});
}
}
async getProductByPath(path: string): Promise<Maybe<Product>> {
ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_READ]);
const query = sql.productByPath();
+4
View File
@@ -199,3 +199,7 @@ export function searchByFieldValue(fieldid: number) {
`
);
}
export function getProductListPrice() {
return 'SELECT listprice FROM v_listprices WHERE market_id = ? AND printproduct_id = ?';
}