Skip to content

Commit

Permalink
fix: command price alert list
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelMedeiros committed Feb 11, 2024
1 parent c01480d commit 301833a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
30 changes: 17 additions & 13 deletions src/domain/bot/commands/my-alert-price.command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, DiscordCommand } from '@discord-nestjs/core'
import { CommandInteraction } from 'discord.js'
import { createResponse, defaultResponse } from 'src/utils/default-response'
import { createResponse } from 'src/utils/default-response'
import { Injectable } from '@nestjs/common'
import { MurrayServiceRepository } from '../repositories'

Expand All @@ -14,20 +14,24 @@ export class MyAlertPriceCommand implements DiscordCommand {
constructor(private readonly repository: MurrayServiceRepository) {}

async handler(interaction: CommandInteraction): Promise<any> {
const userId = interaction.user.id
const { data: alertInfo } = await this.repository.getPriceAlertList({ userId })
try {
const userId = interaction.user.id
const { data: alertInfo } = await this.repository.getPriceAlertList({ userId })

alertInfo.fields.alerts.value = Object.keys(alertInfo.fields.alerts.value)
.map(
(k) =>
`${alertInfo.fields.alerts.value[k].description} ${alertInfo.fields.alerts.value[k].value}`,
)
.join('\n')
alertInfo.fields.alerts.value = Object.keys(alertInfo.fields.alerts.value)
.map(
(k) =>
`${alertInfo.fields.alerts.value[k].description} ${alertInfo.fields.alerts.value[k].value}`,
)
.join('\n')

alertInfo.fields.current.value = Object.keys(alertInfo.fields.current.value)
.map((k) => alertInfo.fields.current.value[k].value)
.join('\n')
alertInfo.fields.current.value = Object.keys(alertInfo.fields.current.value)
.map((k) => alertInfo.fields.current.value[k].value)
.join('\n')

return createResponse(alertInfo)
return createResponse(alertInfo)
} catch (error) {
console.log(error)
}
}
}
14 changes: 9 additions & 5 deletions src/domain/bot/repositories/murrayservice.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,14 @@ export class MurrayServiceRepository {
return this.postData(url, bodyData)
}

getPriceAlertList({ userId }): Promise<any> {
const webhook = this.createWebhookURL('price', userId)
const url = `${this.baseUrl}/alert/price/?webhook=${encodeURIComponent(webhook)}`
return this.getData(url)
getPriceAlertList({ userId }): any {
try {
const webhook = this.createWebhookURL('price', userId)
const url = `${this.baseUrl}/alert/price/?webhookUrl=${encodeURIComponent(webhook)}`
return this.getData(url)
} catch (error) {
console.log(error)
}
}

createTransactionAlert({ userId, transaction, confirmations }): Promise<any> {
Expand Down Expand Up @@ -232,7 +236,7 @@ export class MurrayServiceRepository {
map((response: AxiosResponse<any>) => {
return response.data
}),
catchError(async () => {
catchError(async (err) => {
Logger.error(`GET ${url}`)
throw this.defaultError
}),
Expand Down

0 comments on commit 301833a

Please sign in to comment.