hiệu chỉnh lôi add test report
This commit is contained in:
		
							parent
							
								
									f68fe91071
								
							
						
					
					
						commit
						d930caf4c0
					
				| 
						 | 
				
			
			@ -220,90 +220,12 @@ class CriteriasController extends Controller
 | 
			
		|||
        return AbstractController::ResultSuccess($responseData);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Update or create multiple SprintCriteria and UserCriteria records
 | 
			
		||||
     *
 | 
			
		||||
     * @param int $sprintId The id of the sprint
 | 
			
		||||
     * @param array $criteriaData An array of criteria data. Each element of the array should be an associative array with the following keys:
 | 
			
		||||
     *     - criteria_id: The id of the criteria
 | 
			
		||||
     *     - point: The point of the criteria
 | 
			
		||||
     *     - expect_result: The expected result of the criteria
 | 
			
		||||
     *     - actual_result: The actual result of the criteria
 | 
			
		||||
     *     - note: The note of the criteria
 | 
			
		||||
     *     - user_id (optional): The id of the user
 | 
			
		||||
     *     - user_point (optional): The point of the user (default is the same as point)
 | 
			
		||||
     *     - user_note (optional): The note of the user (default is the same as note)
 | 
			
		||||
     * @return bool True if successful, false otherwise
 | 
			
		||||
     */
 | 
			
		||||
    public function updateCriteriasForSprint2($sprintId, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $user = auth('admins')->user();
 | 
			
		||||
 | 
			
		||||
        // Tạo hoặc lấy Sprint
 | 
			
		||||
        $sprint = Sprint::firstOrCreate(['id' => $sprintId], [
 | 
			
		||||
            'name' => 'Default Sprint Name',
 | 
			
		||||
            'start_date' => now(),
 | 
			
		||||
            'end_date' => now()->addDays(7),
 | 
			
		||||
            'project_id' => 1,
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $criteriaData = $request->criterias;
 | 
			
		||||
 | 
			
		||||
        foreach ($criteriaData as $data) {
 | 
			
		||||
            // print_r($data);
 | 
			
		||||
            $criteriaId = (int)$data['criteria_id'];
 | 
			
		||||
 | 
			
		||||
            // Kiểm tra xem criteria có tồn tại không
 | 
			
		||||
            $criteria = Criteria::find($criteriaId);
 | 
			
		||||
            if (!$criteria) {
 | 
			
		||||
                // Nếu không tồn tại, có thể ném ra ngoại lệ hoặc trả về lỗi
 | 
			
		||||
                return response()->json(['error' => 'Criteria ID ' . $criteriaId . ' does not exist'], 400);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $point = $data['point'];
 | 
			
		||||
            $expectResult = $data['expect_result'];
 | 
			
		||||
            $actualResult = $data['actual_result'];
 | 
			
		||||
            $note = $data['note'];
 | 
			
		||||
 | 
			
		||||
            // Cập nhật hoặc tạo mới SprintCriteria
 | 
			
		||||
            SprintCriteria::updateOrCreate(
 | 
			
		||||
                ['sprint_id' => $sprint->id, 'criteria_id' => $criteriaId],
 | 
			
		||||
                ['point' => $point, 'expect_result' => $expectResult, 'actual_result' => $actualResult, 'note' => $note]
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
            if (isset($data['users'])) {
 | 
			
		||||
                // Xóa hết các bản ghi UserCriteria theo sprint_id và criteria_id
 | 
			
		||||
                UserCriteria::where('criteria_id', $criteriaId)
 | 
			
		||||
                    ->where('sprint_id', $sprint->id)
 | 
			
		||||
                    ->delete();
 | 
			
		||||
                foreach ($data['users'] as $userData) {
 | 
			
		||||
                    $userId = $userData['user_id'];
 | 
			
		||||
                    $userPoint = $userData['point'] ?? $point;
 | 
			
		||||
                    $userNote = $userData['note'] ?? $note;
 | 
			
		||||
 | 
			
		||||
                    // Chèn lại các bản ghi mới vào bảng UserCriteria
 | 
			
		||||
                    UserCriteria::create([
 | 
			
		||||
                        'user_id' => $userId,
 | 
			
		||||
                        'criteria_id' => (int)$criteriaId,
 | 
			
		||||
                        'sprint_id' => $sprint->id,
 | 
			
		||||
                        'point' => $userPoint,
 | 
			
		||||
                        'note' => $userNote,
 | 
			
		||||
                        'created_by' => $user->name
 | 
			
		||||
                    ]);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return AbstractController::ResultSuccess("");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function updateCriteriasForSprint($sprintId, Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        // Validate dữ liệu đầu vào
 | 
			
		||||
        $validated = $request->validate([
 | 
			
		||||
            'name' => 'required|string',
 | 
			
		||||
            'finalPoint' => 'required|string',
 | 
			
		||||
            'finalPoint' => 'string',
 | 
			
		||||
            'project_id' => 'required|integer',
 | 
			
		||||
            'criterias' => 'required|array',
 | 
			
		||||
            'users' => 'required|array',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,6 +8,7 @@ use App\Traits\HasFilterRequest;
 | 
			
		|||
use App\Traits\HasOrderByRequest;
 | 
			
		||||
use App\Traits\HasSearchRequest;
 | 
			
		||||
use Illuminate\Http\Request;
 | 
			
		||||
use Modules\Admin\app\Models\Sprint;
 | 
			
		||||
use Modules\Admin\app\Models\TestCaseForSprint;
 | 
			
		||||
 | 
			
		||||
class TestCaseForSprintController extends Controller
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +30,7 @@ class TestCaseForSprintController extends Controller
 | 
			
		|||
 | 
			
		||||
        $request->validate([
 | 
			
		||||
            'name' => 'required|string|max:255',
 | 
			
		||||
            'position' => 'required|integer',
 | 
			
		||||
            'position' => 'required|string',
 | 
			
		||||
            'input' => 'required|string',
 | 
			
		||||
            'expect_output' => 'required|string',
 | 
			
		||||
            'actual_output' => 'required|string',
 | 
			
		||||
| 
						 | 
				
			
			@ -38,6 +39,20 @@ class TestCaseForSprintController extends Controller
 | 
			
		|||
            'bug_id_on_jira' => 'nullable|string',
 | 
			
		||||
        ]);
 | 
			
		||||
 | 
			
		||||
        $sprint = Sprint::find($sprintId);
 | 
			
		||||
        if (!$sprint) {
 | 
			
		||||
            // Create new sprint
 | 
			
		||||
            Sprint::create([
 | 
			
		||||
                'id' => $sprintId,
 | 
			
		||||
                'name' => $request->sprint_name,
 | 
			
		||||
                'project_id' => $request->project_id,
 | 
			
		||||
                'point' => "",
 | 
			
		||||
                'start_date' => $request->start_date,
 | 
			
		||||
                'end_date' => $request->end_date,
 | 
			
		||||
                'complete_date' => $request->complete_date,
 | 
			
		||||
            ]);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $testReport = TestCaseForSprint::create([
 | 
			
		||||
            'name' => $request->name,
 | 
			
		||||
            'position' => $request->position,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,6 +19,7 @@ return new class extends Migration
 | 
			
		|||
            $table->string('actual_result');
 | 
			
		||||
            $table->string('note')->nullable();
 | 
			
		||||
            $table->string('created_by');
 | 
			
		||||
            $table->timestamps();
 | 
			
		||||
            
 | 
			
		||||
            $table->foreign('sprint_id')->references('id')->on('sprint')->onDelete('cascade');
 | 
			
		||||
            $table->foreign('criteria_id')->references('id')->on('criterias')->onDelete('cascade');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,6 +23,7 @@ return new class extends Migration
 | 
			
		|||
            $table->string('bug_id_on_jira')->nullable();
 | 
			
		||||
            $table->unsignedBigInteger('sprint_id');
 | 
			
		||||
            $table->string('created_by');
 | 
			
		||||
            $table->timestamps();
 | 
			
		||||
            
 | 
			
		||||
            $table->foreign('sprint_id')->references('id')->on('sprint')->onDelete('cascade');
 | 
			
		||||
        });
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,6 +18,7 @@ return new class extends Migration
 | 
			
		|||
            $table->integer('point');
 | 
			
		||||
            $table->string('note')->nullable();
 | 
			
		||||
            $table->string('created_by');
 | 
			
		||||
            $table->timestamps();
 | 
			
		||||
            
 | 
			
		||||
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
 | 
			
		||||
            $table->foreign('criteria_id')->references('id')->on('criterias')->onDelete('cascade');
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,6 +35,9 @@ type DataProject = {
 | 
			
		|||
type DataSprint = {
 | 
			
		||||
  id: number
 | 
			
		||||
  name: string
 | 
			
		||||
  startDate: string
 | 
			
		||||
  endDate: string
 | 
			
		||||
  completeDate: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DataTestCases = {
 | 
			
		||||
| 
						 | 
				
			
			@ -48,6 +51,11 @@ type DataTestCases = {
 | 
			
		|||
  bug_id_on_jira: string
 | 
			
		||||
  note: string
 | 
			
		||||
  created_by?: string
 | 
			
		||||
  project_id?: string
 | 
			
		||||
  sprint_name?: string
 | 
			
		||||
  start_date?: string
 | 
			
		||||
  end_date?: string
 | 
			
		||||
  complete_date?: string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const TestReport = () => {
 | 
			
		||||
| 
						 | 
				
			
			@ -225,7 +233,15 @@ const TestReport = () => {
 | 
			
		|||
 | 
			
		||||
  const handleCreate = async (values: DataTestCases) => {
 | 
			
		||||
    try {
 | 
			
		||||
      const dataSprintSearch = dataSprint.find(
 | 
			
		||||
        (item: DataSprint) => item.id == Number(filter.sprint),
 | 
			
		||||
      )
 | 
			
		||||
      const { ...data } = values
 | 
			
		||||
      data.sprint_name = dataSprintSearch?.name
 | 
			
		||||
      data.project_id = filter.project
 | 
			
		||||
      data.start_date = dataSprintSearch?.startDate
 | 
			
		||||
      data.end_date = dataSprintSearch?.endDate
 | 
			
		||||
      data.complete_date = dataSprintSearch?.completeDate
 | 
			
		||||
      delete data.id
 | 
			
		||||
 | 
			
		||||
      const res = await post(`${createTestCase}/${filter.sprint}`, data)
 | 
			
		||||
| 
						 | 
				
			
			@ -496,9 +512,9 @@ const TestReport = () => {
 | 
			
		|||
      >
 | 
			
		||||
        <form
 | 
			
		||||
          onSubmit={form.onSubmit(async (values) => {
 | 
			
		||||
            setDisableBtn(true)
 | 
			
		||||
            // setDisableBtn(true)
 | 
			
		||||
            await handleCreate(values)
 | 
			
		||||
            setDisableBtn(false)
 | 
			
		||||
            // setDisableBtn(false)
 | 
			
		||||
          })}
 | 
			
		||||
        >
 | 
			
		||||
          <Box pl={'md'} pr={'md'}>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue