1 | import * as dotenv from'dotenv';
|
2 |
|
3 | import LogService from './core/LogService';
|
4 |
|
5 | import { Account } from '../model/Account';
|
6 | import Message from '../model/Message';
|
7 | import MessageMapper from './core/MessageMapper';
|
8 |
|
9 | export class LogClient {
|
10 | private LOGS = process.env.LOGS;
|
11 | private logService: LogService;
|
12 |
|
13 | constructor() {
|
14 | if (this.LOGS && this.LOGS === 'true') {
|
15 | this.logService = LogService.getInstance();
|
16 | }
|
17 | }
|
18 |
|
19 | public async getAccountDetails(accountAddress: string): Promise<Account> {
|
20 | if (this.LOGS && this.LOGS === 'true') {
|
21 | let accountData = await this.logService.findAccount(accountAddress);
|
22 | if (accountData) {
|
23 | return new Account(accountData.account_address)
|
24 | .setLanguage(accountData.language);
|
25 | }
|
26 | return null;
|
27 | } else return null;
|
28 | }
|
29 |
|
30 | public async getThread(accountAddress: string, parentMessageId: string): Promise<Message[]> {
|
31 | if (this.LOGS && this.LOGS === 'true') {
|
32 | let thread = await this.logService.getThread(accountAddress, parentMessageId);
|
33 | let mapper = new MessageMapper();
|
34 | return thread.messages.map((message: any) => mapper.toMessage(message));
|
35 | } else return null;
|
36 | }
|
37 |
|
38 | } |
\ | No newline at end of file |