Skip to content

Commit

Permalink
feat(com-api): review and update all routes
Browse files Browse the repository at this point in the history
Co-authored-by: S. Amir Mohammad Najafi <njfamirm@gmail.com>
  • Loading branch information
AliMD and njfamirm committed Feb 15, 2023
1 parent 2cd9443 commit 957eca9
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 23 deletions.
2 changes: 0 additions & 2 deletions uniquely/com-api/demo-data.http
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ PATCH {{apiUrl}}/price-list/?name=tile-market-ir
Authorization: Bearer {{adminToken}}
Content-Type: application/json


{
"data": [
{
Expand Down Expand Up @@ -99,7 +98,6 @@ PATCH {{apiUrl}}/price-list/?name=tile-agency-ir
Authorization: Bearer {{adminToken}}
Content-Type: application/json


{
"data": [
{
Expand Down
3 changes: 1 addition & 2 deletions uniquely/com-api/demo.http
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ PATCH {{apiUrl}}/price-list/?name=tile-agency-ir
Authorization: Bearer {{adminToken}}
Content-Type: application/json


{
"data": [
{
Expand Down Expand Up @@ -84,5 +83,5 @@ client-id: 2b6861f4-a8d7-4065-a5a5-3caa54b71a20
}

### Get all orders list of special user
get {{apiUrl}}/order/?userId=abc123
get {{apiUrl}}/order-list/?userId=abc123
Authorization: Bearer {{userToken}}
2 changes: 1 addition & 1 deletion uniquely/com-api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {logger} from './lib/config.js';

import './route/home.js';
import './route/get-order.js';
import './route/get-order-list.js';
import './route/get-product-list.js';
import './route/get-price-list.js';
import './route/put-order.js';
Expand Down
2 changes: 1 addition & 1 deletion uniquely/com-api/src/lib/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import {AlwatrStorageClient} from '@alwatr/storage-client';

import {config} from './config.js';

export const storageClient = new AlwatrStorageClient(config.storage);
export const storageClient = new AlwatrStorageClient(config.storageClient);
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import {storageClient} from '../lib/storage.js';

import type {Order} from '@alwatr/type/customer-order-management.js';

// Get all orders of special customer
nanoServer.route('GET', '/order/', async (connection) => {
/**
* Get all orders of special user.
*/
nanoServer.route('GET', '/order-list/', async (connection) => {
logger.logMethod('get-order');

const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
// connection.requireToken((token: string) => {
// return tokenGenerator.verify(params.userId, token) === 'valid';
// });
connection.requireToken(config.nanoServer.accessToken);

return await storageClient.getStorage<Order>(params.userId);
const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
return await storageClient.getStorage<Order>(config.orderStoragePrefix + params.userId);
});
2 changes: 1 addition & 1 deletion uniquely/com-api/src/route/get-price-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ nanoServer.route('GET', '/price-list/', async (connection) => {
logger.logMethod('get-price-list');
connection.requireToken(config.nanoServer.accessToken);
const params = connection.requireQueryParams<{name: string}>({name: 'string'});
return await storageClient.getStorage<ProductPrice>(config.storage.priceStorageName + '-' + params.name);
return await storageClient.getStorage<ProductPrice>(config.priceStoragePrefix + params.name);
});
2 changes: 1 addition & 1 deletion uniquely/com-api/src/route/get-product-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ 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.storage.productStorageName + '-' + params.name);
return await storageClient.getStorage<Product>(config.productStoragePrefix + params.name);
});
2 changes: 1 addition & 1 deletion uniquely/com-api/src/route/patch-price-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ nanoServer.route('PATCH', '/price-list/', async (connection) => {
const bodyJson = await connection.requireJsonBody<{data: Array<ProductPrice>}>();

for (const price of bodyJson.data) {
await storageClient.set(price, config.storage.priceStorageName + '-' + params.name);
await storageClient.set(price, config.priceStoragePrefix + params.name);
}

return {
Expand Down
2 changes: 1 addition & 1 deletion uniquely/com-api/src/route/patch-product-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ nanoServer.route('PATCH', '/product-list/', async (connection) => {
const bodyJson = await connection.requireJsonBody<{data: Array<Product>}>();

for (const price of bodyJson.data) {
await storageClient.set(price, config.storage.productStorageName + '-' + params.name);
await storageClient.set(price, config.productStoragePrefix + params.name);
}

return {
Expand Down
5 changes: 1 addition & 4 deletions uniquely/com-api/src/route/put-order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ import type {Order} from '@alwatr/type/customer-order-management.js';
nanoServer.route('PUT', '/order/', async (connection) => {
logger.logMethod('put-order');

const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
// connection.requireToken((token: string) => {
// return tokenGenerator.verify(params.userId, token) === 'valid';
// });
connection.requireToken(config.nanoServer.accessToken);
const params = connection.requireQueryParams<{userId: string}>({userId: 'string'});
const remoteAddress = connection.getRemoteAddress();
const clientId = connection.requireClientId();

Expand Down

0 comments on commit 957eca9

Please sign in to comment.