mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
34 lines
745 B
JavaScript
34 lines
745 B
JavaScript
'use strict';
|
|
|
|
const db = require('./');
|
|
|
|
module.exports.type = 'Stats';
|
|
module.exports.prefix = 'sta';
|
|
module.exports.slug = 'stats';
|
|
module.exports.init = () => db.initModel({
|
|
lastLaunch: Date.now(),
|
|
lastVersion: null,
|
|
launches: 0
|
|
});
|
|
|
|
module.exports.create = (patch = {}) => {
|
|
return db.docCreate(module.exports.type, patch);
|
|
};
|
|
|
|
module.exports.update = patch => {
|
|
return module.exports.get().then(stats => {
|
|
return db.docUpdate(stats, patch);
|
|
});
|
|
};
|
|
|
|
module.exports.get = () => {
|
|
return db.all(module.exports.type).then(results => {
|
|
if (results.length === 0) {
|
|
return module.exports.create()
|
|
.then(module.exports.get);
|
|
} else {
|
|
return new Promise(resolve => resolve(results[0]));
|
|
}
|
|
});
|
|
};
|