-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemployees.ts
72 lines (66 loc) · 1.83 KB
/
employees.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// @ts-expect-error - Prevent TypeScript from copying the JSON file to the output folder
import jsonEmployees from "../employees.json";
import { deepClone } from "./deep-clone";
import { resolve } from "./isomorphic.node";
/**
* An array of Employee objects. Unlike the raw JSON employee data,
* the date fields of these objects are `Date` objects rather than strings,
* and the image paths are fully resolved.
*/
export const employees: Employee[] = [];
for (let jsonEmployee of jsonEmployees as JsonEmployee[]) {
// Deep-clone the JSON data, so we don't modify the original objects
// (in case the consumer wants to use both the raw and enriched objects)
jsonEmployee = deepClone(jsonEmployee);
employees.push(Object.assign({}, jsonEmployee, {
dob: new Date(jsonEmployee.dob),
hiredOn: new Date(jsonEmployee.hiredOn),
terminatedOn: jsonEmployee.terminatedOn ? new Date(jsonEmployee.terminatedOn) : undefined,
portrait: resolve(jsonEmployee.portrait),
thumbnail: resolve(jsonEmployee.thumbnail),
}));
}
/**
* A raw Employee object, directly from the "employees.json" file
*/
export interface JsonEmployee extends EmployeeBase {
dob: string;
hiredOn: string;
terminatedOn?: string;
}
/**
* An Employee object, as exposed by the Static Mock Data API
*/
export interface Employee extends EmployeeBase {
dob: Date;
hiredOn: Date;
terminatedOn?: Date;
}
/**
* The common fields between Employee and JsonEmployee
*/
interface EmployeeBase {
username: string;
password: string;
name: {
first: string;
last: string;
};
ssn: string;
email: string;
phones: Array<{
type: string;
number: string;
}>;
address: {
street: string;
city: string;
state: string;
zip: string;
};
roles: string[];
department: string;
gender: string;
portrait: string;
thumbnail: string;
}