Skip to content

Commit

Permalink
Merge pull request #987 from bakaphp/hotfix-region-crud
Browse files Browse the repository at this point in the history
Merge pull request #960 from bakaphp/development
  • Loading branch information
kaioken authored Feb 27, 2024
2 parents a34b987 + 973d2c7 commit db33413
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 26 deletions.
21 changes: 9 additions & 12 deletions app/GraphQL/Inventory/Mutations/Regions/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ class Region
/**
* create.
*
* @param mixed $root
* @param array $request
*
* @return Regions
*/
public function create(mixed $root, array $request): RegionModel
{
$request = $request['input'];
$currency = Currencies::findOrFail($request['currency_id']);
$user = auth()->user();
if (! $user->isAppOwner()) {
unset($request['companies_id']);
}

$regionDto = RegionDto::viaRequest($request);
return (new CreateRegionAction($regionDto, auth()->user()))->execute();

return (new CreateRegionAction($regionDto, $user))->execute();
}

/**
* update.
*
* @param mixed $root
* @param array $request
*
* @return Regions
*/
public function update(mixed $root, array $request): RegionModel
Expand All @@ -42,22 +42,19 @@ public function update(mixed $root, array $request): RegionModel
$request = $request['input'];
$region = RegionRepository::getById($id, auth()->user()->getCurrentCompany());
$region->update($request);

return $region;
}

/**
* delete.
*
* @param mixed $root
* @param array $request
*
* @return bool
*/
public function delete(mixed $root, array $request): bool
{
$id = $request['id'];
$region = RegionRepository::getById($id, auth()->user()->getCurrentCompany());
$region->delete();

return true;
}
}
2 changes: 1 addition & 1 deletion graphql/schemas/Ecosystem/city.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extend type Query {
city(id: Int!): Cities @find(model: "Kanvas\\Locations\\Models\\Cities")
}

extend type Mutation {
extend type Mutation @guardByAppKey {
createCities(
name: String!
latitude: Float!
Expand Down
2 changes: 1 addition & 1 deletion graphql/schemas/Ecosystem/country.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ input CreateCityInput {
longitude: Float
}

extend type Mutation {
extend type Mutation @guardByAppKey {
createCountry(
name: String!
code: String!
Expand Down
21 changes: 21 additions & 0 deletions graphql/schemas/Ecosystem/currency.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
type Currency {
id: Int!
code: String!
currency: String!
}

extend type Query @guard {
currencies(
orderBy: _ @orderBy(columns: ["id", "country", "currency", "code"])
where: _
@whereConditions(
columns: [
"country"
"currency"
"code"
"id"
]
)
): [Currency!]!
@paginate(defaultCount: 25, model: "Kanvas\\Currencies\\Models\\Currencies")
}
2 changes: 1 addition & 1 deletion graphql/schemas/Ecosystem/states.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extend type Query {
state(id: Int!): States @find(model: "\\Kanvas\\Locations\\Models\\States")
}

extend type Mutation {
extend type Mutation @guardByAppKey {
createState(countries_id: Int!, name: String!, code: String!): States
@create(model: "\\Kanvas\\Locations\\Models\\States")
updateState(
Expand Down
8 changes: 3 additions & 5 deletions graphql/schemas/Inventory/region.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ type Region {
companies_id: Int!
currency_id: Int!
companies: Company! @belongsTo(relation: "company")
currencies: Currency!
currencies: Currency! @belongsTo(relation: "currencies")
uuid: String!
name: String!
slug: String!
short_slug: String!
settings: String
is_default: Boolean!
}
type Currency {
id: Int!
name: String!
}

input RegionInput {
currency_id: Int!
name: String!
slug: String
companies_id: Int
short_slug: String!
settings: String
is_default: Int!
Expand Down
11 changes: 9 additions & 2 deletions src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,17 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User
}

$sponsorsPage = $company->get('sponsors_page') ?? [];
$sponsorsPageLandingPages = $company->get('sponsors_page_landing') ?? [];
$agentPage = $user->get('agent_website');
$agentPageUserId = $sponsorsPage[$agentPage] ?? null;
$agentPageLandingPage = $sponsorsPageLandingPages[$agentPage] ?? null;

if ($agentPageLandingPage !== null) {
$user->set('landing_page', $agentPageLandingPage);
}

//@todo this is ugly , testing it out
if ($agentPageUserId) {
if ($agentPageUserId !== null) {
try {
$agentOwner = Agent::fromCompany($company)->where('users_id', $agentPageUserId)->firstOrFail();
$ownerMemberNumber = $agentOwner->member_id;
Expand All @@ -129,7 +136,7 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User
}
}

if ($companyDefaultUseRotation && $ownerMemberNumber === null) {
if ($companyDefaultUseRotation !== false && $ownerMemberNumber === null) {
try {
$rotation = LeadRotation::getByIdFromCompany($companyDefaultUseRotation, $company);
$agentUser = $rotation->getAgent();
Expand Down
30 changes: 26 additions & 4 deletions tests/GraphQL/Ecosystem/CountriesGraphqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Tests\GraphQL\Ecosystem;

use Kanvas\AccessControlList\Enums\RolesEnums;
use Kanvas\Apps\Models\Apps;
use Kanvas\Enums\AppEnums;
use Kanvas\Locations\Models\Countries;
use Kanvas\Locations\Models\States;
use Tests\TestCase;
Expand All @@ -18,6 +21,9 @@ public function testCreate(): void
$name = fake()->name;
$stateName = fake()->name;
$cityName = fake()->name;
$app = app(Apps::class);
$app->keys()->first()->user()->firstOrFail()->assign(RolesEnums::OWNER->value);

$response = $this->graphQL(/** @lang GraphQL */ '
mutation(
$name: String!
Expand All @@ -44,11 +50,17 @@ public function testCreate(): void
flag
}
}
', [
',
[
'name' => $name,
'stateName' => $stateName,
'cityName' => $cityName,
])->assertJson([
],
[],
[
AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id,
]
)->assertJson([
'data' => [
'createCountry' => [
'name' => $name,
Expand Down Expand Up @@ -97,6 +109,10 @@ public function testUpdate(): void
{
$country = Countries::orderBy('id', 'desc')->first();
$name = fake()->name;
$app = app(Apps::class);
$app->keys()->first()->user()->firstOrFail()->assign(RolesEnums::OWNER->value);


$response = $this->graphQL(/** @lang GraphQL */ '
mutation(
$id: ID!
Expand All @@ -114,12 +130,18 @@ public function testUpdate(): void
name
}
}
', [
',
[
'id' => $country->id,
'name' => $name,
'code' => $country->code,
'flag' => $country->flag,
]);
],
[],
[
AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id,
]
);
$this->assertArrayHasKey('data', $response);
}

Expand Down

0 comments on commit db33413

Please sign in to comment.