3769 - Differentiate forbidden and unauthenticated - add product group filter (#153)

This commit is contained in:
Anders Gustafsson
2023-05-23 08:40:44 +02:00
committed by GitHub
parent 7f341f510e
commit 6feb7ee388
7 changed files with 18 additions and 6 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ ENV NEW_RELIC_NO_CONFIG_FILE=true
# Installs npm dependencies on container # Installs npm dependencies on container
RUN npm ci RUN npm ci
# Command container will actually run when called # Command container will actually run when called
CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"] CMD ["npx", "nodemon", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"]
+1 -1
View File
@@ -9,4 +9,4 @@ WORKDIR /app
ENV NODE_ENV=development ENV NODE_ENV=development
ENV NEW_RELIC_NO_CONFIG_FILE=true ENV NEW_RELIC_NO_CONFIG_FILE=true
# Command container will actually run when called # Command container will actually run when called
CMD ["npx", "nodemon", "-w", "src", "--ext", "ts", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"] CMD ["npx", "nodemon", "-w", "src", "--ext", "ts, graphql", "--exec", "TZ=Europe/Paris", "ts-node", "src/index.ts"]
+1 -1
View File
@@ -23,7 +23,7 @@ COGNITO_LOGIN_CLIENT_ID and COGNITO_LOGIN_CLIENT_SECRET found in cognito `photow
### Development ### Development
This project runs in docker, so when developing start the docker environment and it will restart automatically when files are changed. Sometimes the watch for files doesn't trigger. Like when you edit the .graphql file. Then just edit a .ts file and it will reload. This project runs in docker, so when developing start the docker environment and it will restart automatically when .graphql (schema) or .ts files are changed.
Run Run
+1 -1
View File
@@ -51,7 +51,7 @@ function throwForbidden() {
extensions: { extensions: {
code: 'FORBIDDEN', code: 'FORBIDDEN',
http: { http: {
status: 401, status: 403,
}, },
}, },
}); });
+1 -1
View File
@@ -187,7 +187,7 @@ const verifyAuthentication = async (req: IncomingMessage) => {
const notAuthorizedError = () => { const notAuthorizedError = () => {
throw new GraphQLError('You are not authorized', { throw new GraphQLError('You are not authorized', {
extensions: { extensions: {
code: 'FORBIDDEN', code: 'UNAUTHENTICATED',
http: { http: {
status: 401, status: 401,
}, },
+12
View File
@@ -3,6 +3,7 @@ import {
Orientation, Orientation,
PrintProduct, PrintProduct,
Product, Product,
ProductGroup,
ProductListResult, ProductListResult,
ProductsFilterInput, ProductsFilterInput,
ProductsSearchResult, ProductsSearchResult,
@@ -32,6 +33,17 @@ const ProductBlacklist = {
}; };
const Product = { const Product = {
async printProducts(
product: { printProducts: PrintProduct[] },
input: { groups: ProductGroup[] },
) {
if (!input.groups) {
return product.printProducts;
}
return product.printProducts.filter((printProduct) => {
return input.groups.includes(printProduct.group);
});
},
async categories({ id }, _args, { dataSources }): Promise<Array<Category>> { async categories({ id }, _args, { dataSources }): Promise<Array<Category>> {
return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id); return (<CategoryAPI>dataSources.categoryApi).getProductCategories(id);
}, },
+1 -1
View File
@@ -254,7 +254,7 @@ type Product {
inserted: DateTime! inserted: DateTime!
updated: DateTime updated: DateTime
publishingDate: DateTime! publishingDate: DateTime!
printProducts: [PrintProduct] printProducts(groups: [ProductGroup]): [PrintProduct]
blacklisting: [ProductBlacklist] blacklisting: [ProductBlacklist]
categories: [Category] categories: [Category]
designerId: Int designerId: Int