This repository was archived by the owner on Sep 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibrisfoliodatamover.js
More file actions
48 lines (43 loc) · 1.45 KB
/
librisfoliodatamover.js
File metadata and controls
48 lines (43 loc) · 1.45 KB
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
module.exports = class LibrisFolioDataMover {
constructor(
fetchScheduler,
librisCommunicator,
dataConverter,
folioCommunicator
) {
this.fetchScheduler = fetchScheduler;
this.librisCommunicator = librisCommunicator;
this.dataConverter = dataConverter;
this.folioCommunicator = folioCommunicator;
}
async moveDataById(id) {
const now = new Date();
const res = await this.librisCommunicator.getDataById(id);
const convertedData = await this.dataConverter.convert(res);
await this.folioCommunicator.sendDataToFolio(convertedData);
await this.fetchScheduler.registerSuccessfulFetchWithId(id, now);
}
async moveDataByTimestamps(from, until, isCronJob) {
const now = new Date();
from = await this.getTimestamp(from);
until = this.getUntilTimestamp(until, now);
const res = await this.librisCommunicator.getDataByTimestamp(from, until);
const convertedData = await this.dataConverter.convert(res);
await this.folioCommunicator.sendDataToFolio(convertedData);
await this.fetchScheduler.registerSuccessfulFetchWithTimestamps(from, until, now, convertedData, isCronJob);
}
async getTimestamp(from) {
if (from) {
return from;
} else {
return await this.fetchScheduler.getLatestSuccessfulFetchTimestamp();
}
}
getUntilTimestamp(until, now) {
if (until) {
return until;
} else {
return this.fetchScheduler.createUTCDateTimeString(now);
}
}
};