mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Changed route to user set custom day start
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user