File tree Expand file tree Collapse file tree 5 files changed +15
-13
lines changed Expand file tree Collapse file tree 5 files changed +15
-13
lines changed Original file line number Diff line number Diff line change 1
1
import { WorkBook } from '~/common/xlsx.util' ;
2
- import { type Downloadable } from '../file/dto' ;
2
+ import { type Downloadable , type FileVersion } from '../file/dto' ;
3
3
import { PlanningSheet } from './planning-sheet' ;
4
4
import { ProgressSheet } from './progress-sheet' ;
5
5
6
6
const ParsedPnp = Symbol ( 'Parsed PnP' ) ;
7
7
8
8
export class Pnp {
9
- constructor ( protected workbook : WorkBook ) { }
9
+ constructor ( protected workbook : WorkBook , protected fileName ?: string ) { }
10
10
11
11
/**
12
12
* Create PnP from Downloadable.
13
13
* Will reuse an existing instance from a previous call.
14
14
*/
15
- static async fromDownloadable ( obj : Downloadable < unknown > ) {
15
+ static async fromDownloadable ( obj : Downloadable < FileVersion > ) {
16
16
const promise = obj . download ( ) as Promise < Buffer > & { [ ParsedPnp ] ?: Pnp } ;
17
17
if ( ! promise [ ParsedPnp ] ) {
18
- promise [ ParsedPnp ] = Pnp . fromBuffer ( await promise ) ;
18
+ promise [ ParsedPnp ] = Pnp . fromBuffer ( await promise , obj . name ) ;
19
19
}
20
20
return promise [ ParsedPnp ] ! ;
21
21
}
22
22
23
- static fromBuffer ( buffer : Buffer ) {
23
+ static fromBuffer ( buffer : Buffer , name ?: string ) {
24
24
const book = WorkBook . fromBuffer ( buffer ) ;
25
25
PlanningSheet . register ( book ) ;
26
26
ProgressSheet . register ( book ) ;
27
- return new Pnp ( book ) ;
27
+ return new Pnp ( book , name ) ;
28
28
}
29
29
30
30
get planning ( ) {
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { entries } from '@seedcompany/common';
3
3
import { assert } from 'ts-essentials' ;
4
4
import type { MergeExclusive } from 'type-fest' ;
5
5
import type { Cell , Column , Row } from '~/common/xlsx.util' ;
6
- import type { Downloadable } from '../file/dto' ;
6
+ import type { Downloadable , FileVersion } from '../file/dto' ;
7
7
import {
8
8
extractScripture ,
9
9
findStepColumns ,
@@ -45,7 +45,7 @@ type ExtractedRow = MergeExclusive<
45
45
@Injectable ( )
46
46
export class StepProgressExtractor {
47
47
async extract (
48
- file : Downloadable < unknown > ,
48
+ file : Downloadable < FileVersion > ,
49
49
result : PnpProgressExtractionResult ,
50
50
) {
51
51
const pnp = await Pnp . fromDownloadable ( file ) ;
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { assert } from 'ts-essentials';
5
5
import { type MergeExclusive } from 'type-fest' ;
6
6
import { type CalendarDate , type DateInterval } from '~/common' ;
7
7
import { type Cell , type Column , type Row } from '~/common/xlsx.util' ;
8
- import { type Downloadable } from '../file/dto' ;
8
+ import { type Downloadable , type FileVersion } from '../file/dto' ;
9
9
import {
10
10
extractScripture ,
11
11
findStepColumns ,
@@ -31,7 +31,7 @@ import { type ProductStep, type ProductStep as Step } from './dto';
31
31
@Injectable ( )
32
32
export class ProductExtractor {
33
33
async extract (
34
- file : Downloadable < unknown > ,
34
+ file : Downloadable < FileVersion > ,
35
35
engagementRange : DateInterval | null ,
36
36
availableSteps : readonly ProductStep [ ] ,
37
37
result : PnpPlanningExtractionResult ,
Original file line number Diff line number Diff line change 8
8
fiscalYear ,
9
9
} from '~/common' ;
10
10
import { type Column , type Row } from '~/common/xlsx.util' ;
11
- import { type Downloadable } from '../file/dto' ;
11
+ import { type Downloadable , type FileVersion } from '../file/dto' ;
12
12
import { Pnp , type ProgressSheet } from '../pnp' ;
13
13
import {
14
14
PnpProblemType ,
@@ -19,7 +19,7 @@ import { type ProgressSummary as Progress } from './dto';
19
19
@Injectable ( )
20
20
export class ProgressSummaryExtractor {
21
21
async extract (
22
- file : Downloadable < unknown > ,
22
+ file : Downloadable < FileVersion > ,
23
23
date : CalendarDate ,
24
24
result : PnpProgressExtractionResult ,
25
25
) {
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import * as fs from 'fs/promises';
6
6
// eslint-disable-next-line no-restricted-imports
7
7
import * as lodash from 'lodash' ;
8
8
import { DateTime , Duration , Interval } from 'luxon' ;
9
+ import { basename } from 'node:path' ;
9
10
import { CalendarDate , DateInterval } from '~/common' ;
10
11
import * as common from '~/common' ;
11
12
import './polyfills' ;
@@ -46,7 +47,8 @@ runRepl({
46
47
session,
47
48
sessionFor : session . withRoles ,
48
49
Resources,
49
- loadPnp : ( filepath : string ) => Pnp . fromBuffer ( readFileSync ( filepath ) ) ,
50
+ loadPnp : ( filepath : string ) =>
51
+ Pnp . fromBuffer ( readFileSync ( filepath ) , basename ( filepath ) ) ,
50
52
} ;
51
53
} ,
52
54
} ) ;
You can’t perform that action at this time.
0 commit comments