mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Added new route for setting last cron and updated front end
This commit is contained in:
@@ -17,6 +17,7 @@ describe('Settings Controller', function () {
|
||||
releasePets: sandbox.stub(),
|
||||
releaseMounts: sandbox.stub(),
|
||||
releaseBoth: sandbox.stub(),
|
||||
setLastCron: sandbox.stub(),
|
||||
user: user
|
||||
};
|
||||
|
||||
@@ -97,8 +98,8 @@ describe('Settings Controller', function () {
|
||||
expect(User.set).to.be.calledOnce;
|
||||
expect(User.set).to.be.calledWith({
|
||||
'preferences.dayStart': 5,
|
||||
'lastCron': expectedTime
|
||||
});
|
||||
expect(User.setLastCron).to.be.calledWith(expectedTime);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -77,10 +77,8 @@ habitrpg.controller('SettingsCtrl',
|
||||
};
|
||||
|
||||
$scope.saveDayStart = function() {
|
||||
User.set({
|
||||
'preferences.dayStart': Math.floor($scope.dayStart),
|
||||
'lastCron': +new Date
|
||||
});
|
||||
User.set({'preferences.dayStart': Math.floor($scope.dayStart)});
|
||||
User.setLastCron(+new Date);
|
||||
};
|
||||
|
||||
$scope.language = window.env.language;
|
||||
|
||||
@@ -310,6 +310,19 @@ angular.module('habitrpg')
|
||||
});
|
||||
},
|
||||
|
||||
setLastCron: function (date) {
|
||||
$http({
|
||||
method: "POST",
|
||||
url: 'api/v3/user/set-cron',
|
||||
data: {
|
||||
lastCron: date
|
||||
}
|
||||
})
|
||||
.then(function (response) {
|
||||
Notification.text('Last cron updated. Remember to refresh');
|
||||
});
|
||||
},
|
||||
|
||||
makeAdmin: function () {
|
||||
$http({
|
||||
method: "POST",
|
||||
|
||||
@@ -1310,4 +1310,28 @@ api.userReset = {
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* @api {post} /api/v3/user/set-cron Sets lastCron for user
|
||||
* @apiVersion 3.0.0
|
||||
* @apiName UserSetCron
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiSuccess {Object} data An empty Object
|
||||
*/
|
||||
api.userSetCron = {
|
||||
method: 'POST',
|
||||
middlewares: [authWithHeaders()],
|
||||
url: '/user/set-cron',
|
||||
async handler (req, res) {
|
||||
let user = res.locals.user;
|
||||
let cron = req.body.lastCron;
|
||||
|
||||
user.lastCron = cron;
|
||||
|
||||
await user.save();
|
||||
|
||||
res.respond(200, {});
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = api;
|
||||
|
||||
Reference in New Issue
Block a user