Updated user prefs endpoints
This commit is contained in:
parent
68ff5a938a
commit
1ce645a209
2 changed files with 5 additions and 20 deletions
|
@ -863,8 +863,10 @@ App::patch('/v1/account/prefs')
|
|||
/** @var Appwrite\Database\Database $projectDB */
|
||||
/** @var Appwrite\Event\Event $audits */
|
||||
|
||||
$old = $user->getAttribute('prefs', new \stdClass);
|
||||
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'prefs' => $prefs,
|
||||
'prefs' => \array_merge($old, $prefs),
|
||||
]));
|
||||
|
||||
if (false === $user) {
|
||||
|
|
|
@ -208,13 +208,6 @@ App::get('/v1/users/:userId/prefs')
|
|||
|
||||
$prefs = $user->getAttribute('prefs', '');
|
||||
|
||||
try {
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
}
|
||||
|
||||
$response->json($prefs);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
|
@ -439,26 +432,16 @@ App::patch('/v1/users/:userId/prefs')
|
|||
throw new Exception('User not found', 404);
|
||||
}
|
||||
|
||||
$old = \json_decode($user->getAttribute('prefs', '{}'), true);
|
||||
$old = ($old) ? $old : [];
|
||||
$old = $user->getAttribute('prefs', new \stdClass);
|
||||
|
||||
$user = $projectDB->updateDocument(\array_merge($user->getArrayCopy(), [
|
||||
'prefs' => \json_encode(\array_merge($old, $prefs)),
|
||||
'prefs' => \array_merge($old, $prefs),
|
||||
]));
|
||||
|
||||
if (false === $user) {
|
||||
throw new Exception('Failed saving user to DB', 500);
|
||||
}
|
||||
|
||||
$prefs = $user->getAttribute('prefs', '');
|
||||
|
||||
try {
|
||||
$prefs = \json_decode($prefs, true);
|
||||
$prefs = ($prefs) ? $prefs : [];
|
||||
} catch (\Exception $error) {
|
||||
throw new Exception('Failed to parse prefs', 500);
|
||||
}
|
||||
|
||||
$response->json($prefs);
|
||||
}, ['response', 'projectDB']);
|
||||
|
||||
|
|
Loading…
Reference in a new issue