You've already forked isop-mirror
Merge branch 'feature/80-Odstránenie-účtu-používateľa-garantom-' into develop
This commit is contained in:
@@ -26,7 +26,7 @@ class RegisteredUserController extends Controller
|
|||||||
$password = bin2hex(random_bytes(16));
|
$password = bin2hex(random_bytes(16));
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
|
||||||
'first_name' => ['required', 'string', 'max:64'],
|
'first_name' => ['required', 'string', 'max:64'],
|
||||||
'last_name' => ['required', 'string', 'max:64'],
|
'last_name' => ['required', 'string', 'max:64'],
|
||||||
'phone' => ['required', 'string', 'max:13'],
|
'phone' => ['required', 'string', 'max:13'],
|
||||||
@@ -56,14 +56,14 @@ class RegisteredUserController extends Controller
|
|||||||
'password' => Hash::make($password),
|
'password' => Hash::make($password),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if($user->role === "STUDENT") {
|
if ($user->role === "STUDENT") {
|
||||||
StudentData::create([
|
StudentData::create([
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'address' => $request->student_data['address'],
|
'address' => $request->student_data['address'],
|
||||||
'personal_email' => $request->student_data['personal_email'],
|
'personal_email' => $request->student_data['personal_email'],
|
||||||
'study_field' => $request->student_data['study_field'],
|
'study_field' => $request->student_data['study_field'],
|
||||||
]);
|
]);
|
||||||
} else if($user->role === "EMPLOYER") {
|
} else if ($user->role === "EMPLOYER") {
|
||||||
Company::create([
|
Company::create([
|
||||||
'name' => $request->company_data['name'],
|
'name' => $request->company_data['name'],
|
||||||
'address' => $request->company_data['address'],
|
'address' => $request->company_data['address'],
|
||||||
@@ -79,7 +79,8 @@ class RegisteredUserController extends Controller
|
|||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function reset_password(Request $request): Response {
|
public function reset_password(Request $request): Response
|
||||||
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'email' => ['required', 'string', 'lowercase', 'email', 'max:255'],
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255'],
|
||||||
]);
|
]);
|
||||||
@@ -97,4 +98,22 @@ class RegisteredUserController extends Controller
|
|||||||
|
|
||||||
return response()->noContent();
|
return response()->noContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function reset_password_2(Request $request): Response
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'id' => ['required', 'string', 'lowercase', 'email', 'max:255'],
|
||||||
|
'password' => ['required', 'string', 'lowercase', 'email', 'max:255'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$user = User::whereEmail($request->email)->first();
|
||||||
|
if (!$user) {
|
||||||
|
return response(status: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user->password = Hash::make($request->password);
|
||||||
|
$user->save();
|
||||||
|
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,10 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Internship;
|
||||||
|
use App\Models\InternshipStatus;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class CompanyController extends Controller
|
class CompanyController extends Controller
|
||||||
{
|
{
|
||||||
@@ -155,4 +158,48 @@ class CompanyController extends Controller
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a company, its contact person and all related data.
|
||||||
|
*/
|
||||||
|
public function delete(int $id)
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
// Admin kontrola
|
||||||
|
if ($user->role !== 'ADMIN') {
|
||||||
|
abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
$company = Company::find($id);
|
||||||
|
$company_contact = User::find($company->contact);
|
||||||
|
|
||||||
|
if (!$company) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'No such company exists.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$internships = Internship::whereCompanyId($company->id);
|
||||||
|
|
||||||
|
// mazanie statusov
|
||||||
|
$internships->each(function ($internship) {
|
||||||
|
InternshipStatus::whereInternshipId($internship->id)->delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
// mazanie praxov
|
||||||
|
$internships->delete();
|
||||||
|
|
||||||
|
// mazanie firmy
|
||||||
|
Company::whereContact($company_contact->id);
|
||||||
|
|
||||||
|
// mazanie účtu firmy
|
||||||
|
$company_contact->delete();
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Internship;
|
||||||
use App\Models\StudentData;
|
use App\Models\StudentData;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\InternshipStatus;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class StudentDataController extends Controller
|
class StudentDataController extends Controller
|
||||||
{
|
{
|
||||||
@@ -171,4 +174,54 @@ class StudentDataController extends Controller
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a student and all related data.
|
||||||
|
*/
|
||||||
|
public function delete(int $id)
|
||||||
|
{
|
||||||
|
$user = auth()->user();
|
||||||
|
|
||||||
|
// Admin kontrola
|
||||||
|
if ($user->role !== 'ADMIN') {
|
||||||
|
abort(403, 'Unauthorized');
|
||||||
|
}
|
||||||
|
|
||||||
|
$student = User::find($id);
|
||||||
|
|
||||||
|
if (!$student) {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'No such student exists.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($student->role !== 'STUDENT') {
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'User is not a student.'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
// mazanie praxov
|
||||||
|
$internships = Internship::whereUserId($student->id);
|
||||||
|
|
||||||
|
// mazanie statusov
|
||||||
|
$internships->each(function ($internship) {
|
||||||
|
InternshipStatus::whereInternshipId($internship->id)->delete();
|
||||||
|
});
|
||||||
|
|
||||||
|
// mazanie praxov
|
||||||
|
$internships->delete();
|
||||||
|
|
||||||
|
// mazanie firmy
|
||||||
|
StudentData::whereUserId($student->id);
|
||||||
|
|
||||||
|
// mazanie účtu firmy
|
||||||
|
$student->delete();
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
|
||||||
|
return response()->noContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,20 @@ class Company extends Model
|
|||||||
'contact',
|
'contact',
|
||||||
'hiring'
|
'hiring'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the internships for the company.
|
||||||
|
*/
|
||||||
|
public function internships()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Internship::class, 'company_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the contact person (user) for the company.
|
||||||
|
*/
|
||||||
|
public function contactPerson()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'contact');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,4 +57,12 @@ class User extends Authenticatable
|
|||||||
{
|
{
|
||||||
return $this->hasOne(StudentData::class, 'user_id');
|
return $this->hasOne(StudentData::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the internships for the user.
|
||||||
|
*/
|
||||||
|
public function internships()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Internship::class, 'user_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ Route::middleware(['auth:sanctum'])->prefix('/students')->group(function () {
|
|||||||
Route::get('/', [StudentDataController::class, 'all']);
|
Route::get('/', [StudentDataController::class, 'all']);
|
||||||
Route::get('/{id}', [StudentDataController::class, 'get']);
|
Route::get('/{id}', [StudentDataController::class, 'get']);
|
||||||
Route::post('/{id}', [StudentDataController::class, 'update_all']);
|
Route::post('/{id}', [StudentDataController::class, 'update_all']);
|
||||||
|
Route::delete('/{id}', [StudentDataController::class, 'delete']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::post('/password-reset', [RegisteredUserController::class, 'reset_password'])
|
Route::post('/password-reset', [RegisteredUserController::class, 'reset_password'])
|
||||||
@@ -56,4 +57,5 @@ Route::prefix('/companies')->middleware("auth:sanctum")->group(function () {
|
|||||||
Route::get("/simple", [CompanyController::class, 'all_simple']);
|
Route::get("/simple", [CompanyController::class, 'all_simple']);
|
||||||
Route::get("/{id}", [CompanyController::class, 'get']);
|
Route::get("/{id}", [CompanyController::class, 'get']);
|
||||||
Route::post("/{id}", [CompanyController::class, 'update_all']);
|
Route::post("/{id}", [CompanyController::class, 'update_all']);
|
||||||
|
Route::delete("/{id}", [CompanyController::class, 'delete']);
|
||||||
});
|
});
|
||||||
@@ -13,6 +13,13 @@ const companyId = route.params.id;
|
|||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
|
|
||||||
|
// Delete state
|
||||||
|
const deleteDialog = ref(false);
|
||||||
|
const deleteLoading = ref(false);
|
||||||
|
const deleteError = ref<string | null>(null);
|
||||||
|
const deleteSuccess = ref(false);
|
||||||
|
const company = ref<CompanyData | null>(null);
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
name: '',
|
name: '',
|
||||||
address: '',
|
address: '',
|
||||||
@@ -31,6 +38,7 @@ const { data } = await useSanctumFetch<CompanyData>(`/api/companies/${companyId}
|
|||||||
|
|
||||||
watch(data, (newData) => {
|
watch(data, (newData) => {
|
||||||
if (newData) {
|
if (newData) {
|
||||||
|
company.value = newData;
|
||||||
form.value.name = newData.name;
|
form.value.name = newData.name;
|
||||||
form.value.address = newData.address;
|
form.value.address = newData.address;
|
||||||
form.value.ico = newData.ico;
|
form.value.ico = newData.ico;
|
||||||
@@ -67,6 +75,49 @@ async function saveChanges() {
|
|||||||
function cancel() {
|
function cancel() {
|
||||||
navigateTo('/dashboard/admin/companies');
|
navigateTo('/dashboard/admin/companies');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funkcia na otvorenie delete dialogu
|
||||||
|
const openDeleteDialog = () => {
|
||||||
|
deleteDialog.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na zatvorenie dialogu
|
||||||
|
const closeDeleteDialog = () => {
|
||||||
|
deleteDialog.value = false;
|
||||||
|
deleteError.value = null;
|
||||||
|
deleteSuccess.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na vymazanie firmy
|
||||||
|
const deleteCompany = async () => {
|
||||||
|
if (!companyId) return;
|
||||||
|
|
||||||
|
deleteLoading.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client(`/api/companies/${companyId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteSuccess.value = true;
|
||||||
|
|
||||||
|
// Presmeruj na zoznam po 1.5 sekundách
|
||||||
|
setTimeout(() => {
|
||||||
|
navigateTo('/dashboard/admin/companies');
|
||||||
|
}, 1500);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof FetchError) {
|
||||||
|
deleteError.value = e.response?._data?.message || 'Chyba pri mazaní firmy.';
|
||||||
|
} else {
|
||||||
|
deleteError.value = 'Neznáma chyba pri mazaní firmy.';
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
deleteLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -125,11 +176,53 @@ function cancel() {
|
|||||||
<v-btn @click="cancel" :disabled="saving">
|
<v-btn @click="cancel" :disabled="saving">
|
||||||
Zrušiť
|
Zrušiť
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="red" variant="outlined" @click="openDeleteDialog" :disabled="saving">
|
||||||
|
Vymazať firmu
|
||||||
|
</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Delete Confirmation Dialog -->
|
||||||
|
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||||
|
<v-card>
|
||||||
|
<v-card-title class="text-h5">
|
||||||
|
Potvrdiť vymazanie
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<p v-if="!deleteSuccess">
|
||||||
|
Naozaj chcete vymazať firmu <strong>{{ company?.name }}</strong>?
|
||||||
|
</p>
|
||||||
|
<p v-if="!deleteSuccess" class="text-error mt-2">
|
||||||
|
Táto akcia vymaže aj kontaktnú osobu (EMPLOYER), všetky praxe a statusy spojené s touto firmou a
|
||||||
|
<strong>nie je možné ju vrátiť späť</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Error message -->
|
||||||
|
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||||
|
{{ deleteError }}
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<!-- Success message -->
|
||||||
|
<v-alert v-if="deleteSuccess" type="success" density="compact" class="mt-3">
|
||||||
|
Firma bola úspešne vymazaná. Presmerovanie...
|
||||||
|
</v-alert>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||||
|
Zrušiť
|
||||||
|
</v-btn>
|
||||||
|
<v-btn color="red" variant="text" @click="deleteCompany" :loading="deleteLoading"
|
||||||
|
:disabled="deleteSuccess">
|
||||||
|
Vymazať
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { CompanyData } from '~/types/company_data';
|
import type { CompanyData } from '~/types/company_data';
|
||||||
|
import { FetchError } from 'ofetch';
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: ['sanctum:auth', 'admin-only'],
|
middleware: ['sanctum:auth', 'admin-only'],
|
||||||
@@ -22,7 +23,54 @@ const headers = [
|
|||||||
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const { data, error } = await useSanctumFetch<CompanyData[]>('/api/companies/simple');
|
const client = useSanctumClient();
|
||||||
|
|
||||||
|
const { data, error, refresh } = await useSanctumFetch<CompanyData[]>('/api/companies/simple');
|
||||||
|
|
||||||
|
// State pre delete dialog
|
||||||
|
const deleteDialog = ref(false);
|
||||||
|
const companyToDelete = ref<CompanyData | null>(null);
|
||||||
|
const deleteLoading = ref(false);
|
||||||
|
const deleteError = ref<string | null>(null);
|
||||||
|
|
||||||
|
// Funkcia na otvorenie delete dialogu
|
||||||
|
const openDeleteDialog = (company: CompanyData) => {
|
||||||
|
companyToDelete.value = company;
|
||||||
|
deleteDialog.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na zatvorenie dialogu
|
||||||
|
const closeDeleteDialog = () => {
|
||||||
|
deleteDialog.value = false;
|
||||||
|
companyToDelete.value = null;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na vymazanie firmy
|
||||||
|
const deleteCompany = async () => {
|
||||||
|
if (!companyToDelete.value) return;
|
||||||
|
|
||||||
|
deleteLoading.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client(`/api/companies/${companyToDelete.value.id}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
closeDeleteDialog();
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof FetchError) {
|
||||||
|
deleteError.value = err.data?.message;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
deleteLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -62,14 +110,46 @@ const { data, error } = await useSanctumFetch<CompanyData[]>('/api/companies/sim
|
|||||||
<td class="text-left">
|
<td class="text-left">
|
||||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
||||||
:to="'/dashboard/admin/companies/edit/' + item.id">Editovať</v-btn>
|
:to="'/dashboard/admin/companies/edit/' + item.id">Editovať</v-btn>
|
||||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-trash-can-outline"
|
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-delete" base-color="red"
|
||||||
base-color="red" @click="async () => { }">Zmazať</v-btn>
|
@click="openDeleteDialog(item)">Vymazať</v-btn>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</v-table>
|
</v-table>
|
||||||
</div>
|
</div>
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
|
<!-- Delete Confirmation Dialog -->
|
||||||
|
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||||
|
<v-card>
|
||||||
|
<v-card-title class="text-h5">
|
||||||
|
Potvrdiť vymazanie
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<p>
|
||||||
|
Naozaj chcete vymazať firmu <strong>{{ companyToDelete?.name }}</strong>?
|
||||||
|
</p>
|
||||||
|
<p class="text-error mt-2">
|
||||||
|
Táto akcia vymaže aj kontaktnú osobu (EMPLOYER), všetky praxe a statusy spojené s touto firmou a
|
||||||
|
<strong>nie je možné ju vrátiť späť</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Error message -->
|
||||||
|
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||||
|
{{ deleteError }}
|
||||||
|
</v-alert>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||||
|
Zrušiť
|
||||||
|
</v-btn>
|
||||||
|
<v-btn color="red" variant="text" @click="deleteCompany" :loading="deleteLoading">
|
||||||
|
Vymazať
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ const student = ref<User | null>(null);
|
|||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
|
|
||||||
|
// Delete state
|
||||||
|
const deleteDialog = ref(false);
|
||||||
|
const deleteLoading = ref(false);
|
||||||
|
const deleteError = ref<string | null>(null);
|
||||||
|
const deleteSuccess = ref(false);
|
||||||
|
|
||||||
const form = ref({
|
const form = ref({
|
||||||
first_name: '',
|
first_name: '',
|
||||||
last_name: '',
|
last_name: '',
|
||||||
@@ -69,6 +75,49 @@ async function saveChanges() {
|
|||||||
function cancel() {
|
function cancel() {
|
||||||
navigateTo('/dashboard/admin/students');
|
navigateTo('/dashboard/admin/students');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Funkcia na otvorenie delete dialogu
|
||||||
|
const openDeleteDialog = () => {
|
||||||
|
deleteDialog.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na zatvorenie dialogu
|
||||||
|
const closeDeleteDialog = () => {
|
||||||
|
deleteDialog.value = false;
|
||||||
|
deleteError.value = null;
|
||||||
|
deleteSuccess.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na vymazanie študenta
|
||||||
|
const deleteStudent = async () => {
|
||||||
|
if (!studentId) return;
|
||||||
|
|
||||||
|
deleteLoading.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client(`/api/students/${studentId}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteSuccess.value = true;
|
||||||
|
|
||||||
|
// Presmeruj na zoznam po 1.5 sekundách
|
||||||
|
setTimeout(() => {
|
||||||
|
navigateTo('/dashboard/admin/students');
|
||||||
|
}, 1500);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof FetchError) {
|
||||||
|
deleteError.value = e.response?._data?.message || 'Chyba pri mazaní študenta.';
|
||||||
|
} else {
|
||||||
|
deleteError.value = 'Neznáma chyba pri mazaní študenta.';
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
deleteLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -124,11 +173,53 @@ function cancel() {
|
|||||||
<v-btn @click="cancel" :disabled="saving">
|
<v-btn @click="cancel" :disabled="saving">
|
||||||
Zrušiť
|
Zrušiť
|
||||||
</v-btn>
|
</v-btn>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="red" variant="outlined" @click="openDeleteDialog" :disabled="saving">
|
||||||
|
Vymazať študenta
|
||||||
|
</v-btn>
|
||||||
</v-card-actions>
|
</v-card-actions>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Delete Confirmation Dialog -->
|
||||||
|
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||||
|
<v-card>
|
||||||
|
<v-card-title class="text-h5">
|
||||||
|
Potvrdiť vymazanie
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<p v-if="!deleteSuccess">
|
||||||
|
Naozaj chcete vymazať študenta <strong>{{ student?.name }}</strong>?
|
||||||
|
</p>
|
||||||
|
<p v-if="!deleteSuccess" class="text-error mt-2">
|
||||||
|
Táto akcia vymaže aj všetky súvisiace dáta (praxe, statusy, atď.) a <strong>nie je možné ju
|
||||||
|
vrátiť späť</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Error message -->
|
||||||
|
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||||
|
{{ deleteError }}
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<!-- Success message -->
|
||||||
|
<v-alert v-if="deleteSuccess" type="success" density="compact" class="mt-3">
|
||||||
|
Študent bol úspešne vymazaný. Presmerovanie...
|
||||||
|
</v-alert>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||||
|
Zrušiť
|
||||||
|
</v-btn>
|
||||||
|
<v-btn color="red" variant="text" @click="deleteStudent" :loading="deleteLoading"
|
||||||
|
:disabled="deleteSuccess">
|
||||||
|
Vymazať
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { User } from '~/types/user';
|
import type { User } from '~/types/user';
|
||||||
|
import { FetchError } from 'ofetch';
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
middleware: ['sanctum:auth', 'admin-only'],
|
middleware: ['sanctum:auth', 'admin-only'],
|
||||||
@@ -22,8 +23,54 @@ const headers = [
|
|||||||
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
{ title: 'Operácie', key: 'ops', align: 'middle' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const client = useSanctumClient();
|
||||||
|
|
||||||
// Načítame všetkých študentov
|
// Načítame všetkých študentov
|
||||||
const { data: students, error } = await useSanctumFetch<User[]>('/api/students');
|
const { data: students, error, refresh } = await useSanctumFetch<User[]>('/api/students');
|
||||||
|
|
||||||
|
// State pre delete dialog
|
||||||
|
const deleteDialog = ref(false);
|
||||||
|
const studentToDelete = ref<User | null>(null);
|
||||||
|
const deleteLoading = ref(false);
|
||||||
|
const deleteError = ref<string | null>(null);
|
||||||
|
|
||||||
|
// Funkcia na otvorenie delete dialogu
|
||||||
|
const openDeleteDialog = (student: User) => {
|
||||||
|
studentToDelete.value = student;
|
||||||
|
deleteDialog.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na zatvorenie dialogu
|
||||||
|
const closeDeleteDialog = () => {
|
||||||
|
deleteDialog.value = false;
|
||||||
|
studentToDelete.value = null;
|
||||||
|
deleteError.value = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Funkcia na vymazanie študenta
|
||||||
|
const deleteStudent = async () => {
|
||||||
|
if (!studentToDelete.value) return;
|
||||||
|
|
||||||
|
deleteLoading.value = true;
|
||||||
|
deleteError.value = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client(`/api/students/${studentToDelete.value.id}`, {
|
||||||
|
method: 'DELETE'
|
||||||
|
});
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
closeDeleteDialog();
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof FetchError) {
|
||||||
|
deleteError.value = err.data?.message;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
deleteLoading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -63,6 +110,8 @@ const { data: students, error } = await useSanctumFetch<User[]>('/api/students')
|
|||||||
<td class="text-left">
|
<td class="text-left">
|
||||||
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-pencil" base-color="orange"
|
||||||
:to="'/dashboard/admin/students/edit/' + item.id">Editovať</v-btn>
|
:to="'/dashboard/admin/students/edit/' + item.id">Editovať</v-btn>
|
||||||
|
<v-btn class="m-1 op-btn" density="compact" append-icon="mdi-delete" base-color="red"
|
||||||
|
@click="openDeleteDialog(item)">Vymazať</v-btn>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
@@ -72,6 +121,38 @@ const { data: students, error } = await useSanctumFetch<User[]>('/api/students')
|
|||||||
class="mt-4"></v-alert>
|
class="mt-4"></v-alert>
|
||||||
</div>
|
</div>
|
||||||
</v-card>
|
</v-card>
|
||||||
|
|
||||||
|
<!-- Delete Confirmation Dialog -->
|
||||||
|
<v-dialog v-model="deleteDialog" max-width="500px">
|
||||||
|
<v-card>
|
||||||
|
<v-card-title class="text-h5">
|
||||||
|
Potvrdiť vymazanie
|
||||||
|
</v-card-title>
|
||||||
|
<v-card-text>
|
||||||
|
<p>
|
||||||
|
Naozaj chcete vymazať študenta <strong>{{ studentToDelete?.name }}</strong>?
|
||||||
|
</p>
|
||||||
|
<p class="text-error mt-2">
|
||||||
|
Táto akcia vymaže aj všetky súvisiace dáta (praxe, statusy, atď.) a <strong>nie je možné ju
|
||||||
|
vrátiť späť</strong>.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<!-- Error message -->
|
||||||
|
<v-alert v-if="deleteError" type="error" density="compact" class="mt-3">
|
||||||
|
{{ deleteError }}
|
||||||
|
</v-alert>
|
||||||
|
</v-card-text>
|
||||||
|
<v-card-actions>
|
||||||
|
<v-spacer></v-spacer>
|
||||||
|
<v-btn color="grey" variant="text" @click="closeDeleteDialog" :disabled="deleteLoading">
|
||||||
|
Zrušiť
|
||||||
|
</v-btn>
|
||||||
|
<v-btn color="red" variant="text" @click="deleteStudent" :loading="deleteLoading">
|
||||||
|
Vymazať
|
||||||
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-card>
|
||||||
|
</v-dialog>
|
||||||
</v-container>
|
</v-container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user