3124: added listprice to printproduct and public access to product and designers (#138)
This commit is contained in:
@@ -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('*')
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -199,3 +199,7 @@ export function searchByFieldValue(fieldid: number) {
|
||||
`
|
||||
);
|
||||
}
|
||||
|
||||
export function getProductListPrice() {
|
||||
return 'SELECT listprice FROM v_listprices WHERE market_id = ? AND printproduct_id = ?';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user