-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
54 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
uniquely/com-api/src/lib/nano-server.ts → uniquely/com-api/src/lib/server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {AlwatrNanoServer} from '@alwatr/nano-server'; | ||
|
||
import {config} from '../config.js'; | ||
import {config} from './config.js'; | ||
|
||
export const nanoServer = new AlwatrNanoServer(config.nanoServer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import {AlwatrStorageClient} from '@alwatr/storage-client'; | ||
|
||
import {config} from '../config.js'; | ||
import {config} from './config.js'; | ||
|
||
export const storageClient = new AlwatrStorageClient(config.storage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {AlwatrTokenGenerator} from '@alwatr/token'; | ||
|
||
import {config} from './config.js'; | ||
|
||
export const tokenGenerator = new AlwatrTokenGenerator(config.token); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import {logger} from '../../config.js'; | ||
import {nanoServer} from '../../lib/nano-server.js'; | ||
import {storageClient} from '../../lib/storage.js'; | ||
import {tokenGenerator} from '../../token.js'; | ||
import {logger} from '../lib/config.js'; | ||
import {nanoServer} from '../lib/server.js'; | ||
import {storageClient} from '../lib/storage.js'; | ||
import {tokenGenerator} from '../lib/token.js'; | ||
|
||
import type {AlwatrConnection} from '@alwatr/nano-server'; | ||
import type {AlwatrServiceResponse} from '@alwatr/type'; | ||
import type {Order} from '@alwatr/type/src/customer-order-management.js'; | ||
import type {Order} from '@alwatr/type/customer-order-management.js'; | ||
|
||
// Get current order object | ||
nanoServer.route('GET', '/order/', getOrder); | ||
|
||
async function getOrder(connection: AlwatrConnection): Promise<AlwatrServiceResponse> { | ||
logger.logMethod('getOrder'); | ||
// Get all orders of special customer | ||
nanoServer.route('GET', '/order/', 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'; | ||
}); | ||
|
||
return await storageClient.getStorage<Order>(params.userId); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import {config, logger} from '../../config.js'; | ||
import {nanoServer} from '../../lib/nano-server.js'; | ||
import {storageClient} from '../../lib/storage.js'; | ||
import {config, logger} from '../lib/config.js'; | ||
import {nanoServer} from '../lib/server.js'; | ||
import {storageClient} from '../lib/storage.js'; | ||
|
||
import type {AlwatrServiceResponse} from '@alwatr/type'; | ||
import type {Product} from '@alwatr/type/src/customer-order-management.js'; | ||
|
||
nanoServer.route('GET', '/product/', getProduct); | ||
|
||
async function getProduct(): Promise<AlwatrServiceResponse> { | ||
logger.logMethod('getProduct'); | ||
nanoServer.route('GET', '/product/', async () => { | ||
logger.logMethod('get-product'); | ||
return await storageClient.getStorage<Product>(config.storage.productStorageName); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,38 @@ | ||
import {logger} from '../../config.js'; | ||
import {nanoServer} from '../../lib/nano-server.js'; | ||
import {storageClient} from '../../lib/storage.js'; | ||
import {tokenGenerator} from '../../token.js'; | ||
import {logger} from '../lib/config.js'; | ||
import {nanoServer} from '../lib/server.js'; | ||
import {storageClient} from '../lib/storage.js'; | ||
import {tokenGenerator} from '../lib/token.js'; | ||
|
||
import type {AlwatrConnection} from '@alwatr/nano-server'; | ||
import type {AlwatrServiceResponse} from '@alwatr/type'; | ||
import type {Order} from '@alwatr/type/customer-order-management.js'; | ||
|
||
// Add order | ||
nanoServer.route('PUT', '/order/', newOrder); | ||
|
||
async function newOrder(connection: AlwatrConnection): Promise<AlwatrServiceResponse> { | ||
logger.logMethod('newOrder'); | ||
// Insert new order | ||
nanoServer.route('PUT', '/order/', async (connection) => { | ||
logger.logMethod('put-order'); | ||
|
||
const params = connection.requireQueryParams<{userId: string}>({userId: 'string'}); | ||
const token = connection.requireToken((token: string) => { | ||
return tokenGenerator.verify(params.userId, token) === 'valid'; | ||
}); | ||
const order = await connection.requireJsonBody<Order>(); | ||
const remoteAddress = connection.incomingMessage.socket.remoteAddress ?? 'unknown'; | ||
const clientId = connection.incomingMessage.headers['client-id']; | ||
|
||
if (await storageClient.has(order.id, token)) { | ||
if (!clientId) { | ||
return { | ||
ok: false, | ||
statusCode: 400, | ||
errorCode: 'order_exist', | ||
statusCode: 401, | ||
errorCode: 'client_id_header_required', | ||
}; | ||
} | ||
|
||
// else | ||
const order = await connection.requireJsonBody<Order>(); | ||
|
||
order.id = 'auto_increment'; | ||
order.status = 'registered'; | ||
order.clientId = clientId; | ||
order.remoteAddress = remoteAddress; | ||
|
||
return { | ||
ok: true, | ||
data: await storageClient.set<Order>(order, params.userId), | ||
}; | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.