58 lines
1.1 KiB
JavaScript
58 lines
1.1 KiB
JavaScript
/**
|
|
* Module Dependencies.
|
|
*/
|
|
|
|
var DataModel = require('../loopback').DataModel
|
|
, loopback = require('../loopback')
|
|
, assert = require('assert');
|
|
|
|
/**
|
|
* Properties
|
|
*/
|
|
|
|
var properties = {
|
|
id: {type: Number, generated: true, id: true},
|
|
time: {type: Number, generated: true, default: Date.now},
|
|
sourceId: {type: String}
|
|
};
|
|
|
|
/**
|
|
* Options
|
|
*/
|
|
|
|
var options = {
|
|
|
|
};
|
|
|
|
/**
|
|
* Checkpoint list entry.
|
|
*
|
|
* @property id {Number} the sequencial identifier of a checkpoint
|
|
* @property time {Number} the time when the checkpoint was created
|
|
* @property sourceId {String} the source identifier
|
|
*
|
|
* @class
|
|
* @inherits {DataModel}
|
|
*/
|
|
|
|
var Checkpoint = module.exports = DataModel.extend('Checkpoint', properties, options);
|
|
|
|
/**
|
|
* Get the current checkpoint id
|
|
* @callback {Function} callback
|
|
* @param {Error} err
|
|
* @param {Number} checkpointId The current checkpoint id
|
|
*/
|
|
|
|
Checkpoint.current = function(cb) {
|
|
this.find({
|
|
limit: 1,
|
|
sort: 'id DESC'
|
|
}, function(err, checkpoints) {
|
|
if(err) return cb(err);
|
|
var checkpoint = checkpoints[0] || {id: 0};
|
|
cb(null, checkpoint.id);
|
|
});
|
|
}
|
|
|