From 8c9d237906488c6530a5b112883b3c3633147d43 Mon Sep 17 00:00:00 2001 From: rozetko Date: Fri, 20 Jan 2023 15:51:56 +0300 Subject: [PATCH] rm promisify from utils --- src/services/exporter.ts | 6 +++--- src/utils.ts | 12 ------------ 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/services/exporter.ts b/src/services/exporter.ts index 2c33bf0..f353d15 100644 --- a/src/services/exporter.ts +++ b/src/services/exporter.ts @@ -1,6 +1,6 @@ -// TODO: import promisify from 'util' +import { promisify } from 'util' import { getApiKey } from './api_keys'; -import { promisify, toIsoString } from '../utils'; +import { toIsoString } from '../utils'; import { DashboardQuery, ExportProgress, ExportStatus, ExportTask } from '../types'; import { CSV_PATH } from '../config'; @@ -135,7 +135,7 @@ export class Exporter { progress: _.assign(this._task.progress, progress, { time }), }; - await promisify(fs.writeFile, this._getFilePath('json'), JSON.stringify(data), 'utf8'); + await promisify(fs.writeFile)(this._getFilePath('json'), JSON.stringify(data), 'utf8'); } catch(err) { console.error(err); throw new Error('Can`t write file'); diff --git a/src/utils.ts b/src/utils.ts index a1fcc7f..1377075 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,17 +1,5 @@ import * as moment from 'moment-timezone'; -export async function promisify(method: (...params: any[]) => Promise | void, ...params: any[]) { - return new Promise((resolve, reject) => { - method(...params, (err, result) => { - if(err) { - reject(err); - } else { - resolve(result); - } - }) - }); -} - export function toIsoString(msTimestamp: number, timeZone: string): string { return moment.tz(msTimestamp, timeZone).format('YYYY-MM-DD HH:mm:ssZ').replace(/:00$/, ''); }