Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as mssql from 'mssql';
- import { AppConfig } from '../config';
- import { ActionService } from './data-services';
- import { Logger, LoggerFactory } from '../common';
- export class AppDataServices {
- private static readonly LOGGER: Logger = LoggerFactory.getLogger();
- private db: any;
- public actionService: ActionService;
- constructor(private appConfig: AppConfig) {
- this.initConnectionPool();
- this.actionService = new ActionService(this.db, AppDataServices.LOGGER);
- }
- private initConnectionPool() {
- this.db = new mssql.ConnectionPool({
- user: this.appConfig.mssqlUsername,
- password: this.appConfig.mssqlPassword,
- server: this.appConfig.mssqlServer,
- database: this.appConfig.mssqlDatabase,
- // If you are on Microsoft Azure, you need this:
- options: { encrypt: true }
- }, (err: any) => {
- if (err) AppDataServices.LOGGER.error('MSSQL error', err);
- });
- }
- }
- import * as mssql from 'mssql';
- import { Logger, LoggerFactory } from '../../../common';
- export class ActionService {
- private static readonly LOGGER: Logger = LoggerFactory.getLogger();
- constructor (private db: any, private logger: any) {
- this.insertion();
- }
- insertion() {
- const request = new mssql.Request(this.db);
- request.query(
- `
- INSERT INTO dbo.action
- (timestamp, result, description, request_endpoint, request_payload, response_status, response_payload, actualAmount, rule_id, lendbook_id)
- SELECT t1.start, 'SUCCESS', NULL, '/lendbook/usd', NULL, '200', NULL, t1.originalAmount, t1.id, t2.id
- FROM dbo.rule t1, dbo.lendbook t2
- INNER JOIN t2.id = t1.id
- `, (err, result) => {
- if (err) {
- console.error(err);
- return;
- }
- return result.recordsets[0];
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement