-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressService.js
28 lines (25 loc) · 1.15 KB
/
AddressService.js
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
var environment = require('./environment');
var DBProviderFactory = require('./DBService/DBProviderFactory');
var dbInstance = DBProviderFactory.getInstance(environment.CURRENT_DB_PROVIDER);
class AddressService {
checkAddress(address) {
dbInstance.getAddressesData().then(function (addressesDataObj) {
var addresses = addressesDataObj.addresses;
var addressesCount = addressesDataObj.addressesCount;
if (addresses && Array.isArray(addresses) && addresses.length > 0 && addresses.indexOf(address)) {
var addressIndex = addresses.indexOf(address);
var addressCount = ++addressesDataObj.addressesCount[addressIndex];
this.print(addressesDataObj);
dbInstance.setAddressData(address, addressCount);
}
}.bind(this));
}
print(addressesDataObj) {
var addresses = addressesDataObj.addresses;
var addressesCount = addressesDataObj.addressesCount;
for (index in addresses) {
console.log("Address : " + addresses[index] + " occures : " + addressesCount[index]);
}
}
}
module.exports = AddressService;