From d505b133e154a22a9088c80780f6d5647da0a131 Mon Sep 17 00:00:00 2001 From: Lukas Hroch Date: Mon, 26 Jun 2023 15:53:40 +0100 Subject: [PATCH] fix(export-survey-settings): exclude expired studies --- src/tasks/export-survey-settings.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/tasks/export-survey-settings.ts b/src/tasks/export-survey-settings.ts index ac35754..2f27302 100644 --- a/src/tasks/export-survey-settings.ts +++ b/src/tasks/export-survey-settings.ts @@ -63,9 +63,10 @@ export default class ExtractStudyData implements Task { } private async fetchData() { - const selectQuery = `SELECT id, start_date, end_date FROM surveys ORDER BY start_date ASC;`; - - const data = await this.pgClient.query(selectQuery); + const data = await this.pgClient.query( + `SELECT id, start_date, end_date FROM surveys WHERE end_date > $1 ORDER BY start_date ASC;`, + [new Date()] + ); const fields: FieldInfo[] = [ { label: 'SurveyID', value: 'id' }, @@ -83,8 +84,6 @@ export default class ExtractStudyData implements Task { const csv = await new AsyncParser({ fields }).parse(data.rows).promise(); await fs.writeFile(path, csv, { encoding: 'utf8', flag: 'w+' }); - const attachments = [{ contentType: 'text/csv', path, filename }]; - - return attachments; + return [{ contentType: 'text/csv', path, filename }]; } }