Skip to content

Commit

Permalink
Merge pull request #955 from bakaphp/development
Browse files Browse the repository at this point in the history
Release 1.21
  • Loading branch information
kaioken authored Feb 19, 2024
2 parents 3530561 + 6917205 commit 4e08472
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Support\Facades\Auth;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Actions\CreateCompaniesAction;
use Kanvas\Companies\Actions\DeleteCompaniesAction;
use Kanvas\Companies\Actions\UpdateCompaniesAction;
use Kanvas\Companies\DataTransferObject\CompaniesPostData;
use Kanvas\Companies\DataTransferObject\CompaniesPutData;
Expand Down Expand Up @@ -51,9 +50,10 @@ public function updateCompany(mixed $root, array $request): Companies
$request['input']['users_id'] = $user->getKey();
} else {
$request['input']['users_id'] = Auth::user()->getKey();
$user = Auth::user();
}
$dto = CompaniesPutData::fromArray($request['input']);
$action = new UpdateCompaniesAction(Auth::user(), $dto);
$action = new UpdateCompaniesAction($user, $dto);

return $action->execute((int) $request['id']);
}
Expand All @@ -66,7 +66,7 @@ public function deleteCompany(mixed $root, array $request): bool
/**
* @todo only super admin can do this
*/
DeleteCompanyJob::dispatch((int) $request['id'], Auth::user());
DeleteCompanyJob::dispatch((int) $request['id'], Auth::user(), app(Apps::class));

return true;
}
Expand Down
67 changes: 34 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions graphql/schemas/Ecosystem/user.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ input RegisterInput {
password: String! @rules(apply: ["required", "min:8"])
password_confirmation: String! @rules(apply: ["required"])
company_name: String
phone_number: String
custom_fields: [CustomFieldEntityInput!]
}

Expand Down
2 changes: 1 addition & 1 deletion graphql/schemas/Inventory/region.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ type Region {
id: Int!
companies_id: Int!
currency_id: Int!
companies: Company!
companies: Company! @belongsTo(relation: "company")
currencies: Currency!
uuid: String!
name: String!
Expand Down
7 changes: 4 additions & 3 deletions graphql/schemas/Inventory/warehouse.graphql
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
type Warehouse {
id: Int!
companies: Company!
apps: App!
regions: Region!
apps_id: Int!
regions_id: Int!
companies_id: Int!
company: Company!
uuid: String!
name: String!
location: String
is_default: Boolean!
is_published: Boolean!
total_products: Int!
@method(name: "getTotalProducts")
}

input WarehouseInput {
Expand Down Expand Up @@ -65,7 +66,7 @@ extend type Query @guard {
getWarehouses(
where: _
@whereConditions(
columns: ["name", "location", "is_default", "is_published"]
columns: ["id", "name", "location", "is_default", "is_published"]
)
): [Warehouse]!
@paginate(
Expand Down
35 changes: 21 additions & 14 deletions src/Domains/Inventory/Warehouses/Models/Warehouses.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Baka\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Models\Companies;
use Kanvas\Inventory\Models\BaseModel;
use Kanvas\Inventory\Regions\Models\Regions;
use Kanvas\Inventory\Traits\DefaultTrait;
use Kanvas\Inventory\Variants\Models\VariantsWarehouses;

/**
* Class Warehouses.
Expand Down Expand Up @@ -39,30 +41,21 @@ class Warehouses extends BaseModel

protected $guarded = [];

/**
* Get the companies that owns the Warehouses.
*/
public function companies(): BelongsTo
{
return $this->belongsTo(Companies::class, 'companies_id');
}

/**
*
*/
public function apps(): BelongsTo
{
return $this->belongsTo(Apps::class, 'apps_id');
}

/**
*
*/
public function regions(): BelongsTo
{
return $this->belongsTo(Regions::class, 'regions_id');
}

public function variantsWarehouses(): HasMany
{
return $this->hasMany(VariantsWarehouses::class, 'warehouses_id');
}

/**
* quantityAttribute.
*/
Expand Down Expand Up @@ -172,4 +165,18 @@ public function isVariantPublished(): ?Attribute
get: fn () => $this->pivot->is_published
);
}

/**
* Get the total amount of products of a warehouse.
*
* @return Int
*/
public function getTotalProducts(): int
{
if (! $totalProducts = $this->get('total_products')) {
$this->set('total_products', $this->variantsWarehouses()->count());
return $this->get('total_products');
}
return $totalProducts;
}
}
2 changes: 1 addition & 1 deletion src/Domains/Social/Channels/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Channel extends BaseModel

public function users(): BelongsToMany
{
$databaseSocial = config('database.social.database', 'social');
$databaseSocial = config('database.connections.social.database', 'social');

return $this->belongsToMany(Users::class, $databaseSocial . '.channel_users', 'channel_id', 'users_id')
->withTimestamps()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static function getById(int $id, Users $user): Channel

public static function getByIdBuilder(Users $user): Builder
{
$databaseSocial = config('database.social.database', 'social');
$databaseSocial = config('database.connections.social.database', 'social');
$builder = Channel::join($databaseSocial . '.channel_users', 'channel_users.channel_id', '=', 'channels.id')
->where('users_id', auth()->user()->id);

Expand Down
Loading

0 comments on commit 4e08472

Please sign in to comment.