-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replaced moment with Date object (#5)
* replaced moment with Date object * some refactor * remove filesize --------- Co-authored-by: Erfanium <[email protected]>
- Loading branch information
1 parent
3eb02d5
commit 8fd6a6d
Showing
5 changed files
with
63 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,32 @@ | ||
import CliTable from "cli-table3"; | ||
|
||
import { AuthorizedCommand } from "../../command.js"; | ||
import { TableCommon } from "../../table.js"; | ||
import { makeTable } from "../../table.js"; | ||
|
||
export default class Offers extends AuthorizedCommand { | ||
static description = "List all available offers"; | ||
|
||
async run(): Promise<void> { | ||
const data = await this.api.getOffers(); | ||
|
||
const orderByDuration = data | ||
.filter((item) => item.category !== "smart-bundle") | ||
|
||
.sort((a, b) => { | ||
const aDuration = Number(a.duration); | ||
const bDuration = Number(b.duration); | ||
return aDuration - bDuration; | ||
}); | ||
|
||
const table = new CliTable({ | ||
...TableCommon, | ||
const table = makeTable({ | ||
head: ["Offer Code", "Title", "Price", "Per Gig Price"], | ||
colWidths: [15, 30, 15, 15], | ||
rows: data | ||
.filter((item) => item.category !== "smart-bundle") | ||
.sort((a, b) => { | ||
const aDuration = Number(a.duration); | ||
const bDuration = Number(b.duration); | ||
return aDuration - bDuration; | ||
}) | ||
.map((offer) => [ | ||
offer.offer_id, | ||
offer.title, | ||
Math.round(offer.price / 10_000).toLocaleString() + "T", | ||
offer.volume | ||
? (offer.price / 10_000 / (offer.volume / 1024)).toFixed(1) + "T" | ||
: "-", | ||
]), | ||
}); | ||
|
||
for (const offer of orderByDuration) { | ||
table.push([ | ||
offer.offer_id, | ||
offer.title, | ||
Math.round(offer.price / 10_000).toLocaleString() + "T", | ||
offer.volume | ||
? (offer.price / 10_000 / (offer.volume / 1024)).toFixed(1) + "T" | ||
: "-", | ||
]); | ||
} | ||
|
||
this.log(table.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters