diff --git a/app/GraphQL/Inventory/Mutations/Regions/Region.php b/app/GraphQL/Inventory/Mutations/Regions/Region.php index c494d3389..4b53b2ac8 100644 --- a/app/GraphQL/Inventory/Mutations/Regions/Region.php +++ b/app/GraphQL/Inventory/Mutations/Regions/Region.php @@ -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 @@ -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; } } diff --git a/graphql/schemas/Ecosystem/city.graphql b/graphql/schemas/Ecosystem/city.graphql index ad70d5f77..86759e8fd 100644 --- a/graphql/schemas/Ecosystem/city.graphql +++ b/graphql/schemas/Ecosystem/city.graphql @@ -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! diff --git a/graphql/schemas/Ecosystem/country.graphql b/graphql/schemas/Ecosystem/country.graphql index eb27acac8..92533c3c3 100644 --- a/graphql/schemas/Ecosystem/country.graphql +++ b/graphql/schemas/Ecosystem/country.graphql @@ -57,7 +57,7 @@ input CreateCityInput { longitude: Float } -extend type Mutation { +extend type Mutation @guardByAppKey { createCountry( name: String! code: String! diff --git a/graphql/schemas/Ecosystem/currency.graphql b/graphql/schemas/Ecosystem/currency.graphql new file mode 100644 index 000000000..e02014bb5 --- /dev/null +++ b/graphql/schemas/Ecosystem/currency.graphql @@ -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") +} diff --git a/graphql/schemas/Ecosystem/states.graphql b/graphql/schemas/Ecosystem/states.graphql index b695ac2ed..f89544437 100644 --- a/graphql/schemas/Ecosystem/states.graphql +++ b/graphql/schemas/Ecosystem/states.graphql @@ -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( diff --git a/graphql/schemas/Inventory/region.graphql b/graphql/schemas/Inventory/region.graphql index 4bb140f0a..73a68650f 100644 --- a/graphql/schemas/Inventory/region.graphql +++ b/graphql/schemas/Inventory/region.graphql @@ -3,7 +3,7 @@ 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! @@ -11,14 +11,12 @@ type Region { 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! diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php index fb6fc1411..7b665367c 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php @@ -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; @@ -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(); diff --git a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php index 9ba57b195..9e84a98d3 100644 --- a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php +++ b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php @@ -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; @@ -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! @@ -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, @@ -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! @@ -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); }