diff --git a/src/api/aerijOtODMtkHo6i/index.js b/src/api/aerijOtODMtkHo6i/index.js index 9ed8bb1..8a92c97 100644 --- a/src/api/aerijOtODMtkHo6i/index.js +++ b/src/api/aerijOtODMtkHo6i/index.js @@ -44,5 +44,6 @@ class _aerijOtODMtkHo6i extends Endpoint { } } - export default new _aerijOtODMtkHo6i(); + + diff --git a/src/api/ce43d210be3c0afd/index.js b/src/api/ce43d210be3c0afd/index.js new file mode 100644 index 0000000..7079f37 --- /dev/null +++ b/src/api/ce43d210be3c0afd/index.js @@ -0,0 +1,45 @@ +import Endpoint from '../endpoint'; +import database from '../../database/database'; +import peer from '../../network/peer'; + +/** + * api list_ad + */ + +class _ce43d210be3c0afd extends Endpoint { + constructor() { + super('ce43d210be3c0afd'); + } + + /** + * returns list of ads by given + * @param app + * @param req + * @param res + */ + handler(app, req, res) { + if (peer.protocolAddressKeyIdentifier === null) { + return res.send({ + api_status : 'fail', + api_message: `unexpected generic api error: (wallet not loaded)` + }); + } + + let pipeline = Promise.resolve(); + pipeline.then(() => { + const advertiserRepository = database.getRepository('advertiser'); + return advertiserRepository.getAdvertisementRunningCounters().then(counters => res.send({ + api_status : 'ok', + api_message : 'fetch successfull', + counters : counters + } + )); + }).catch(e => res.send({ + api_status : 'fail', + api_message: `unexpected generic api error: (${e})` + })); + + } +} + +export default new _ce43d210be3c0afd(); \ No newline at end of file diff --git a/src/config/api.json b/src/config/api.json index 5bf1071..fa363a8 100644 --- a/src/config/api.json +++ b/src/config/api.json @@ -1,5 +1,14 @@ { "endpoint_list": [ + { + "id": "ce43d210be3c0afd", + "name": "ads_counters", + "description": "user ads counters", + "method": "GET", + "version_released": "1.0.0", + "permission": "{\"require_identity\": false, \"private\": false}", + "enable": true + }, { "id": "0QJZ31dutPTSexxZ", "name": "api_version", diff --git a/src/database/repositories/advertiser.js b/src/database/repositories/advertiser.js index 0d564e5..e92874c 100644 --- a/src/database/repositories/advertiser.js +++ b/src/database/repositories/advertiser.js @@ -737,7 +737,7 @@ export default class Advertiser { resolve(); }); }); - } + } resetAd(where) { return new Promise((resolve, reject) => { @@ -755,4 +755,19 @@ export default class Advertiser { }); }); } + + getAdvertisementRunningCounters() { + return new Promise((resolve, reject) => { + this.database.get('SELECT COUNT(*) as total, COUNT(CASE WHEN status = 1 THEN 1 END) as active, COUNT(CASE WHEN status = 0 THEN 1 END) as paused FROM advertisement_advertiser.advertisement', (err, data) => { + if (err) { + return reject(err); + } + resolve({ + total :data['total'], + active :data['active'], + paused :data['paused'] + }); + }); + }); + } }