mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Fixes for company purging
This commit is contained in:
parent
aa7ebcee3e
commit
fd38a964e7
@ -497,80 +497,5 @@ class CompanyController extends BaseController
|
||||
|
||||
return response()->json(['message' => 'success'], 200);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Purge Company
|
||||
*
|
||||
* @OA\Post(
|
||||
* path="/api/v1/companies/purge/{company}",
|
||||
* operationId="postCompanyPurge",
|
||||
* tags={"companies"},
|
||||
* summary="Attempts to purge a company record and all its child records",
|
||||
* description="Attempts to purge a company record and all its child records",
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Secret"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Api-Token"),
|
||||
* @OA\Parameter(ref="#/components/parameters/X-Requested-With"),
|
||||
* @OA\Parameter(
|
||||
* name="company",
|
||||
* in="path",
|
||||
* description="The Company Hashed ID",
|
||||
* example="D2J234DFA",
|
||||
* required=true,
|
||||
* @OA\Schema(
|
||||
* type="string",
|
||||
* format="string",
|
||||
* ),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=200,
|
||||
* description="Returns a refresh object",
|
||||
* @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"),
|
||||
* @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"),
|
||||
* @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"),
|
||||
* @OA\JsonContent(ref="#/components/schemas/CompanyUser"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response=422,
|
||||
* description="Validation error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/ValidationError"),
|
||||
* ),
|
||||
* @OA\Response(
|
||||
* response="default",
|
||||
* description="Unexpected Error",
|
||||
* @OA\JsonContent(ref="#/components/schemas/Error"),
|
||||
* ),
|
||||
* )
|
||||
*/
|
||||
public function purgeCompany(Company $company)
|
||||
{
|
||||
$account = $company->account;
|
||||
$company_id = $company->id;
|
||||
|
||||
$company->delete();
|
||||
|
||||
/*Set New Company*/
|
||||
if($account->companies->count() >= 1)
|
||||
auth()->user()->setCompany($account->companies->first());
|
||||
|
||||
/*Update the new default company if necessary*/
|
||||
if($company_id == $account->default_company_id){
|
||||
|
||||
$new_default_company = $account->companies->first();
|
||||
|
||||
if($new_default_company){
|
||||
$account->default_company_id = $new_default_company->id;
|
||||
$account->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*Prep response*/
|
||||
$this->entity_type = CompanyUser::class;
|
||||
$this->entity_transformer = CompanyUserTransformer::class;
|
||||
|
||||
$company_user = $account->company_users->where('user_id', auth()->user()->id);
|
||||
|
||||
return $this->refreshResponse($company_user);
|
||||
}
|
||||
}
|
||||
|
@ -78,8 +78,24 @@ class MigrationController extends BaseController
|
||||
public function purgeCompany(Company $company)
|
||||
{
|
||||
|
||||
$account = $company->account;
|
||||
$company_id = $company->id;
|
||||
|
||||
$company->delete();
|
||||
|
||||
/*Update the new default company if necessary*/
|
||||
if($company_id == $account->default_company_id && $account->companies->count() >= 1)
|
||||
{
|
||||
|
||||
$new_default_company = $account->companies->first();
|
||||
|
||||
if($new_default_company){
|
||||
$account->default_company_id = $new_default_company->id;
|
||||
$account->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return response()->json(['message' => 'Company purged'], 200);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user