diff --git a/app/Http/Controllers/HostedMigrationController.php b/app/Http/Controllers/HostedMigrationController.php index 5d5e0cc18a..78f007b042 100644 --- a/app/Http/Controllers/HostedMigrationController.php +++ b/app/Http/Controllers/HostedMigrationController.php @@ -19,6 +19,35 @@ use Illuminate\Http\Request; class HostedMigrationController extends Controller { + public function checkStatus(Request $request) + { + + if ($request->header('X-API-HOSTED-SECRET') != config('ninja.ninja_hosted_secret')) { + return; + } + + MultiDB::findAndSetDbByCompanyKey($request->company_key); + $c = Company::where('company_key', $request->company_key)->first(); + + if(!$c || $c->is_disabled) + return response()->json(['message' => 'ok'], 200); + + if(\App\Models\Invoice::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))->first()) + return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); + + if(\App\Models\Client::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))->first()) + return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); + + if(\App\Models\Quote::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) + return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); + + if(\App\Models\RecurringInvoice::query()->where('company_id', $c->id)->where('created_at', '>', now()->subMonths(2))) + return response()->json(['message' => 'New data exists, are you sure? Please log in here https://app.invoicing.co and delete the company if you really need to migrate again.'], 400); + + return response()->json(['message' => 'ok'], 200); + + } + public function getAccount(Request $request) { if ($request->header('X-API-HOSTED-SECRET') != config('ninja.ninja_hosted_secret')) { diff --git a/routes/api.php b/routes/api.php index 487c82e83b..eb5e8963d8 100644 --- a/routes/api.php +++ b/routes/api.php @@ -422,6 +422,7 @@ Route::get('token_hash_router', [OneTimeTokenController::class, 'router'])->midd Route::get('webcron', [WebCronController::class, 'index'])->middleware('throttle:100,1'); Route::post('api/v1/get_migration_account', [HostedMigrationController::class, 'getAccount'])->middleware('guest')->middleware('throttle:100,1'); Route::post('api/v1/confirm_forwarding', [HostedMigrationController::class, 'confirmForwarding'])->middleware('guest')->middleware('throttle:100,1'); +Route::post('api/v1/check_status', [HostedMigrationController::class, 'checkStatus'])->middleware('guest')->middleware('throttle:100,1'); Route::post('api/v1/process_webhook', [AppleController::class, 'process_webhook'])->middleware('throttle:1000,1'); Route::post('api/v1/confirm_purchase', [AppleController::class, 'confirm_purchase'])->middleware('throttle:1000,1');