Skip to content

Commit

Permalink
add revenue report
Browse files Browse the repository at this point in the history
  • Loading branch information
fegloff committed Jan 10, 2024
1 parent f3ab56e commit 746c087
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/database/stats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,24 @@ export class StatsService {
return rows
}

public async getRevenue (daysPeriod = 7): Promise<string> {
const currentTime = moment()
const dateStart = moment()
.tz('America/Los_Angeles')
.set({ hour: 0, minute: 0, second: 0 })
.subtract(daysPeriod, 'days')
.unix()

const dateEnd = currentTime.unix()
const result = await logRepository.createQueryBuilder('logs')
// const result = await invoiceRepository.createQueryBuilder('invoice')
.select('SUM(CAST(logs.amountCredits AS NUMERIC)) AS revenue')
.where('logs.isSupportedCommand=true')
.andWhere(`logs.createdAt BETWEEN TO_TIMESTAMP(${dateStart}) and TO_TIMESTAMP(${dateEnd})`)
.execute()
return result[0].revenue
}

public async addCommandStat ({ tgUserId, rawMessage, command }: { tgUserId: number, rawMessage: string, command: string }): Promise<StatBotCommand> {
const stat = new StatBotCommand()

Expand Down

0 comments on commit 746c087

Please sign in to comment.