Skip to content

Commit

Permalink
Adding search/symbol endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexintosh committed Mar 16, 2018
1 parent df2f4a1 commit c0284a9
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 89 deletions.
1 change: 1 addition & 0 deletions assets/db.json

Large diffs are not rendered by default.

127 changes: 38 additions & 89 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"@nestjs/testing": "^4.5.5",
"@nestjs/websockets": "^4.5.8",
"js-yaml": "^3.11.0",
"lodash": "^4.17.5",
"lodash-es": "^4.17.7",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.12",
"rxjs": "^5.5.6",
Expand Down
35 changes: 35 additions & 0 deletions src/ERC20Tokens/erc20-tokens.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Controller, Get, Param } from '@nestjs/common';
import * as path from 'path';
import * as fs from 'fs';
import {find, startsWith, without} from 'lodash';
// tslint:disable-next-line:no-var-requires
const db = require('../../assets/db.json');
// tslint:disable-next-line:no-var-requires
const yaml = require('js-yaml');
const tokenYalmDirectory = path.join(__dirname, '..', '..', '/assets/ERC20-tokens/');
Expand All @@ -21,6 +24,38 @@ export class ERC20TokensController {
}
}

@Get('/json')
getJson() {
try {
const res = [];
const json = [];

fs.readdirSync(tokenYalmDirectory).forEach(file => {
res.push(file.replace('.yaml', ''));
});

res.forEach( o => {
const doc = yaml.safeLoad(fs.readFileSync(`${tokenYalmDirectory}${o}.yaml`, 'utf8'));
json.push(doc);
});

fs.writeFile(tokenYalmDirectory + '../db.json', JSON.stringify(json), (err) => {
if (err) {
return err;
}
});

return json;
} catch (e) {
return [];
}
}

@Get('/search/symbol/:v')
search(@Param() params) {
return without(db.map(i => startsWith(i.symbol, params.v) ? i : undefined), undefined) || [];
}

@Get(':contractAddress')
findOne(@Param() params) {
try {
Expand Down

0 comments on commit c0284a9

Please sign in to comment.