2016-11-10 05:56:23 +00:00
|
|
|
import * as db from '../common/database';
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export const type = 'Stats';
|
|
|
|
export const prefix = 'sta';
|
|
|
|
export function init () {
|
2016-11-10 01:15:27 +00:00
|
|
|
return {
|
2016-10-02 20:57:00 +00:00
|
|
|
lastLaunch: Date.now(),
|
|
|
|
lastVersion: null,
|
|
|
|
launches: 0
|
2016-11-10 01:15:27 +00:00
|
|
|
};
|
2016-10-02 20:57:00 +00:00
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export function create (patch = {}) {
|
|
|
|
return db.docCreate(type, patch);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export async function update (patch) {
|
|
|
|
const stats = await get();
|
|
|
|
return db.docUpdate(stats, patch);
|
|
|
|
}
|
2016-09-21 20:32:45 +00:00
|
|
|
|
2016-10-02 20:57:00 +00:00
|
|
|
export async function get () {
|
|
|
|
const results = await db.all(type);
|
|
|
|
if (results.length === 0) {
|
|
|
|
return await create();
|
|
|
|
} else {
|
|
|
|
return results[0];
|
|
|
|
}
|
|
|
|
}
|