Fix scopes and promise handling (#152)
This commit is contained in:
@@ -103,7 +103,10 @@ export class InteriorAPI extends BaseSQLDataSource {
|
||||
// ----------------------------
|
||||
|
||||
async getInteriors(filter: Maybe<InteriorsFilter>): Promise<Array<Interior>> {
|
||||
ScopeAccess.validate(this.user).all([Scopes.INTERIORS_READ]);
|
||||
ScopeAccess.validate(this.user).some([
|
||||
Scopes.INTERIORS_READ,
|
||||
Scopes.INTERIORS_PUBLIC_READ,
|
||||
]);
|
||||
const sql = /* sql */ `
|
||||
SELECT rooms.*, room_types.name roomType FROM rooms
|
||||
LEFT JOIN room_types ON rooms.room_type_id = room_types.id
|
||||
@@ -161,9 +164,9 @@ export class InteriorAPI extends BaseSQLDataSource {
|
||||
async getPrintProductInteriorsBatch(
|
||||
printIds: number[],
|
||||
): Promise<InteriorWithPrintId[]> {
|
||||
ScopeAccess.validate(this.user).all([
|
||||
ScopeAccess.validate(this.user).some([
|
||||
Scopes.INTERIORS_READ,
|
||||
Scopes.PRODUCTS_READ,
|
||||
Scopes.INTERIORS_PUBLIC_READ,
|
||||
]);
|
||||
return this.knex
|
||||
.select('*')
|
||||
|
||||
@@ -198,7 +198,10 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
// ----------------------------
|
||||
|
||||
async getProductsTotal(input: ProductsFilterInput): Promise<number> {
|
||||
ScopeAccess.validate(this.user).some([Scopes.PRODUCTS_READ]);
|
||||
ScopeAccess.validate(this.user).some([
|
||||
Scopes.PRODUCTS_READ,
|
||||
Scopes.PRODUCTS_PUBLIC_READ,
|
||||
]);
|
||||
const query = sql.productsTotal(input);
|
||||
const res = await this.cachedRaw(query, null)
|
||||
.cache(MINUTE * 5)
|
||||
@@ -254,7 +257,10 @@ export class ProductAPI extends BaseSQLDataSource {
|
||||
}
|
||||
|
||||
async getProductByPath(path: string): Promise<Maybe<Product>> {
|
||||
ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_READ]);
|
||||
ScopeAccess.validate(this.user).some([
|
||||
Scopes.PRODUCTS_READ,
|
||||
Scopes.PRODUCTS_PUBLIC_READ,
|
||||
]);
|
||||
const query = sql.productByPath();
|
||||
|
||||
const res = await this.knex.raw(query, [path]).then((data) =>
|
||||
|
||||
Reference in New Issue
Block a user