Browse Source

rm promisify from utils

pull/7/head
rozetko 2 years ago
parent
commit
8c9d237906
  1. 6
      src/services/exporter.ts
  2. 12
      src/utils.ts

6
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');

12
src/utils.ts

@ -1,17 +1,5 @@
import * as moment from 'moment-timezone';
export async function promisify(method: (...params: any[]) => Promise<any> | 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$/, '');
}

Loading…
Cancel
Save