Skip to content

Commit

Permalink
customer image path url
Browse files Browse the repository at this point in the history
  • Loading branch information
indpurvesh committed Dec 20, 2022
1 parent 881f7e2 commit ed3152d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/avored.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@

'types' => [
'Token' => TokenType::class,
\Rebing\GraphQL\Support\UploadType::class,
'Category' => CategoryType::class,
'Product' => ProductType::class,
'Customer' => CustomerType::class,
Expand Down
12 changes: 10 additions & 2 deletions src/Database/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function getFullNameAttribute()
*/
public function getImagePathUrlAttribute()
{
if ($this->attributes['image_path'] === null) {
if ($this->imagePath === null) {
return 'https://placehold.it/250x250';
}
return asset('storage/'.$this->attributes['image_path']);
return asset('storage/'. $this->imagePath->path);
}

/**
Expand Down Expand Up @@ -150,4 +150,12 @@ public function orderComments()
{
// <!-- return $this->morphMany(OrderComment::class, 'commentable'); -->
}

/**
* Get the staff profile image.
*/
public function imagePath()
{
return $this->morphOne(Document::class, 'documentable');
}
}
11 changes: 11 additions & 0 deletions src/Graphql/Mutations/Customer/CustomerUpdateMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AvoRed\Framework\Database\Contracts\CustomerModelInterface;
use AvoRed\Framework\Database\Models\Customer;
use AvoRed\Framework\Document\Document;
use AvoRed\Framework\Graphql\Traits\AuthorizedTrait;
use Closure;
use GraphQL\Type\Definition\ResolveInfo;
Expand Down Expand Up @@ -53,13 +54,23 @@ public function args(): array
'name' => 'last_name',
'type' => Type::nonNull(Type::string())
],
'profile_image' => [
'name' => 'profile_image',
'type' => GraphQL::type('Upload'),
],
];
}

public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
{
/** @var \Avored\Framework\Database\Models\Customer $customer */
$customer = Auth::guard('customer')->user();


if (isset($args['profile_image'])) {
$document = Document::uploadPublicly($args['profile_image']);
$customer->imagePath()->updateOrCreate(optional($customer->imagePath)->toArray() ?? [], $document);
}

$customer->update($args);

Expand Down
2 changes: 2 additions & 0 deletions src/Graphql/Queries/CustomerQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closur
return $this->customerRepository->find($args['id']);
}

dd(Auth::guard('customer')->user()->image_path_url);

return $this->customerRepository->find(Auth::guard('customer')->user()->id);
}
}
4 changes: 4 additions & 0 deletions src/Graphql/Types/CustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function fields(): array
'type' => Type::string(),
'description' => 'The customer for the image path'
],
'image_path_url' => [
'type' => Type::string(),
'description' => 'The customer for the image path url'
],
'id' => [
'type' => Type::string(),
'description' => 'The customer for the id'
Expand Down

0 comments on commit ed3152d

Please sign in to comment.