diff --git a/backend/app/Models/Company.php b/backend/app/Models/Company.php index 6320e72..f98416b 100644 --- a/backend/app/Models/Company.php +++ b/backend/app/Models/Company.php @@ -23,6 +23,16 @@ class Company extends Model 'hiring' ]; + /** + * The attributes that should be hidden for serialization. + * + * @var list + */ + protected $hidden = [ + 'created_at', + 'updated_at', + ]; + /** * Get the internships for the company. */ @@ -34,7 +44,7 @@ class Company extends Model /** * Get the contact person (user) for the company. */ - public function contactPerson() + public function contact() { return $this->belongsTo(User::class, 'contact'); } diff --git a/backend/app/Models/Internship.php b/backend/app/Models/Internship.php index 82dcd51..4330fee 100644 --- a/backend/app/Models/Internship.php +++ b/backend/app/Models/Internship.php @@ -2,6 +2,7 @@ namespace App\Models; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -28,6 +29,16 @@ class Internship extends Model 'report_confirmed', ]; + /** + * The attributes that should be hidden for serialization. + * + * @var list + */ + protected $hidden = [ + 'created_at', + 'updated_at', + ]; + /** * Get the attributes that should be cast. * @@ -49,4 +60,32 @@ class Internship extends Model { return $this->belongsTo(Company::class, 'company_id'); } + + public function status() + { + return $this->hasOne(InternshipStatus::class, 'internship_id')->latestOfMany(); + } + + /** + * Prepare the model for JSON serialization. + * + * @return array + */ + public function toArray(): array + { + return [ + 'id' => $this->id, + 'student' => $this->student, + 'company' => $this->company, + 'start' => Carbon::parse($this->start)->format('d.m.Y'), + 'end' => Carbon::parse($this->end)->format('d.m.Y'), + 'year_of_study' => $this->year_of_study, + 'semester' => $this->semester, + 'position_description' => $this->position_description, + 'agreement' => $this->agreement !== null, + 'report' => $this->report !== null, + 'report_confirmed' => $this->report_confirmed, + 'status' => $this->status, + ]; + } } diff --git a/backend/app/Models/InternshipStatus.php b/backend/app/Models/InternshipStatus.php index 4272c86..fc41517 100644 --- a/backend/app/Models/InternshipStatus.php +++ b/backend/app/Models/InternshipStatus.php @@ -22,4 +22,31 @@ class InternshipStatus extends Model 'note', 'modified_by' ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var list + */ + protected $hidden = [ + 'created_at', + 'updated_at', + ]; + + public function modifiedBy() + { + return $this->belongsTo(User::class, 'modified_by'); + } + + public function toArray() + { + return [ + 'id' => $this->id, + 'internship_id' => $this->internship_id, + 'status' => $this->status, + 'changed' => $this->changed, + 'note' => $this->note, + 'modified_by' => $this->modifiedBy, + ]; + } } diff --git a/backend/app/Models/StudentData.php b/backend/app/Models/StudentData.php index 8490416..d9fb90f 100644 --- a/backend/app/Models/StudentData.php +++ b/backend/app/Models/StudentData.php @@ -21,4 +21,14 @@ class StudentData extends Model 'personal_email', 'study_field', ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var list + */ + protected $hidden = [ + 'created_at', + 'updated_at', + ]; } diff --git a/backend/app/Models/User.php b/backend/app/Models/User.php index c80bbdc..744275f 100644 --- a/backend/app/Models/User.php +++ b/backend/app/Models/User.php @@ -39,6 +39,11 @@ class User extends Authenticatable 'password', 'remember_token', 'activation_token', + 'created_at', + 'updated_at', + 'email_verified_at', + 'active', + 'needs_password_change' ]; /**