scheduler-node-models 1.2.94 → 1.2.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scheduler-node-models",
3
- "version": "1.2.94",
3
+ "version": "1.2.96",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -32,3 +32,23 @@ export declare class ExcelRow implements IExcelRow {
32
32
  compareTo(other?: ExcelRow): number;
33
33
  toString(): string;
34
34
  }
35
+ /**
36
+ * This interface will contain the rows of information for employees reported on a single
37
+ * SAP Ingest spreadsheet or a Manual Excel spreadsheet, plus the start and ending dates
38
+ * for the spreadsheet, which equates to the first date reported on the sheet and the last.
39
+ */
40
+ export interface IExcelRowPeriod {
41
+ start: Date;
42
+ end: Date;
43
+ rows: IExcelRow[];
44
+ }
45
+ /**
46
+ * This class implements the IExcelRowPeriod interface and provides either default
47
+ * values for the build or fills the information into the object.
48
+ */
49
+ export declare class ExcelRowPeriod implements IExcelRowPeriod {
50
+ start: Date;
51
+ end: Date;
52
+ rows: ExcelRow[];
53
+ constructor(period?: IExcelRowPeriod);
54
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ExcelRow = void 0;
3
+ exports.ExcelRowPeriod = exports.ExcelRow = void 0;
4
4
  class ExcelRow {
5
5
  date;
6
6
  employee;
@@ -59,3 +59,24 @@ class ExcelRow {
59
59
  }
60
60
  }
61
61
  exports.ExcelRow = ExcelRow;
62
+ /**
63
+ * This class implements the IExcelRowPeriod interface and provides either default
64
+ * values for the build or fills the information into the object.
65
+ */
66
+ class ExcelRowPeriod {
67
+ start;
68
+ end;
69
+ rows;
70
+ constructor(period) {
71
+ this.start = (period) ? new Date(period.start) : new Date(Date.UTC(9999, 11, 30));
72
+ this.end = (period) ? new Date(period.end) : new Date(0);
73
+ this.rows = [];
74
+ if (period && period.rows.length > 0) {
75
+ period.rows.forEach(row => {
76
+ this.rows.push(new ExcelRow(row));
77
+ });
78
+ this.rows.sort((a, b) => a.compareTo(b));
79
+ }
80
+ }
81
+ }
82
+ exports.ExcelRowPeriod = ExcelRowPeriod;
@@ -1,19 +1,18 @@
1
1
  import { Row } from "exceljs";
2
2
  import { ISite, Site } from "../sites";
3
3
  import { ITeam, Team } from "../teams";
4
- import { ExcelRow } from "./excelRow";
4
+ import { ExcelRow, ExcelRowPeriod } from "./excelRow";
5
5
  import { LaborCode } from "../labor";
6
6
  import { Employee } from "../employees";
7
7
  export declare class ExcelRowIngest {
8
- files: File[];
8
+ files: Express.Multer.File[];
9
9
  team: Team;
10
10
  site: Site;
11
11
  company: string;
12
12
  docDate: Date;
13
- results: ExcelRow[];
14
- constructor(date: Date, files?: File[], team?: ITeam, site?: ISite, company?: string);
15
- Process(): Promise<ExcelRow[]>;
16
- processFile(file: File): Promise<void>;
13
+ constructor(date: Date, files?: Express.Multer.File[], team?: ITeam, site?: ISite, company?: string);
14
+ Process(): Promise<ExcelRowPeriod[]>;
15
+ processFile(file: Express.Multer.File): Promise<ExcelRowPeriod>;
17
16
  /**
18
17
  * This function is used to provide a list of labor codes for a particular date and
19
18
  * for site and company
@@ -22,5 +21,5 @@ export declare class ExcelRowIngest {
22
21
  * @returns A list of labor codes that can be assigned to an employee.
23
22
  */
24
23
  getForecast(date: Date): Promise<LaborCode[]>;
25
- readCell(row: Row, c: number, colDate: Date, emp: Employee): Promise<void>;
24
+ readCell(row: Row, c: number, colDate: Date, emp: Employee): Promise<ExcelRow | null>;
26
25
  }
@@ -6,36 +6,36 @@ const sites_1 = require("../sites");
6
6
  const teams_1 = require("../teams");
7
7
  const excelRow_1 = require("./excelRow");
8
8
  const labor_1 = require("../labor");
9
+ const stream_1 = require("stream");
9
10
  class ExcelRowIngest {
10
11
  files;
11
12
  team;
12
13
  site;
13
14
  company;
14
15
  docDate;
15
- results;
16
16
  constructor(date, files, team, site, company) {
17
17
  this.files = (files) ? files : [];
18
18
  this.team = (team) ? new teams_1.Team(team) : new teams_1.Team();
19
19
  this.site = (site) ? new sites_1.Site(site) : new sites_1.Site();
20
20
  this.company = (company) ? company : '';
21
21
  this.docDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), 1));
22
- this.results = [];
23
22
  }
24
23
  async Process() {
25
- this.results = [];
24
+ const results = [];
26
25
  if (this.files.length > 0) {
27
26
  const allfiles = this.files.map(async (file, f) => {
28
- await this.processFile(file);
27
+ const result = await this.processFile(file);
28
+ results.push(result);
29
29
  });
30
30
  await Promise.allSettled(allfiles);
31
31
  }
32
- this.results.sort((a, b) => a.compareTo(b));
33
- return this.results;
32
+ return results;
34
33
  }
35
34
  async processFile(file) {
35
+ const result = new excelRow_1.ExcelRowPeriod();
36
36
  // convert the file into a buffer to allow the exceljs library to create an excel
37
37
  // document to read through.
38
- const filereader = file.stream().getReader();
38
+ const filereader = stream_1.Readable.from(file.buffer);
39
39
  const fileDataU8 = [];
40
40
  while (true) {
41
41
  const { done, value } = await filereader.read();
@@ -49,7 +49,13 @@ class ExcelRowIngest {
49
49
  const worksheet = workbook.getWorksheet('Sheet1');
50
50
  const monthDates = [];
51
51
  for (let d = 0; d < 31; d++) {
52
- monthDates.push(new Date(this.docDate.getTime() + (d * 24 * 3600000)));
52
+ const nDate = new Date(this.docDate.getTime() + (d * 24 * 3600000));
53
+ if (nDate.getTime() < result.start.getTime()) {
54
+ result.start = new Date(nDate);
55
+ }
56
+ if (nDate.getTime() > result.end.getTime()) {
57
+ result.end = new Date(nDate);
58
+ }
53
59
  }
54
60
  if (worksheet) {
55
61
  worksheet.eachRow(async (row, r) => {
@@ -60,7 +66,10 @@ class ExcelRowIngest {
60
66
  const emp = this.site.employees.find(e => e.name.getLastFirst().toLowerCase() === name.toLowerCase());
61
67
  if (emp) {
62
68
  const rowPromises = monthDates.map(async (day, d) => {
63
- await this.readCell(row, d + 3, day, emp);
69
+ const erow = await this.readCell(row, d + 3, day, emp);
70
+ if (erow !== null) {
71
+ result.rows.push(new excelRow_1.ExcelRow(erow));
72
+ }
64
73
  });
65
74
  await Promise.allSettled(rowPromises);
66
75
  }
@@ -75,6 +84,8 @@ class ExcelRowIngest {
75
84
  else {
76
85
  throw new Error('No worksheet');
77
86
  }
87
+ result.rows.sort((a, b) => a.compareTo(b));
88
+ return result;
78
89
  }
79
90
  /**
80
91
  * This function is used to provide a list of labor codes for a particular date and
@@ -129,7 +140,7 @@ class ExcelRowIngest {
129
140
  eRow.extension = laborcode.extension;
130
141
  eRow.premium = '1';
131
142
  eRow.hours = Number(sValue);
132
- this.results.push(new excelRow_1.ExcelRow(eRow));
143
+ return new excelRow_1.ExcelRow(eRow);
133
144
  }
134
145
  }
135
146
  else {
@@ -143,11 +154,12 @@ class ExcelRowIngest {
143
154
  eRow.employee = emp.companyinfo.employeeid;
144
155
  eRow.code = wc.id;
145
156
  eRow.hours = emp.getStandardWorkday(colDate);
146
- this.results.push(new excelRow_1.ExcelRow(eRow));
157
+ return new excelRow_1.ExcelRow(eRow);
147
158
  }
148
159
  });
149
160
  }
150
161
  }
162
+ return null;
151
163
  }
152
164
  }
153
165
  exports.ExcelRowIngest = ExcelRowIngest;
@@ -1,9 +1,9 @@
1
1
  import { ITeam, Team } from "../teams";
2
- import { ExcelRow } from "./excelRow";
2
+ import { ExcelRowPeriod } from "./excelRow";
3
3
  export declare class SAPIngest {
4
- files: File[];
4
+ files: Express.Multer.File[];
5
5
  team: Team;
6
- constructor(files?: File[], team?: ITeam);
7
- Process(): Promise<ExcelRow[]>;
8
- processFile(file: File): Promise<ExcelRow[]>;
6
+ constructor(files?: Express.Multer.File[], team?: ITeam);
7
+ Process(): Promise<ExcelRowPeriod[]>;
8
+ processFile(file: Express.Multer.File): Promise<ExcelRowPeriod>;
9
9
  }
@@ -4,6 +4,7 @@ exports.SAPIngest = void 0;
4
4
  const teams_1 = require("../teams");
5
5
  const excelRow_1 = require("./excelRow");
6
6
  const exceljs_1 = require("exceljs");
7
+ const stream_1 = require("stream");
7
8
  class SAPIngest {
8
9
  files;
9
10
  team;
@@ -16,18 +17,17 @@ class SAPIngest {
16
17
  if (this.files.length > 0) {
17
18
  const allfiles = this.files.map(async (file, f) => {
18
19
  const results = await this.processFile(file);
19
- result.push(...results);
20
+ result.push(results);
20
21
  });
21
22
  await Promise.allSettled(allfiles);
22
23
  }
23
- result.sort((a, b) => a.compareTo(b));
24
24
  return result;
25
25
  }
26
26
  async processFile(file) {
27
- const result = [];
27
+ const result = new excelRow_1.ExcelRowPeriod();
28
28
  // convert the file into a buffer to allow the exceljs library to create an excel
29
29
  // document to read through.
30
- const filereader = file.stream().getReader();
30
+ const filereader = stream_1.Readable.from(file.buffer);
31
31
  const fileDataU8 = [];
32
32
  while (true) {
33
33
  const { done, value } = await filereader.read();
@@ -114,11 +114,17 @@ class SAPIngest {
114
114
  }
115
115
  }
116
116
  });
117
- result.push(eRow);
117
+ if (eRow.date.getTime() < result.start.getTime()) {
118
+ result.start = new Date(eRow.date);
119
+ }
120
+ if (eRow.date.getTime() > result.end.getTime()) {
121
+ result.end = new Date(eRow.date);
122
+ }
123
+ result.rows.push(eRow);
118
124
  }
119
125
  });
120
126
  }
121
- result.sort((a, b) => a.compareTo(b));
127
+ result.rows.sort((a, b) => a.compareTo(b));
122
128
  }
123
129
  return result;
124
130
  }
@@ -0,0 +1 @@
1
+ export * from './requests';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./requests"), exports);
@@ -0,0 +1,6 @@
1
+ export interface SiteUpdate {
2
+ team: string;
3
+ site: string;
4
+ field: string;
5
+ value: string;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });