Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(com-api)!: limit productStorageList and product-list storage param #830

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});