loopback/lib/models/checkpoint.js

58 lines
1.1 KiB
JavaScript
Raw Normal View History

/**
* Module Dependencies.
*/
2014-05-03 04:19:14 +00:00
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
2014-05-03 04:19:14 +00:00
* @inherits {DataModel}
*/
2014-05-03 04:19:14 +00:00
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'
2014-01-28 20:54:41 +00:00
}, function(err, checkpoints) {
if(err) return cb(err);
2014-01-28 20:54:41 +00:00
var checkpoint = checkpoints[0] || {id: 0};
cb(null, checkpoint.id);
});
}