Skip to content

Commit

Permalink
feat(com-api)!: limit productStorageList and product-list storage par…
Browse files Browse the repository at this point in the history
…am (#830)
  • Loading branch information
alimd authored Feb 15, 2023
2 parents ea54eb9 + 7ea567e commit 4d02a15
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion uniquely/com-api/demo-data.http
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@adminToken = ADMIN_SECRET_TOKEN

### New product 1
PATCH {{apiUrl}}/product-list/?name=tile
PATCH {{apiUrl}}/product-list/?storage=tile
Authorization: Bearer {{adminToken}}
Content-Type: application/json

Expand Down
4 changes: 2 additions & 2 deletions uniquely/com-api/demo.http
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
GET {{apiUrl}}/

### Get all product.
GET {{apiUrl}}/product-list/?name=tile
GET {{apiUrl}}/product-list/?storage=tile
Authorization: Bearer {{userToken}}

### Insert/edit a product.
PATCH {{apiUrl}}/product-list/?name=tile
PATCH {{apiUrl}}/product-list/?storage=tile
Authorization: Bearer {{adminToken}}
Content-Type: application/json

Expand Down
4 changes: 4 additions & 0 deletions uniquely/com-api/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const config = {
productStoragePrefix: 'product-list-',
priceStoragePrefix: 'price-list-',
orderStoragePrefix: 'order-list-',
productStorageList: (process.env.PRODUCT_STORAGE_LIST ?? 'temp')
.split(',')
.map((f) => f.trim())
.filter((f) => f != ''),
} as const;

logger.logProperty('config', config);
11 changes: 9 additions & 2 deletions uniquely/com-api/src/route/get-product-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import type {Product} from '@alwatr/type/customer-order-management.js';
nanoServer.route('GET', '/product-list/', async (connection) => {
logger.logMethod('get-product-list');
connection.requireToken(config.nanoServer.accessToken);
const params = connection.requireQueryParams<{name: string}>({name: 'string'});
return await storageClient.getStorage<Product>(config.productStoragePrefix + params.name);
const params = connection.requireQueryParams<{storage: string}>({storage: 'string'});
if (config.productStorageList.indexOf(params.storage) === -1) {
return {
ok: false,
statusCode: 404,
errorCode: 'product_not_found',
};
}
return await storageClient.getStorage<Product>(config.productStoragePrefix + params.storage);
});

0 comments on commit 4d02a15

Please sign in to comment.