tokens: add lastUsedTime
This commit is contained in:
+30
-8
@@ -3,13 +3,14 @@
|
||||
'use strict';
|
||||
|
||||
exports = module.exports = {
|
||||
get: get,
|
||||
getByAccessToken: getByAccessToken,
|
||||
delByAccessToken: delByAccessToken,
|
||||
add: add,
|
||||
del: del,
|
||||
getByIdentifier: getByIdentifier,
|
||||
delExpired: delExpired,
|
||||
get,
|
||||
getByAccessToken,
|
||||
delByAccessToken,
|
||||
add,
|
||||
del,
|
||||
getByIdentifier,
|
||||
delExpired,
|
||||
update,
|
||||
|
||||
_clear: clear
|
||||
};
|
||||
@@ -18,7 +19,7 @@ var assert = require('assert'),
|
||||
BoxError = require('./boxerror.js'),
|
||||
database = require('./database.js');
|
||||
|
||||
var TOKENS_FIELDS = [ 'id', 'accessToken', 'identifier', 'clientId', 'scope', 'expires', 'name' ].join(',');
|
||||
var TOKENS_FIELDS = [ 'id', 'accessToken', 'identifier', 'clientId', 'scope', 'expires', 'name', 'lastUsedTime' ].join(',');
|
||||
|
||||
function getByAccessToken(accessToken, callback) {
|
||||
assert.strictEqual(typeof accessToken, 'string');
|
||||
@@ -79,6 +80,27 @@ function add(token, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function update(id, values, callback) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof values, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
let args = [ ];
|
||||
let fields = [ ];
|
||||
for (let k in values) {
|
||||
fields.push(k + ' = ?');
|
||||
args.push(values[k]);
|
||||
}
|
||||
args.push(id);
|
||||
|
||||
database.query('UPDATE tokens SET ' + fields.join(', ') + ' WHERE id = ?', args, function (error, result) {
|
||||
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
|
||||
if (result.affectedRows !== 1) return callback(new BoxError(BoxError.NOT_FOUND, 'Token not found'));
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
function del(id, callback) {
|
||||
assert.strictEqual(typeof id, 'string');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
Reference in New Issue
Block a user