Skip to content
Permalink
Browse files

Implement user settings

  • Loading branch information
vantezzen committed Oct 20, 2019
1 parent 5bf9eb5 commit f09ebd80b32ee1beac2bfc1de358de14f947bdbc
Showing with 26 additions and 0 deletions.
  1. +24 −0 app/Controllers/Http/UserController.js
  2. +1 −0 database/migrations/1503250034279_user.js
  3. +1 −0 start/routes.js
@@ -146,6 +146,30 @@ class UserController {
isSubscriptionOwner: true,
lastname: 'Franz',
locale: 'en-US',
...auth.user.settings || {},
});
}

async updateMe({
request,
response,
auth
}) {
let settings = auth.user.settings || {};
if (typeof settings === 'string') {
settings = JSON.parse(settings);
}

let newSettings = {
...settings,
...request.all(),
}

auth.user.settings = JSON.stringify(newSettings);
await auth.user.save();

return response.send({
status: 'success'
});
}

@@ -9,6 +9,7 @@ class UserSchema extends Schema {
table.string('username', 80).notNullable();
table.string('email', 254).notNullable().unique();
table.string('password', 60).notNullable();
table.json('settings');
table.timestamps();
});
}
@@ -26,6 +26,7 @@ Route.group(() => {

// User info
Route.get('me', 'UserController.me').middleware('auth');
Route.put('me', 'UserController.updateMe').middleware('auth');

// Service info
Route.post('service', 'ServiceController.create').middleware('auth');

0 comments on commit f09ebd8

Please sign in to comment.
You can’t perform that action at this time.