Fix scopes and promise handling (#152)

This commit is contained in:
Anders Gustafsson
2023-05-10 09:17:49 +02:00
committed by GitHub
parent 77f8973a32
commit 7f341f510e
10 changed files with 72 additions and 43 deletions
+6 -3
View File
@@ -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('*')
+8 -2
View File
@@ -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) =>