Skip to content

Commit

Permalink
📡 add: some safe null validation in selesai method ujian-controller
Browse files Browse the repository at this point in the history
  • Loading branch information
shellrean committed Mar 15, 2021
1 parent 7792536 commit e7bec9c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/Http/Controllers/Api/v2/UjianController.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ public function selesai()

$ujian = $this->_getUjianCurrent($peserta);

if (!$ujian) {
return SendResponse::badRequest('Anda tidak sedang mengerjakan ujian apapun. silakan logout, laporkan perihal ini kepada administrator');
}

// Cek apakah hasil ujian pernah di generate sebelumnya
$hasilUjian = DB::table('hasil_ujians')
->where([
Expand All @@ -271,6 +275,16 @@ public function selesai()
->count();

if($hasilUjian > 0) {
try {
DB::table('siswa_ujians')
->where('id', $ujian->id)
->update([
'status_ujian' => 1
]);

} catch (\Exception $e) {
return SendResponse::internalServerError('Terjadi kesalahan 500. '.$e->getMessage());
}
return SendResponse::badRequest('Ujian ini telah diselesaikan. silakan logout, laporkan perihal ini kepada andministrator');
}

Expand All @@ -281,6 +295,10 @@ public function selesai()
])
->select('banksoal_id')
->first();

if (!$jawaban) {
return SendResponse::badRequest('Anda tidak sedang mengerjakan ujian apapun. silakan logout, laporkan perihal ini kepada administrator');
}

try {
DB::beginTransaction();
Expand Down

0 comments on commit e7bec9c

Please sign in to comment.