Skip to content

Commit

Permalink
Be 769 convert to ts (#184)
Browse files Browse the repository at this point in the history
Signed-off-by: jeeva <jeevasang@gmail.com>
  • Loading branch information
JeevaSang authored Sep 26, 2020
1 parent 571ba55 commit 65b5001
Show file tree
Hide file tree
Showing 38 changed files with 312 additions and 295 deletions.
47 changes: 20 additions & 27 deletions app/Explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,31 @@
* SPDX-License-Identifier: Apache-2.0
*/

const Express = require('express');
const bodyParser = require('body-parser');
const swaggerUi = require('swagger-ui-express');
const compression = require('compression');
const passport = require('passport');
const RateLimit = require('express-rate-limit');
import Express from 'express';
import bodyParser from 'body-parser';
import swaggerUi from 'swagger-ui-express';
import compression from 'compression';
import passport from 'passport';
import RateLimit from 'express-rate-limit';
import {PlatformBuilder } from './platform/PlatformBuilder';
const explorerconfig = require('./explorerconfig.json');
const PersistenceFactory = require('./persistence/PersistenceFactory');
const ExplorerError = require('./common/ExplorerError');

const localLoginStrategy = require('./passport/local-login');
const authroutes = require('./rest/authroutes');
const dbroutes = require('./rest/dbroutes');
const platformroutes = require('./rest/platformroutes');
const adminroutes = require('./platform/fabric/rest/adminroutes');

const authCheckMiddleware = require('./middleware/auth-check');

const swaggerDocument = require('../swagger.json');

import explorerconfig from './explorerconfig.json';
import {PersistenceFactory} from './persistence/PersistenceFactory';
import {authroutes} from './rest/authroutes';
import {dbroutes} from './rest/dbroutes';
import {platformroutes} from './rest/platformroutes';
import {adminroutes} from './platform/fabric/rest/adminroutes';
import {explorerConst} from './common/ExplorerConst'
import {explorerError} from './common/ExplorerMessage'

import authCheckMiddleware from './middleware/auth-check';
import swaggerDocument from '../swagger.json';
import {ExplorerError} from './common/ExplorerError';
const localLoginStrategy = require('./passport/local-login');
/**
*
*
* @class Explorer
*/
class Explorer {
export class Explorer {

app = Express();
persistence : any;
Expand Down Expand Up @@ -119,12 +114,12 @@ class Explorer {

this.app.use('/api', authCheckMiddleware);

const authrouter = new Express.Router();
const authrouter = Express.Router();

// Initializing the rest app services
await authroutes(authrouter, platform);

const apirouter = new Express.Router();
const apirouter = Express.Router();

// Initializing the rest app services
await dbroutes(apirouter, platform);
Expand Down Expand Up @@ -157,6 +152,4 @@ class Explorer {
}
}
}
}

module.exports = Explorer;
}
24 changes: 11 additions & 13 deletions app/Synchronizer.js → app/Synchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@
*/
/* eslint-disable import/extensions */
import { helper } from './common/helper';

import { explorerConst } from './common/ExplorerConst';
import { explorerError } from './common/ExplorerMessage';
import {ExplorerError} from './common/ExplorerError';
import syncconfig from './explorerconfig.json';
import {SyncBuilder} from './sync/SyncBuilder';
import {PersistenceFactory} from './persistence/PersistenceFactory';
import {ExplorerSender} from './sync/sender/ExplorerSender';
/* eslint-enable import/extensions */

const syncconfig = require('./explorerconfig.json');
const ExplorerError = require('./common/ExplorerError');

const logger = helper.getLogger('Synchronizer');
const SyncBuilder = require('./sync/SyncBuilder');
const PersistenceFactory = require('./persistence/PersistenceFactory');
const ExplorerSender = require('./sync/sender/ExplorerSender');

/**
*
*
* @class Synchronizer
*/
class Synchronizer {
export class Synchronizer {
args: any;
persistence: any;
platform: any;
/**
* Creates an instance of Synchronizer.
* @param {*} args
* @memberof Synchronizer
*/
constructor(args) {
constructor(args: any) {
this.args = args;
this.persistence = null;
this.platform = null;
Expand Down Expand Up @@ -91,6 +91,4 @@ class Synchronizer {
this.platform.destroy();
}
}
}

module.exports = Synchronizer;
}
4 changes: 2 additions & 2 deletions app/common/ExplorerError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import util from 'util';
* %% - single percent sign ('%'). This does not consume an argument.
* }
*/
module.exports = function ExplorerError(...args) {
export function ExplorerError(...args: string[]) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = util.format(args);
};

require('util').inherits(module.exports, Error);
//require('util').inherits(module.exports, Error);
4 changes: 1 addition & 3 deletions app/common/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const logger = helper.getLogger('ForkSenderHandler');
* @returns
*/

function toUTCmilliseconds(dateStr) {
export function toUTCmilliseconds(dateStr: any) {
let startSyncMills = null;
try {
startSyncMills = Date.parse(dateStr);
Expand All @@ -23,5 +23,3 @@ function toUTCmilliseconds(dateStr) {
}
return startSyncMills;
}

exports.toUTCmilliseconds = toUTCmilliseconds;
7 changes: 3 additions & 4 deletions app/common/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
* limitations under the License.
*/

const log4js = require('log4js/lib/log4js');
import log4js from 'log4js/lib/log4js';

const fs = require('fs-extra');
const yn = require('yn');
import yn from 'yn';

/*
* Please assign the logger with the file name for the application logging and assign the logger with "PgService"
Expand All @@ -43,7 +42,7 @@ const yn = require('yn');
*/
export class helper {

static getLogger(moduleName) : any {
static getLogger(moduleName: string) : any {
const logger = log4js.getLogger(moduleName);

let appLog = 'logs/app/app.log';
Expand Down
10 changes: 4 additions & 6 deletions app/persistence/PersistenceFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import {explorerConst} from '../common/ExplorerConst'
import {explorerError} from '../common/ExplorerMessage'
const ExplorerError = require('../common/ExplorerError');
import {ExplorerError} from '../common/ExplorerError';

/**
*
*
* @class PersistenceFactory
*/
class PersistenceFactory {
export class PersistenceFactory {
/**
*
*
Expand All @@ -21,7 +21,7 @@ class PersistenceFactory {
* @returns
* @memberof PersistenceFactory
*/
static async create(db, dbconfig) {
static async create(db: string, dbconfig: any) {
console.log("check",explorerConst.PERSISTENCE_POSTGRESQL)
if (db === explorerConst.PERSISTENCE_POSTGRESQL) {
// Avoid to load all db Persist module
Expand All @@ -32,6 +32,4 @@ class PersistenceFactory {
}
throw new ExplorerError(explorerError.ERROR_1003, db);
}
}

module.exports = PersistenceFactory;
}
26 changes: 13 additions & 13 deletions app/persistence/fabric/CRUDService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class CRUDService {
* @memberof CRUDService
*/

getTxCountByBlockNum(network_name, channel_genesis_hash, blockNum) {
getTxCountByBlockNum(network_name: any, channel_genesis_hash: any, blockNum: any) {
return this.sql.getRowByPkOne(
`select blocknum ,txcount from blocks where channel_genesis_hash='${channel_genesis_hash}' and blocknum=${blockNum} and network_name = '${network_name}' `
);
Expand All @@ -41,7 +41,7 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
getTransactionByID(network_name, channel_genesis_hash, txhash) {
getTransactionByID(network_name: any, channel_genesis_hash: any, txhash: any) {
const sqlTxById = ` select t.txhash,t.validation_code,t.payload_proposal_hash,t.creator_msp_id,t.endorser_msp_id,t.chaincodename,t.type,t.createdt,t.read_set,
t.write_set,channel.name as channelName from TRANSACTIONS as t inner join channel on t.channel_genesis_hash=channel.channel_genesis_hash and t.network_name=channel.network_name
where t.txhash = '${txhash}' and t.network_name = '${network_name}' `;
Expand All @@ -56,7 +56,7 @@ export class CRUDService {
* @memberof CRUDService
*/

getBlockActivityList(network_name, channel_genesis_hash) {
getBlockActivityList(network_name: any, channel_genesis_hash: any) {
const sqlBlockActivityList = `select blocks.blocknum,blocks.txcount ,blocks.datahash ,blocks.blockhash ,blocks.prehash,blocks.createdt, (
SELECT array_agg(txhash) as txhash FROM transactions where blockid = blocks.blocknum and
channel_genesis_hash = '${channel_genesis_hash}' and network_name = '${network_name}' group by transactions.blockid ),
Expand All @@ -78,7 +78,7 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
getTxList(network_name, channel_genesis_hash, blockNum, txid, from, to, orgs) {
getTxList(network_name: any, channel_genesis_hash: any, blockNum: any, txid: any, from: any, to: any, orgs: string) {
let byOrgs = false;
if (orgs && orgs !== '') {
byOrgs = true;
Expand Down Expand Up @@ -113,12 +113,12 @@ export class CRUDService {
* @memberof CRUDService
*/
getBlockAndTxList(
network_name,
channel_genesis_hash,
blockNum,
from,
to,
orgs
network_name: any,
channel_genesis_hash: any,
blockNum: any,
from: any,
to: any,
orgs: string
) {
let byOrgs = false;
// workaround for SQL injection
Expand Down Expand Up @@ -162,7 +162,7 @@ export class CRUDService {
* @memberof CRUDService
*/

async getChannelConfig(network_name, channel_genesis_hash) {
async getChannelConfig(network_name: any, channel_genesis_hash: any) {
const channelConfig = await this.sql.getRowsBySQlCase(
` select * from channel where channel_genesis_hash ='${channel_genesis_hash}' and network_name = '${network_name}' `
);
Expand All @@ -177,7 +177,7 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
async getChannel(network_name, channelname, channel_genesis_hash) {
async getChannel(network_name: any, channelname: any, channel_genesis_hash: any) {
const channel = await this.sql.getRowsBySQlCase(
` select * from channel where name='${channelname}' and channel_genesis_hash='${channel_genesis_hash}' and network_name = '${network_name}' `
);
Expand All @@ -190,7 +190,7 @@ export class CRUDService {
* @returns
* @memberof CRUDService
*/
async existChannel(network_name, channelname) {
async existChannel(network_name: any, channelname: any) {
const channel = await this.sql.getRowsBySQlCase(
` select count(1) from channel where name='${channelname}' and network_name = '${network_name}' `
);
Expand Down
Loading

0 comments on commit 65b5001

Please sign in to comment.