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() {
|
function throwForbidden() {
|
||||||
throw new GraphQLError('You are not authorized to perform this action', {
|
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 || '';
|
const cognitoPoolId = process.env.COGNITO_POOL_ID || '';
|
||||||
if (!cognitoPoolId) {
|
if (!cognitoPoolId) {
|
||||||
throw new GraphQLError('env var required for cognito pool', {
|
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}`;
|
const cognitoIssuer = `https://cognito-idp.eu-west-1.amazonaws.com/${cognitoPoolId}`;
|
||||||
@@ -181,7 +186,12 @@ const verifyToken = async (
|
|||||||
const verifyAuthentication = async (req: IncomingMessage) => {
|
const verifyAuthentication = async (req: IncomingMessage) => {
|
||||||
const notAuthorizedError = () => {
|
const notAuthorizedError = () => {
|
||||||
throw new GraphQLError('You are not authorized', {
|
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> {
|
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 (
|
return (
|
||||||
this.knex
|
this.knex
|
||||||
.select('*')
|
.select('*')
|
||||||
|
|||||||
@@ -220,7 +220,10 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getProducts(input: ProductsFilterInput): Promise<Array<Product>> {
|
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);
|
const query = sql.products(input);
|
||||||
|
|
||||||
return this.knex
|
return this.knex
|
||||||
@@ -229,7 +232,10 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getProduct(id: number): Promise<Maybe<Product>> {
|
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 query = sql.product();
|
||||||
|
|
||||||
const res = await this.knex.raw(query, [id]).then((data) =>
|
const res = await this.knex.raw(query, [id]).then((data) =>
|
||||||
@@ -241,6 +247,25 @@ export class ProductAPI extends BaseSQLDataSource {
|
|||||||
return res.find(Boolean);
|
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>> {
|
async getProductByPath(path: string): Promise<Maybe<Product>> {
|
||||||
ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_READ]);
|
ScopeAccess.validate(this.user).all([Scopes.PRODUCTS_READ]);
|
||||||
const query = sql.productByPath();
|
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) => {
|
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 {
|
try {
|
||||||
const response = await getClientAccessToken(req);
|
const response = await getClientAccessToken(req);
|
||||||
res.status(200).send(response);
|
res.status(200).send(response);
|
||||||
@@ -57,7 +60,7 @@ async function main() {
|
|||||||
|
|
||||||
app.use(
|
app.use(
|
||||||
'/',
|
'/',
|
||||||
cors<cors.CorsRequest>(),
|
cors<cors.CorsRequest>('*'),
|
||||||
json(),
|
json(),
|
||||||
expressMiddleware(server, {
|
expressMiddleware(server, {
|
||||||
context: async ({ req }) => {
|
context: async ({ req }) => {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { Keyword } from '../types/keyword-types';
|
|||||||
import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
import { MarketLocaleAPI } from '../datasources/market-locale-api';
|
||||||
import { InteriorAPI } from '../datasources/interior-api';
|
import { InteriorAPI } from '../datasources/interior-api';
|
||||||
import { InteriorsLambdaAPI } from '../datasources/interiors-lambda-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 { moveS3File } from '../aws/s3';
|
||||||
import { DesignerAPI } from '../datasources/designer-api';
|
import { DesignerAPI } from '../datasources/designer-api';
|
||||||
import { PrintProductDefaultsAPI } from '../datasources/printproduct-defaults-api';
|
import { PrintProductDefaultsAPI } from '../datasources/printproduct-defaults-api';
|
||||||
@@ -55,6 +55,12 @@ const PrintProduct = {
|
|||||||
dataSources.printProductDefaultsApi
|
dataSources.printProductDefaultsApi
|
||||||
)).getDefaults(id);
|
)).getDefaults(id);
|
||||||
},
|
},
|
||||||
|
async listprice({ id }, input: MarketInput, { dataSources }) {
|
||||||
|
return (<ProductAPI>dataSources.productApi).getListPrice(
|
||||||
|
id,
|
||||||
|
input.marketId,
|
||||||
|
);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getProductsResult(
|
async function getProductsResult(
|
||||||
|
|||||||
@@ -341,6 +341,7 @@ type PrintProduct {
|
|||||||
updated: DateTime
|
updated: DateTime
|
||||||
interiors: [Interior]
|
interiors: [Interior]
|
||||||
defaults: PrintProductDefaults
|
defaults: PrintProductDefaults
|
||||||
|
listprice(marketId: Int!): Float!
|
||||||
}
|
}
|
||||||
|
|
||||||
enum InteriorType {
|
enum InteriorType {
|
||||||
|
|||||||
@@ -45,3 +45,7 @@ export interface PaginationResult {
|
|||||||
export interface IdNumberResult {
|
export interface IdNumberResult {
|
||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface MarketInput {
|
||||||
|
marketId: number;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user