-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaginator.ts
76 lines (58 loc) · 2.35 KB
/
paginator.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
73
74
75
76
import { NextFunction, Request, Response } from 'express';
import { Injectable } from '@angular/core';
import axios from 'axios';
// export function pag(req: Request, res: Response, next: NextFunction) {
// paginationpost(endURL, payload);
// }
let paginationValue: number = 1000;
let jsonArr: any = [];
let paginationId = (new Date().getTime() / 1000 | 0).toString(16) + Math.ceil(Math.random() * 100000000000);
// let paginationId: number = Math.ceil(Math.random() * 100000000000);
let pageNo: any;
let payloadSize: number;
// export function paginationpost(endURL: string, payload: any, option: any, callback): any {
export function paginationpost(endURL: string, payload: any, option: any, callback): any {
let arr: any = [];
let i: number, responseCount: number = 0, j = 0;
let promise: any = [];
for (i = 0; i < payload.length; i += paginationValue) {
arr[j] = payload.substring(i, i + paginationValue);
jsonArr[j] = {
'id': paginationId,
'pageno': (j + 1),
'payloadSize': payload.length,
'total': Math.ceil(payload.length / paginationValue),
'data': arr[j]
};
// sending splitted jdp
axios.post(endURL, jsonArr[j])
// handling last jdp response
.then(function (response) {
if (response.status === 200) {
responseCount++;
if (responseCount === Math.ceil(payload.length / paginationValue)) {
// return "success! all jdp recieved";
// response.status(200).send("DONE!");
console.log('success! all jdp sent, recieved by BE');
} else
console.log(response.status);
}
})
.catch(function (error) {
console.log('error in axios ');
});
// this.http.post(endURL, payload, option)
// .subscribe(
// (response) => {
// console.log(response);
// callback(response);
// },
// (error) => {
// console.log('Error: ' + error);
// callback(error);
// }
// );
j++;
}
}
// ........................................................