Skip to content

Commit f2061a5

Browse files
authored
feat(GAT-8233): DAR answer add new field (#1553)
1 parent cc03927 commit f2061a5

File tree

5 files changed

+45
-6
lines changed

5 files changed

+45
-6
lines changed

app/Http/Controllers/Api/V1/UserDataAccessApplicationController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,11 +953,13 @@ public function storeAnswers(CreateUserDataAccessApplicationAnswer $request, int
953953
'question_id' => $answer['question_id'],
954954
'application_id' => $id,
955955
])->delete();
956+
956957
DataAccessApplicationAnswer::create([
957958
'question_id' => $answer['question_id'],
958959
'application_id' => $id,
959960
'answer' => $answer['answer'],
960961
'contributor_id' => $jwtUser['id'],
962+
'answer_index' => isset($answer['answer_index']) ? $answer['answer_index'] : null,
961963
]);
962964
}
963965
} else {

app/Http/Traits/DataAccessApplicationHelpers.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public function updateDataAccessApplication(DataAccessApplication $application,
130130
'application_id' => $id,
131131
'answer' => $answer['answer'],
132132
'contributor_id' => $input['applicant_id'],
133+
'answer_index' => isset($answer['answer_index']) ? $answer['answer_index'] : null,
133134
]);
134135
}
135136
}
@@ -162,6 +163,7 @@ public function editDataAccessApplication(DataAccessApplication $application, ar
162163
'application_id' => $id,
163164
'answer' => $answer['answer'],
164165
'contributor_id' => $application->applicant_id,
166+
'answer_index' => isset($answer['answer_index']) ? $answer['answer_index'] : null,
165167
]);
166168
}
167169
}

app/Models/DataAccessApplicationAnswer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DataAccessApplicationAnswer extends Model
2626
'application_id',
2727
'answer',
2828
'contributor_id',
29+
'answer_index',
2930
];
3031

3132
protected $casts = [

app/Models/QuestionBankVersion.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class QuestionBankVersion extends Model
2222
*
2323
* @var string
2424
*/
25-
2625
protected $table = 'question_bank_versions';
2726

2827
public $timestamps = true;
@@ -47,25 +46,33 @@ class QuestionBankVersion extends Model
4746
/**
4847
* The question this version is associated with.
4948
*/
50-
public function question(): belongsTo
49+
public function question(): BelongsTo
5150
{
5251
return $this->belongsTo(QuestionBank::class, 'question_id');
5352
}
5453

5554
/**
56-
* @return belongsToMany<QuestionBankVersion, $this>
55+
* The child versions associated with this version.
56+
*
57+
* @return BelongsToMany<QuestionBankVersion, QuestionBankVersion>
5758
*/
58-
public function childVersions(): belongsToMany
59+
public function childVersions(): BelongsToMany
5960
{
60-
return $this->belongsToMany(
61+
/** @var BelongsToMany<QuestionBankVersion, QuestionBankVersion> $relation */
62+
$relation = $this->belongsToMany(
6163
QuestionBankVersion::class,
6264
'question_bank_version_has_child_version',
6365
'parent_qbv_id',
6466
'child_qbv_id'
6567
)->withPivot('condition');
68+
69+
return $relation;
6670
}
6771

68-
public function parentVersion(): belongsTo
72+
/**
73+
* The parent version associated with this version.
74+
*/
75+
public function parentVersion(): BelongsTo
6976
{
7077
return $this->belongsTo(
7178
QuestionBankVersion::class,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class () extends Migration {
8+
/**
9+
* Run the migrations.
10+
*/
11+
public function up(): void
12+
{
13+
Schema::table('dar_application_answers', function (Blueprint $table) {
14+
$table->integer('answer_index')->nullable();
15+
});
16+
}
17+
18+
/**
19+
* Reverse the migrations.
20+
*/
21+
public function down(): void
22+
{
23+
Schema::table('dar_application_answers', function (Blueprint $table) {
24+
$table->dropColumn('answer_index');
25+
});
26+
}
27+
};

0 commit comments

Comments
 (0)