3124: added listprice to printproduct and public access to product and designers (#138)
This commit is contained in:
@@ -46,7 +46,12 @@ function getScopes(user: ClaimVerifyResult): Scopes[] | [] {
|
||||
|
||||
function throwForbidden() {
|
||||
throw new GraphQLError('You are not authorized to perform this action', {
|
||||
extensions: { code: 'FORBIDDEN' },
|
||||
extensions: {
|
||||
code: 'FORBIDDEN',
|
||||
http: {
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,12 @@ interface Identity {
|
||||
const cognitoPoolId = process.env.COGNITO_POOL_ID || '';
|
||||
if (!cognitoPoolId) {
|
||||
throw new GraphQLError('env var required for cognito pool', {
|
||||
extensions: { code: 'FORBIDDEN' },
|
||||
extensions: {
|
||||
code: 'FORBIDDEN',
|
||||
http: {
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
const cognitoIssuer = `https://cognito-idp.eu-west-1.amazonaws.com/${cognitoPoolId}`;
|
||||
@@ -181,7 +186,12 @@ const verifyToken = async (
|
||||
const verifyAuthentication = async (req: IncomingMessage) => {
|
||||
const notAuthorizedError = () => {
|
||||
throw new GraphQLError('You are not authorized', {
|
||||
extensions: { code: 'FORBIDDEN' },
|
||||
extensions: {
|
||||
code: 'FORBIDDEN',
|
||||
http: {
|
||||
status: 401,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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 = ?';
|
||||
}
|
||||
|
||||
+4
-1
@@ -46,6 +46,9 @@ async function main() {
|
||||
});
|
||||
|
||||
app.post('/login', async (req, res) => {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
res.setHeader('Access-Control-Allow-Methods', '*');
|
||||
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
||||
try {
|
||||
const response = await getClientAccessToken(req);
|
||||
res.status(200).send(response);
|
||||
@@ -57,7 +60,7 @@ async function main() {
|
||||
|
||||
app.use(
|
||||
'/',
|
||||
cors<cors.CorsRequest>(),
|
||||
cors<cors.CorsRequest>('*'),
|
||||
json(),
|
||||
expressMiddleware(server, {
|
||||
context: async ({ req }) => {
|
||||
|
||||
@@ -14,7 +14,7 @@ import { Keyword } from '../types/keyword-types';
|
||||
import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
||||
import { InteriorAPI } from '../datasources/interior-api';
|
||||
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-api';
|
||||
import { IdNumberResult } from '../types/types';
|
||||
import { IdNumberResult, MarketInput } from '../types/types';
|
||||
import { moveS3File } from '../aws/s3';
|
||||
import { DesignerAPI } from '../datasources/designer-api';
|
||||
import { PrintProductDefaultsAPI } from '../datasources/printproduct-defaults-api';
|
||||
@@ -55,6 +55,12 @@ const PrintProduct = {
|
||||
dataSources.printProductDefaultsApi
|
||||
)).getDefaults(id);
|
||||
},
|
||||
async listprice({ id }, input: MarketInput, { dataSources }) {
|
||||
return (<ProductAPI>dataSources.productApi).getListPrice(
|
||||
id,
|
||||
input.marketId,
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
async function getProductsResult(
|
||||
|
||||
@@ -341,6 +341,7 @@ type PrintProduct {
|
||||
updated: DateTime
|
||||
interiors: [Interior]
|
||||
defaults: PrintProductDefaults
|
||||
listprice(marketId: Int!): Float!
|
||||
}
|
||||
|
||||
enum InteriorType {
|
||||
|
||||
@@ -45,3 +45,7 @@ export interface PaginationResult {
|
||||
export interface IdNumberResult {
|
||||
id: number;
|
||||
}
|
||||
|
||||
export interface MarketInput {
|
||||
marketId: number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user