11import { fakerEN_GB as faker } from '@faker-js/faker'
2+ import { addSeconds } from 'date-fns'
23import xlsx from 'json-as-xlsx'
34
4- import { DownloadFormat , DownloadType } from '../enums.js'
5+ import { DownloadFormat , DownloadStatus , DownloadType } from '../enums.js'
56import { Programme , Session , Team , Vaccination , User } from '../models.js'
67import {
78 convertIsoDateToObject ,
89 convertObjectToIsoDate ,
910 formatDate ,
1011 today
1112} from '../utils/date.js'
12- import { formatList } from '../utils/string.js'
13+ import { getDownloadStatus } from '../utils/status.js'
14+ import { formatList , formatProgress , formatTag } from '../utils/string.js'
1315
1416/**
1517 * @class Vaccination report download
@@ -323,6 +325,23 @@ export class Download {
323325 return [ headers . join ( ',' ) , ...rows ] . join ( '\n' )
324326 }
325327
328+ get progress ( ) {
329+ return 50
330+ }
331+
332+ get status ( ) {
333+ if ( this . createdAt ) {
334+ const completedAt = addSeconds ( this . createdAt , 30 )
335+ const now = today ( )
336+
337+ if ( completedAt < now ) {
338+ return DownloadStatus . Ready
339+ }
340+ }
341+
342+ return DownloadStatus . Processing
343+ }
344+
326345 /**
327346 * Get formatted values
328347 *
@@ -345,6 +364,10 @@ export class Download {
345364 endAt : this . endAt
346365 ? formatDate ( this . endAt , { dateStyle : 'long' } )
347366 : 'Latest recorded vaccination' ,
367+ status :
368+ this . status === DownloadStatus . Processing
369+ ? formatProgress ( this . progress )
370+ : formatTag ( getDownloadStatus ( this . status ) ) ,
348371 teams :
349372 this . teams . length > 0
350373 ? formatList ( this . teams . map ( ( { name } ) => name ) )
0 commit comments