1
0
Fork 0
mirror of synced 2024-06-28 11:10:46 +12:00

Updated user prefs endpoints

This commit is contained in:
Eldad Fux 2020-08-06 14:18:53 +03:00
parent 68ff5a938a
commit 1ce645a209
2 changed files with 5 additions and 20 deletions

View file

@ -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) {

View file

@ -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']);