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
@@ -320,6 +322,23 @@ export class Download {
320322 return [ headers . join ( ',' ) , ...rows ] . join ( '\n' )
321323 }
322324
325+ get progress ( ) {
326+ return 50
327+ }
328+
329+ get status ( ) {
330+ if ( this . createdAt ) {
331+ const completedAt = addSeconds ( this . createdAt , 30 )
332+ const now = today ( )
333+
334+ if ( completedAt < now ) {
335+ return DownloadStatus . Ready
336+ }
337+ }
338+
339+ return DownloadStatus . Processing
340+ }
341+
323342 /**
324343 * Get formatted values
325344 *
@@ -342,6 +361,10 @@ export class Download {
342361 endAt : this . endAt
343362 ? formatDate ( this . endAt , { dateStyle : 'long' } )
344363 : 'Latest recorded vaccination' ,
364+ status :
365+ this . status === DownloadStatus . Processing
366+ ? formatProgress ( this . progress )
367+ : formatTag ( getDownloadStatus ( this . status ) ) ,
345368 teams :
346369 this . teams . length > 0
347370 ? formatList ( this . teams . map ( ( { name } ) => name ) )
0 commit comments