Skip to content
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
9 changes: 2 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"ignorePatterns": [
"dist",
"src/proto"
],
"ignorePatterns": ["dist", "src/proto"],
"rules": {
"@typescript-eslint/no-unused-vars": [
"warn",
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
.github
dist
src/proto/*.ts
typechain-videre
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ How to add observer on waku:

```typescript
import WakuService from './services/WakuService';
import { Test } from "./proto/test";
import { Test } from './proto/test';
import WakuService, { WakuMessageHandler } from './services/WakuService';

const wakuService = await WakuService
.getInstance()
.connect()
;

const wakuService = await WakuService.getInstance().connect();
const handler: WakuMessageHandler = (message) => {
return wakuService.processMessage(Test, message);
};
Expand All @@ -24,11 +20,7 @@ await wakuService.makeWakuObserver(handler, ['some-topic']);
```

```typescript
const wakuService = await WakuService
.getInstance()
.connect()
;

const wakuService = await WakuService.getInstance().connect();
const testPayload: Test = {
test1: 'some-message',
test2: 'some-message 2'
Expand Down
7 changes: 2 additions & 5 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"name": "LPMS server",
"description": "LPMS server",
"repository": "https://github.com/windingtree/lpms-server",
"keywords": [
"node",
"express"
],
"keywords": ["node", "express"],
"env": {
"CLIENT_URL": "<CLIENT_URL>",
"APP_ACCESS_TOKEN_KEY": "<APP_ACCESS_TOKEN_KEY>",
Expand All @@ -14,6 +11,6 @@
"WEB3STORAGE_KEY": "<WEBSTORAGE_API_KEY>",
"APP_CHAIN_ID": "31337",
"APP_VERIFYING_CONTRACT": "<APP_VERIFYING_CONTRACT>",
"APP_PROMETHEUS_PORT":"9100"
"APP_PROMETHEUS_PORT": "9100"
}
}
79 changes: 40 additions & 39 deletions docs/STORAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ All fields, except simple arrays of a primitives (ie. `number`, `number[]` etc),

Related: [story: AP reservation overview](https://github.com/windingtree/win-stays/issues/17)

Identify what *queries* must be able to be answered from the database:
Identify what _queries_ must be able to be answered from the database:

1. How to get information relating to a booking?
2. How to get what bookings are staying at an accommodation facility on a specific day?
Expand All @@ -30,7 +30,7 @@ Description: A list of facilities that are handled by this `lpms-server`.

### facilities

Parent level: *root*
Parent level: _root_
Level: `facilityId` (dynamic)

Key: `metadata`
Expand Down Expand Up @@ -174,7 +174,7 @@ Level: `stubs`

Key: `YYYY-MM-DD` (dynamic)
Value: `string[]`
Description: Contains a list of all stubs, ie. `stubId` (bookings) that are on the date YYYY-MM-DD in this `spaceId`.
Description: Contains a list of all stubs, ie. `stubId` (bookings) that are on the date YYYY-MM-DD in this `spaceId`.
Notes: This meets the requirement (3)

Key: `YYYY-MM-DD-num_booked` (dynamic)
Expand Down Expand Up @@ -210,25 +210,27 @@ Description: Contains generic data for the item (name, photos, etc)
4. Find number of spaces (rooms) booked by date: `facilityId.spaceId.stubs.YYYY-MM-DD-num_booked`.
5. Determine if a space can be booked on a given day:

With daily availability override:
With daily availability override:

`Ask.numSpacesReq <= (facilityId.spaceId.availability.YYYY-MM-DD - facilityId.spaceId.YYYY-MM-DD-num_booked)`
`Ask.numSpacesReq <= (facilityId.spaceId.availability.YYYY-MM-DD - facilityId.spaceId.YYYY-MM-DD-num_booked)`

With no daily availability override:
With no daily availability override:

`Ask.numSpacesReq <= (facilityId.spaceId.availability.default - facilityId.spaceId.YYYY-MM-DD-num_booked)`
`Ask.numSpacesReq <= (facilityId.spaceId.availability.default - facilityId.spaceId.YYYY-MM-DD-num_booked)`

This meets the requirement of (5)

This meets the requirement of (5)
6. Determine if a space can be booked for a date range:

```python
for day in date_range:
# isAvailable = logic from (5) above
if (!isAvailable)
return false
return true
```
This meets the requirement of (6)
```python
for day in date_range:
# isAvailable = logic from (5) above
if (!isAvailable)
return false
return true
```

This meets the requirement of (6)

### Update

Expand All @@ -243,40 +245,39 @@ Description: Contains generic data for the item (name, photos, etc)
In order to generate the final `metadata` binary glob that is uploaded to `IPFS`:

```typescript

let items: ServiceItemData[]
let items: ServiceItemData[];

// process all spaces
const spaces = db.get('facilityId.spaces') // insert correct leveldb query here
const spaces = db.get('facilityId.spaces'); // insert correct leveldb query here
for (const space of object) {
// get generic metadata
const generic = db.get(`${facilityId}.${space}.metadata_generic`) as Item
const specific = db.get(`${facilityId}.${space}.metadata`) as Space
generic.payload = Space.toBinary(specific)

items.push({
item: utils.arrayify(utils.formatBytes32String(space)),
payload: Item.toBinary(generic)
})
// get generic metadata
const generic = db.get(`${facilityId}.${space}.metadata_generic`) as Item;
const specific = db.get(`${facilityId}.${space}.metadata`) as Space;
generic.payload = Space.toBinary(specific);

items.push({
item: utils.arrayify(utils.formatBytes32String(space)),
payload: Item.toBinary(generic)
});
}

// process all other items
const otherItems = db.get('facilityId.otherItems') as Item[]
const otherItems = db.get('facilityId.otherItems') as Item[];
for (const item of otherItems) {
const otherItem = db.get(`${facilityId}.otherItems.${item}`) as Item
items.push({
item: utils.arrayify(utils.formatBytes32String(item)),
payload: Item.toBinary(otherItem)
})
const otherItem = db.get(`${facilityId}.otherItems.${item}`) as Item;
items.push({
item: utils.arrayify(utils.formatBytes32String(item)),
payload: Item.toBinary(otherItem)
});
}

// assemble the metadata for signing / publishing
const serviceProviderData: ServiceProviderData = {
serviceProvider: utils.arrayify(utils.formatBytes32String('provider')),
payload: Facility.toBinary(db.get(`$facilityId.metadata`)),
items: items,
terms: []
}
serviceProvider: utils.arrayify(utils.formatBytes32String('provider')),
payload: Facility.toBinary(db.get(`$facilityId.metadata`)),
items: items,
terms: []
};
```

# Todo
Expand Down
4 changes: 1 addition & 3 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"exec": "ts-node src/index.ts",
"watch": [
"src"
],
"watch": ["src"],
"ext": "ts"
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
"scripts": {
"commit": "git-cz -S",
"changelog": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s",
"tsc": "tsc -p tsconfig-build.json",
"typechain:videre": "npx typechain --target ethers-v5 --out-dir ./typechain-videre './node_modules/@windingtree/videre-contracts/artifacts/contracts/**/*.json'",
"prepublish": "yarn typechain:videre && yarn protoc:libs && yarn protoc:local",
"dev": "cross-env NODE_ENV=development nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec 'ts-node' src/index.ts",
"lint": "npx eslint . --ext .ts",
"lint:fix": "npx eslint . --ext .ts --fix",
"lint:fix": "npx eslint . --ext .ts --fix && npx prettier --write .",
"test": "npx mocha -r ts-node/register test/**/*.spec.ts",
"clean": "rm -rf dist",
"build": "npx clean && npx tsc -p tsconfig-build.json",
"build": "yarn clean && yarn tsc -p tsconfig-build.json",
"protoc:libs": "cp -pR ./node_modules/@windingtree/stays-models/dist/proto/*.proto ./src/proto/",
"protoc:local": "protoc --ts_out ./src/proto --proto_path ./src/proto ./src/proto/*.proto",
"prepare": "husky install",
Expand Down
24 changes: 10 additions & 14 deletions swagger/server.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import express, { Application } from "express";
import morgan from "morgan";
import swaggerUI from "swagger-ui-express";
import swaggerJsDoc from "swagger-jsdoc";
import { options } from "./swagger-options";
import express, { Application } from 'express';
import morgan from 'morgan';
import swaggerUI from 'swagger-ui-express';
import swaggerJsDoc from 'swagger-jsdoc';
import { options } from './swagger-options';

import Router from "../src/router";
import Router from '../src/router';

const PORT = process.env.SWAGGER_PORT || 3000;

const app: Application = express();

app.use(express.json());
app.use(morgan("tiny"));
app.use(express.static("public"));
app.use(morgan('tiny'));
app.use(express.static('public'));

const specs = swaggerJsDoc(options);

app.use(
"/docs",
swaggerUI.serve,
swaggerUI.setup(specs)
);
app.use('/docs', swaggerUI.serve, swaggerUI.setup(specs));

app.use(Router);

app.listen(PORT, () => {
console.log("Server is running on port", PORT);
console.log('Server is running on port', PORT);
});
28 changes: 15 additions & 13 deletions swagger/swagger-options.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
export const options = {
definition: {
openapi: "3.0.3",
openapi: '3.0.3',
info: {
title: "API",
version: "1.0.0",
description: "",
title: 'API',
version: '1.0.0',
description: ''
},
components: {
securitySchemes: {
bearerAuth: {
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
bearerFormat: 'JWT'
}
}
},
security: [{
bearerAuth: []
}],
servers: [
security: [
{
url: "http://localhost:5000/api",
description: "local server"
},
bearerAuth: []
}
],
servers: [
{
url: 'http://localhost:5000/api',
description: 'local server'
}
]
},
apis: ["./src/router/*.ts"],
apis: ['./src/router/*.ts']
};
18 changes: 5 additions & 13 deletions test/package.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ describe('test', async () => {
const anotherUserForTest = 'test_staff_for_tests';

it('make manager', async () => {
await userService.createUser(
managerLogin,
managerPass,
[AppRole.MANAGER]
);
await userService.createUser(managerLogin, managerPass, [AppRole.MANAGER]);

const userId = await userService.getUserIdByLogin(managerLogin);
expect(userId).to.be.an('number');
Expand Down Expand Up @@ -59,7 +55,7 @@ describe('test', async () => {

it('refresh token', async () => {
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}

//without sleep script is very fast and refreshed access token is equal with old
Expand All @@ -68,9 +64,7 @@ describe('test', async () => {
const res = await requestWithSupertest
.post('/api/user/refresh')
.set('Accept', 'application/json')
.set('Cookie', [`refreshToken=${refreshToken}`])
;

.set('Cookie', [`refreshToken=${refreshToken}`]);
const oldAccessToken = accessToken;
accessToken = res.body.accessToken;
expect(accessToken).to.be.an('string');
Expand All @@ -88,7 +82,6 @@ describe('test', async () => {
.set('Authorization', `Bearer ${accessToken}`)
.set('Accept', 'application/json');


expect(res.status).to.equal(200);
});

Expand All @@ -114,7 +107,6 @@ describe('test', async () => {
.set('Authorization', `Bearer ${staffAccessToken}`)
.set('Accept', 'application/json');


expect(res.status).to.equal(403);
});

Expand Down Expand Up @@ -169,7 +161,8 @@ describe('test', async () => {
expect(res.status).to.equal(200);
});

it('delete users', async () => { //todo think about APIs for delete users
it('delete users', async () => {
//todo think about APIs for delete users
const id = await userService.getUserIdByLogin(managerLogin);
const anotherUser = await userService.getUserIdByLogin(anotherUserForTest);
await userService.deleteUser(Number(id));
Expand All @@ -180,4 +173,3 @@ describe('test', async () => {
expect(checkId).to.be.null;
});
});

4 changes: 1 addition & 3 deletions tsconfig-build.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": [
"test"
]
"exclude": ["test"]
}
Loading