Skip to content

Commit

Permalink
fix: export emails
Browse files Browse the repository at this point in the history
  • Loading branch information
fufeck committed Nov 13, 2024
1 parent 916fc8d commit 4f20132
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions apps/api/src/modules/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export class AdminController {
@ApiBearerAuth('admin-token')
@UseGuards(SuperAdminGuard)
async downloadEmailCsv(@Res() res: Response) {
const emails: string[] =
const emails: string[][] =
await this.baseLocaleService.findDistinct('emails');

const flattenEmails = emails.reduce((acc, email) => [...acc, ...email], []);
const flattenEmails = emails.reduce(
(acc, email) => [...acc, ...(email || [])],
[],
);
const uniqueEmails = [...new Set(flattenEmails)];

const csvFile = await getStream(
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/modules/base_locale/base_locale.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export class BaseLocaleService {
return updatedBaseLocale;
}

async findDistinct(field: string): Promise<string[]> {
async findDistinct(field: string): Promise<string[][]> {
const distinctValues = await this.basesLocalesRepository
.createQueryBuilder()
.select(`DISTINCT ${field}`)
Expand Down

0 comments on commit 4f20132

Please sign in to comment.