feat: added function to parse user object
This commit is contained in:
parent
898d89f322
commit
46114a5920
|
@ -8,9 +8,10 @@ abstract class Filter {
|
|||
* Parse the content to another format.
|
||||
*
|
||||
* @param array $content
|
||||
* @param string $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract function parse(array $content): array;
|
||||
abstract function parse(array $content, string $model): array;
|
||||
|
||||
}
|
|
@ -2,13 +2,58 @@
|
|||
|
||||
namespace Appwrite\Utopia\Response\Filter;
|
||||
|
||||
use Appwrite\Database\Validator\Authorization;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Filter;
|
||||
use Exception;
|
||||
use Utopia\Config\Config;
|
||||
|
||||
class V06 extends Filter {
|
||||
|
||||
|
||||
// Convert 0.7 Data format to 0.6 format
|
||||
public function parse(array $content): array {
|
||||
return array();
|
||||
public function parse(array $content, string $model): array {
|
||||
|
||||
$parsedResponse = array();
|
||||
|
||||
switch($model) {
|
||||
case Response::MODEL_PROJECT :
|
||||
$parsedResponse = $this->parseProject($content);
|
||||
break;
|
||||
|
||||
case Response::MODEL_USER :
|
||||
$parsedResponse = $this->parseUser($content);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Exception('Recevied invlaid model : '.$model);
|
||||
}
|
||||
|
||||
return $parsedResponse;
|
||||
}
|
||||
|
||||
private function parseProject(array $content)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private function parseUser(array $content){
|
||||
$parsedContent = [];
|
||||
|
||||
$parsedContent['$id'] = $content['$id'];
|
||||
$parsedContent['registration'] = $content['registration'];
|
||||
$parsedContent['name'] = $content['name'];
|
||||
$parsedContent['email'] = $content['email'];
|
||||
|
||||
foreach (Config::getParam('providers') as $key => $provider) {
|
||||
if (!$provider['enabled']) {
|
||||
continue;
|
||||
}
|
||||
$parsedContent['oauth2'.ucfirst($key)] = '';
|
||||
$parsedContent['oauth2'.ucfirst($key).'AccessToken'] = '';
|
||||
}
|
||||
|
||||
$parsedContent['roles'] = Authorization::getRoles();
|
||||
|
||||
return $parsedContent;
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ class User extends Model
|
|||
])
|
||||
->addRule('status', [
|
||||
'type' => self::TYPE_INTEGER,
|
||||
'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.',
|
||||
'description' => 'User status. 0 for Unactivated, 1 for active and 2 is blocked.',
|
||||
'example' => 0,
|
||||
])
|
||||
->addRule('email', [
|
||||
|
|
Loading…
Reference in a new issue