Changed route to user set custom day start

This commit is contained in:
Keith Holliday
2016-05-19 21:14:35 +01:00
parent e8b53d6b22
commit 5b7a56d28d
4 changed files with 30 additions and 12 deletions

View File

@@ -0,0 +1,19 @@
import {
generateUser,
} from '../../../../helpers/api-integration/v3';
let user;
let endpoint = '/user/set-custom-day-start';
describe('POST /user/set-custom-day-start', () => {
beforeEach(async () => {
user = await generateUser();
});
it('update user.preferences.dayStart', async () => {
expect(user.preferences.dayStart).to.eql(0);
await user.post(endpoint, { dayStart: 1 });
await user.sync();
expect(user.preferences.dayStart).to.eql(1);
});
});

View File

@@ -77,8 +77,7 @@ habitrpg.controller('SettingsCtrl',
};
$scope.saveDayStart = function() {
User.set({'preferences.dayStart': Math.floor($scope.dayStart)});
User.setLastCron(+new Date);
User.setCustomDayStart(Math.floor($scope.dayStart));
};
$scope.language = window.env.language;

View File

@@ -310,16 +310,16 @@ angular.module('habitrpg')
});
},
setLastCron: function (date) {
setCustomDayStart: function (dayStart) {
$http({
method: "POST",
url: 'api/v3/user/set-cron',
url: 'api/v3/user/set-custom-day-start',
data: {
lastCron: date
dayStart: dayStart
}
})
.then(function (response) {
Notification.text('Last cron updated. Remember to refresh');
Notification.text('Day start updated. Remember to refresh');
});
},

View File

@@ -1311,22 +1311,22 @@ api.userReset = {
};
/**
* @api {post} /api/v3/user/set-cron Sets lastCron for user
* @api {post} /api/v3/user/set-custom-day-start Sets preferences.dayStart for user
* @apiVersion 3.0.0
* @apiName UserSetCron
* @apiName UserSetCustomDayStart
* @apiGroup User
*
* @apiSuccess {Object} data An empty Object
*/
api.userSetCron = {
api.userSetCustomDayStart = {
method: 'POST',
middlewares: [authWithHeaders()],
url: '/user/set-cron',
url: '/user/set-custom-day-start',
async handler (req, res) {
let user = res.locals.user;
let cron = req.body.lastCron;
let dayStart = req.body.dayStart;
user.lastCron = cron;
user.preferences.dayStart = dayStart;
await user.save();