-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallkeyshop.js
More file actions
43 lines (43 loc) · 1.49 KB
/
Copy pathallkeyshop.js
File metadata and controls
43 lines (43 loc) · 1.49 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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AllkeyshopService = void 0;
const constants_1 = require("../config/constants");
const gather_1 = require("./gather");
class AllkeyshopService {
currency;
platform;
store;
constructor(options) {
this.currency = options?.currency?.toLowerCase() ?? constants_1.defaultOptions.currency;
this.platform = options?.platform?.toLowerCase() ?? constants_1.defaultOptions.platform;
this.platform = this.platform === 'pc' ? '' : this.platform;
this.store = options?.store?.toLowerCase() ?? constants_1.defaultOptions.store;
}
async search(name) {
name = this.appendPlatform(name);
const games = await (0, gather_1.getProductIds)(name);
if (games.status === 'error') {
return this.emptyData();
}
const response = await (0, gather_1.getGameData)(games.games, this.currency, this.store);
return response ?? this.emptyData();
}
async find(name) {
name = this.appendPlatform(name);
return await (0, gather_1.getProductIds)(name);
}
appendPlatform(name) {
return this.platform !== '' ? `${name} ${this.platform}` : name;
}
emptyData() {
return {
offers: [],
lowestPrices: {
official: null,
keyshops: null,
},
};
}
}
exports.AllkeyshopService = AllkeyshopService;
//# sourceMappingURL=allkeyshop.js.map