#feature: some update
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Config;
|
||||
use App\Services\ErpRequestReportService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
@@ -14,6 +15,7 @@ class ConfigController extends Controller
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
$configs = Config::query()
|
||||
->where('key', '!=', ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY)
|
||||
->orderBy('key')
|
||||
->get();
|
||||
|
||||
@@ -28,7 +30,7 @@ class ConfigController extends Controller
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'key' => ['required', 'string', 'max:255', 'unique:configs,key'],
|
||||
'key' => ['required', 'string', 'max:255', 'unique:configs,key', 'not_in:'.ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY],
|
||||
'value' => ['nullable', 'string'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
@@ -49,12 +51,15 @@ class ConfigController extends Controller
|
||||
|
||||
public function update(Request $request, Config $config): JsonResponse
|
||||
{
|
||||
$this->ensureNotProtected($config);
|
||||
|
||||
$data = $request->validate([
|
||||
'key' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('configs', 'key')->ignore($config->id),
|
||||
'not_in:'.ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY,
|
||||
],
|
||||
'value' => ['nullable', 'string'],
|
||||
'description' => ['nullable', 'string', 'max:255'],
|
||||
@@ -76,6 +81,8 @@ class ConfigController extends Controller
|
||||
|
||||
public function destroy(Config $config): JsonResponse
|
||||
{
|
||||
$this->ensureNotProtected($config);
|
||||
|
||||
$config->delete();
|
||||
|
||||
return response()->json([
|
||||
@@ -103,4 +110,13 @@ class ConfigController extends Controller
|
||||
|
||||
return $decoded;
|
||||
}
|
||||
|
||||
private function ensureNotProtected(Config $config): void
|
||||
{
|
||||
if ($config->key === ErpRequestReportService::DINGTALK_TOKEN_CONFIG_KEY) {
|
||||
throw ValidationException::withMessages([
|
||||
'key' => '该配置只能通过 ERP 请求日报设置修改',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user