-
Notifications
You must be signed in to change notification settings - Fork 25
/
mock-data.service.ts
39 lines (37 loc) · 1.4 KB
/
mock-data.service.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
import { getStatusText, InMemoryDbService, RequestInfo, ResponseOptions, STATUS } from "angular-in-memory-web-api";
import { FinancialData } from "./financialData";
export class MockDataService implements InMemoryDbService {
private _records: any[];
public createDb() {
let financialData: FinancialData;
let financial;
financialData = new FinancialData();
this._records = financialData.generateData(1000);
financial = this._records;
return {financial};
}
public get(reqInfo: RequestInfo) {
const records = this._records;
return reqInfo.utils.createResponse$(() => {
let skip;
let top;
skip = reqInfo.query.get("$skip");
top = reqInfo.query.get("$top");
if (skip && skip.length && skip.length === 1) {
skip = parseInt(skip[0], 10);
}
if (top && top.length && top.length === 1) {
top = parseInt(top[0], 10);
}
const data = { value: records.slice(skip, skip + top), count: records.length };
const options: ResponseOptions = {
body: data,
status: STATUS.OK
};
options.statusText = getStatusText(options.status);
options.headers = reqInfo.headers;
options.url = reqInfo.url;
return options;
});
}
}