feat(admin): implement 4 admin modules schema, migrations, DTOs and controllers with CSV export
This commit is contained in:
1 parent
5e0541c739
commit
ff3f819fb6
12 files changed
+1584
-157
No files matched your search
@@ -0,0 +1,27 @@
|
||||
export function generateCsv(
|
||||
rows: Record<string, any>[],
|
||||
columns: { key: string; header: string }[],
|
||||
): string {
|
||||
const headerLine = columns
|
||||
.map((c) => `"${c.header.replace(/"/g, '""')}"`)
|
||||
.join(",");
|
||||
const lines = rows.map((row) => {
|
||||
return columns
|
||||
.map((c) => {
|
||||
let val = row[c.key];
|
||||
if (val === null || val === undefined) {
|
||||
return '""';
|
||||
}
|
||||
if (typeof val === "object") {
|
||||
if (val instanceof Date) {
|
||||
val = val.toISOString();
|
||||
} else {
|
||||
val = JSON.stringify(val);
|
||||
}
|
||||
}
|
||||
return `"${String(val).replace(/"/g, '""')}"`;
|
||||
})
|
||||
.join(",");
|
||||
});
|
||||
return "\uFEFF" + [headerLine, ...lines].join("\r\n");
|
||||
}
|
||||
Reference in new issue
Block a user