Skip to content

Commit

Permalink
use tsv instead since some names contain commas
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Nov 9, 2024
1 parent 4337bfe commit 499eb92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions backend/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { TopupTable } from "types/topup"
import { TransactionTable } from "types/transaction"
import { UserTable, UserType } from "types/user"
import Archiver from "archiver"
import { objectsToCsv } from "utils"
import { objectsToCsv as objectsToTsv } from "utils"
import { getRandom } from "getRandom"
import { hash } from "passwords"

Expand Down Expand Up @@ -165,14 +165,14 @@ router.get("/dump", async (_, res) => {
archive.pipe(res)

await archive
.append(objectsToCsv(topups, topupHeaders), {
name: "topups.csv",
.append(objectsToTsv(topups, topupHeaders), {
name: "topups.tsv",
})
.append(objectsToCsv(transactions, transactionHeaders), {
name: "transactions.csv",
.append(objectsToTsv(transactions, transactionHeaders), {
name: "transactions.tsv",
})
.append(objectsToCsv(users, userHeaders), {
name: "users.csv",
.append(objectsToTsv(users, userHeaders), {
name: "users.tsv",
})
.finalize()
})
Expand Down
6 changes: 3 additions & 3 deletions backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ export function objectsToCsv(
data: Record<string, unknown>[],
headers: string[],
): string {
const csv = [headers.join(",")]
const tsv = [headers.join("\t")]

for (const row of data) {
csv.push(headers.map((key) => row[key]).join(","))
tsv.push(headers.map((key) => row[key]).join("\t"))
}

return csv.join("\n")
return tsv.join("\n")
}

0 comments on commit 499eb92

Please sign in to comment.