refactoring interfaces

modified:   database.ts
	new file:   interfaces/databaseInterface.d.ts
	modified:   tsconfig.json
This commit is contained in:
”minicx” 2022-11-30 15:51:56 +03:00
parent 4ca734b1a7
commit c82106ab79
3 changed files with 46 additions and 45 deletions

View file

@ -3,48 +3,10 @@ import {Fingerprint, FingerprintGenerator} from "fingerprint-generator"
import logger from "./logger" import logger from "./logger"
import fs = require('fs'); import fs = require('fs');
import path=require('path'); import path=require('path');
import * as interfaces from "./interfaces/databaseInterface"
// interfaces
interface faucetMailInterface {
faucet: {
username: string,
password: string
}
mail: {
address: string,
password: string
}
}
interface AccountCompletedGroupsTasksInterface {
}
interface AccountWithdrawInterface {
}
interface AccountInterface {
phoneNumber: string,
telegramID: number,
apiID: number,
apiHash: string,
password: string,
faucetMail: faucetMailInterface,
stringSession: string,
balance: number,
withdraws:AccountWithdrawInterface[],
completedGroupsTasks:AccountCompletedGroupsTasksInterface[],
canBeRefferal: boolean,
browserFingerprint:Fingerprint,
refferal:number | boolean
}
interface DatabaseInterface {
accounts: AccountInterface[]
}
//
class Database { class Database {
public readonly default: DatabaseInterface={ public readonly default: interfaces.DatabaseInterface={
accounts:[] accounts:[]
} }
private json: JsonDB; private json: JsonDB;
@ -60,7 +22,7 @@ class Database {
} }
}) })
} }
private async findWallet(walletsFile: string): Promise<faucetMailInterface | undefined>{ private async findWallet(walletsFile: string): Promise<interfaces.faucetMailInterface | undefined>{
const wallets_json=new JsonDB(new Config(walletsFile,true,true,'/')); const wallets_json=new JsonDB(new Config(walletsFile,true,true,'/'));
const wallets=(await wallets_json.getData('/')); const wallets=(await wallets_json.getData('/'));
if (Object.keys(wallets).length==0){ if (Object.keys(wallets).length==0){
@ -68,7 +30,7 @@ class Database {
throw new Error('File which you choose doesnt have anything') throw new Error('File which you choose doesnt have anything')
} }
const accounts=(await this.getUsers()); const accounts=(await this.getUsers());
let faucetWallet:faucetMailInterface | undefined=undefined; let faucetWallet:interfaces.faucetMailInterface | undefined=undefined;
for (const _wallet in wallets){ for (const _wallet in wallets){
let flag=false; let flag=false;
if (accounts.length>0){ if (accounts.length>0){
@ -125,7 +87,7 @@ class Database {
} }
return refferal; return refferal;
} }
async addUser(account: Omit<AccountInterface, async addUser(account: Omit<interfaces.AccountInterface,
'balance' | 'withdraws' | 'completedGroupsTasks' | 'canBeRefferal' 'balance' | 'withdraws' | 'completedGroupsTasks' | 'canBeRefferal'
| 'browserFingerprint' | 'faucetMail'>,wallets_json: string): Promise<void>{ | 'browserFingerprint' | 'faucetMail'>,wallets_json: string): Promise<void>{
const fingerprintGenerator = new FingerprintGenerator(); const fingerprintGenerator = new FingerprintGenerator();
@ -135,7 +97,7 @@ class Database {
}).fingerprint; }).fingerprint;
const faucet:faucetMailInterface | undefined=await this.findWallet(wallets_json); const faucet:interfaces.faucetMailInterface | undefined=await this.findWallet(wallets_json);
if (faucet === undefined){ if (faucet === undefined){
logger.error('Add new faucet accounts'); logger.error('Add new faucet accounts');
throw new Error('Add new faucet accounts'); throw new Error('Add new faucet accounts');
@ -162,7 +124,7 @@ class Database {
} }
async getUsers(): Promise<AccountInterface[]>{ async getUsers(): Promise<interfaces.AccountInterface[]>{
try { try {
return await this.json.getData('/accounts'); return await this.json.getData('/accounts');
@ -177,3 +139,4 @@ class Database {
} }
class Settings {}

37
interfaces/databaseInterface.d.ts vendored Normal file
View file

@ -0,0 +1,37 @@
import {Fingerprint} from "fingerprint-generator"
export interface faucetMailInterface {
faucet: {
username: string,
password: string
}
mail: {
address: string,
password: string
}
}
export interface AccountCompletedGroupsTasksInterface {
}
export interface AccountWithdrawInterface {
}
export interface AccountInterface {
phoneNumber: string,
telegramID: number,
apiID: number,
apiHash: string,
password: string,
faucetMail: faucetMailInterface,
stringSession: string,
balance: number,
withdraws:AccountWithdrawInterface[],
completedGroupsTasks:AccountCompletedGroupsTasksInterface[],
canBeRefferal: boolean,
browserFingerprint:Fingerprint,
refferal:number | boolean
}
export interface DatabaseInterface {
accounts: AccountInterface[]
}

View file

@ -11,6 +11,7 @@
}, },
"exclude": [ "exclude": [
"interfaces",
"node_modules", "node_modules",
"**/node_modules/*" "**/node_modules/*"
] ]