Skip to content

Commit

Permalink
feat(com-api): add product route
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and AliMD committed Feb 11, 2023
1 parent d1e3c61 commit 487a2c0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion uniquely/com-api/demo.http
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
@apiUrl = http://127.0.0.1:8000/api/v0
@token = YOUR_SECRET_TOKEN
@adminToken = ADMIN_SECRET_TOKEN

@userToken = 8FanBtr0adx_Nmocgy_XkzaZ0-bRn59G9SO1I2bk2jo

### Home
GET {{apiUrl}}/

### Get all product
Get {{apiUrl}}/product/
GET {{apiUrl}}/product/
Authorization: Bearer {{token}}

### New product
PUT {{apiUrl}}/product/
Authorization: Bearer {{adminToken}}
Content-Type: application/json

{
"id": "1",
"title": {"fa": "تایل کد ۰۰۱"},
"image": "/image/sample-1.jpg"
}

### New order of user
PUT {{apiUrl}}/order/?userId=abc123
Authorization: Bearer {{token}}
Expand Down
1 change: 1 addition & 0 deletions uniquely/com-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import './route/home.js';
import './route/get-order.js';
import './route/get-product.js';
import './route/put-order.js';
import './route/put-product.js';

logger.logOther('..:: Alwatr Customer Order Management API ::..');
1 change: 1 addition & 0 deletions uniquely/com-api/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const config = {
host: process.env.HOST ?? '0.0.0.0',
port: process.env.PORT != null ? +process.env.PORT : 8000,
accessToken: process.env.ACCESS_TOKEN ?? 'YOUR_SECRET_TOKEN',
adminToken: process.env.ADMIN_TOKEN ?? 'ADMIN_SECRET_TOKEN',
allowAllOrigin: true,
},
} as const;
Expand Down
16 changes: 16 additions & 0 deletions uniquely/com-api/src/route/put-product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {config, logger} from '../lib/config.js';
import {nanoServer} from '../lib/server.js';
import {storageClient} from '../lib/storage.js';

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

nanoServer.route('PUT', '/product/', async (connection) => {
logger.logMethod('put-product');
connection.requireToken(config.nanoServer.adminToken);
const bodyJson = await connection.requireJsonBody<Product>();

return {
ok: true,
data: await storageClient.set(bodyJson, config.storage.productStorageName),
};
});

0 comments on commit 487a2c0

Please sign in to comment.