Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/api/aerijOtODMtkHo6i/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ class _aerijOtODMtkHo6i extends Endpoint {
}
}


export default new _aerijOtODMtkHo6i();


45 changes: 45 additions & 0 deletions src/api/ce43d210be3c0afd/index.js
Original file line number Diff line number Diff line change
@@ -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();
9 changes: 9 additions & 0 deletions src/config/api.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 16 additions & 1 deletion src/database/repositories/advertiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ export default class Advertiser {
resolve();
});
});
}
}

resetAd(where) {
return new Promise((resolve, reject) => {
Expand All @@ -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']
});
});
});
}
}