Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Renamed foreign keys [#150]
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Jan 9, 2019
1 parent 0639693 commit 4317178
Show file tree
Hide file tree
Showing 35 changed files with 397 additions and 189 deletions.
11 changes: 3 additions & 8 deletions api/app/Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@

class Holiday extends Model
{
protected $fillable = ['id',
'date_from',
'date_to',
'holiday_type',
'description'
];
protected $fillable = ['date_from', 'date_to', 'description', 'holiday_type_id' ];

public function holidayType()
public function holiday_type()
{
return $this->belongsTo('App\HolidayType', 'holiday_type');
return $this->belongsTo(HolidayType::class);
}
}
2 changes: 2 additions & 0 deletions api/app/HolidayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public function holiday()
{
return $this->hasMany('App\Holiday');
}

public $timestamps = false;
}
6 changes: 3 additions & 3 deletions api/app/Http/Controllers/api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function jwt(User $user)
$payload = [
'iss' => "izivi-api", // Issuer of the token
'sub' => $user->id, // Subject of the token
'isAdmin' => $user->role == 1,
'isAdmin' => $user->isAdmin(),
'iat' => time(), // Time when JWT was issued.
'exp' => time() + 60*60*24, // Expiration time,
];
Expand Down Expand Up @@ -147,8 +147,8 @@ public function postRegister(Request $request)
$user->phone_business = "";
$user->phone_mobile = "";
$user->phone_private = "";
$user->regional_center = 1;
$user->role = AuthController::USER_ROLE_ZIVI;
$user->regional_center_id = 1;
$user->role_id = AuthController::USER_ROLE_ZIVI;
$user->zdp = $request->input("zdp");
$user->save();

Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/api/FeedbackController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function postFeedback()

foreach ($content['answers'] as $answer) {
$user_feedback = new UserFeedback();
$user_feedback->user = $userId;
$user_feedback->user_id = $userId;
$user_feedback->feedbackId = $feedbackId;
$user_feedback->year = $date;
$user_feedback->questionId = $answer['id'];
Expand Down
2 changes: 1 addition & 1 deletion api/app/Http/Controllers/api/HolidayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private function validateRequest(Request $request)
'date_from' => 'required|date',
'date_to' => 'required|date',
'description' => 'required|string',
'holiday_type' => 'required|integer'
'holiday_type_id' => 'required|integer'
]);
}
}
16 changes: 8 additions & 8 deletions api/app/Http/Controllers/api/MissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function delete($id)
public function indexByYear($year)
{
// TODO remove join and work with Laravel relations instead
$data = Mission::join('users', 'users.id', '=', 'missions.user')
->join('specifications', 'specifications.id', '=', 'missions.specification')
$data = Mission::join('users', 'users.id', '=', 'missions.user_id')
->join('specifications', 'specifications.id', '=', 'missions.specification_id')
->select('*', 'users.id AS userid')
->whereNull('missions.deleted_at')
->whereDate('end', '>=', $year . '-01-01')
Expand All @@ -51,7 +51,7 @@ public function post(Request $request)
{
$validatedData = $this->validateRequest($request);

if (Auth::user()->isAdmin() || Auth::id() == $validatedData['user']) {
if (Auth::user()->isAdmin() || Auth::id() == $validatedData['user_id']) {
$mission = new Mission($validatedData);
$mission->feedback_mail_sent = false;
$mission->feedback_done = false;
Expand All @@ -63,8 +63,8 @@ public function post(Request $request)

// TODO replace this piece as soon as the frontend implementation of the Profile view is specified
$user = Auth::user();
if ($mission->user == 'me') {
$mission->user = $user->id;
if ($mission->user_id == 'me') {
$mission->user_id = $user->id;
}

$mission->save();
Expand All @@ -78,7 +78,7 @@ public function put($id, Request $request)
{
$mission = Mission::findOrFail($id);

if (Auth::user()->isAdmin() || Auth::id() == $mission->user) {
if (Auth::user()->isAdmin() || Auth::id() == $mission->user_id) {
DB::beginTransaction();
try {
$validatedData = $this->validateRequest($request);
Expand Down Expand Up @@ -167,9 +167,9 @@ private function validateRequest(Request $request)
'long_mission' => 'required|boolean',
'mission_type' => 'required|integer',
'probation_period' => 'required|boolean',
'specification' => 'required|integer',
'specification_id' => 'required|integer',
'start' => 'required|date',
'user' => 'required|integer'
'user_id' => 'required|integer'
]);
}
}
3 changes: 1 addition & 2 deletions api/app/Http/Controllers/api/PDFController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ public function getAufgebot(Application $app, $id)

//Allow only admins to get reportSheets of other Users
$user = Auth::user();
if ($user->role!=1 && $user->id!=$aufgebot->getUserId()) {
if (!$user->isAdmin() && $user->id!=$aufgebot->getUserId()) {
return response("unauthorized", 401);
}


$response = response()->download($aufgebot->createPDF(), 'aufgebot.pdf')
->deleteFileAfterSend(true);
$response->headers->set("Content-Type", "application/pdf");
Expand Down
14 changes: 7 additions & 7 deletions api/app/Http/Controllers/api/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ public function getIsoPaymentXml()
$sheet->save();

$paymentEntry = new PaymentEntry();
$paymentEntry->payment = $payment->id;
$paymentEntry->payment_id = $payment->id;
$paymentEntry->amount = $element['amount']*100;
$paymentEntry->user = $element['userid'];
$paymentEntry->user_id = $element['userid'];
$paymentEntry->iban = $element['iban'];
$paymentEntry->report_sheet = $element['sheet_id'];
$paymentEntry->report_sheet_id = $element['sheet_id'];
$paymentEntry->save();
}

Expand All @@ -199,10 +199,10 @@ public function getArchivedPayment($id)
{
$payment = Payment::find($id);
$payment->sheets = PaymentEntry::
join('users', 'users.id', '=', 'payment_entries.user')
->join('report_sheets', 'report_sheets.id', '=', 'payment_entries.report_sheet')
->select('amount', 'report_sheet', 'first_name', 'last_name', 'zdp', 'users.id AS userid', 'iban', 'state')
->where('payment', '=', $id)->get();
join('users', 'users.id', '=', 'payment_entries.user_id')
->join('report_sheets', 'report_sheets.id', '=', 'payment_entries.report_sheet_id')
->select('amount', 'report_sheet_id', 'first_name', 'last_name', 'zdp', 'users.id AS userid', 'iban', 'state')
->where('payment_id', '=', $id)->get();
return new JsonResponse($payment);
}

Expand Down
7 changes: 4 additions & 3 deletions api/app/Http/Controllers/api/ReportSheetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function index()
{
if (!Auth::user()->isAdmin()) {
// TODO Improve this piece by using Auth::user->report_sheets, then use the Laravel Collection where and select functions
$reportSheets = ReportSheet::join('users', 'report_sheets.user', '=', 'users.id')
$reportSheets = ReportSheet::join('users', 'report_sheets.user_id', '=', 'users.id')
->select('report_sheets.id AS id', 'start', 'end', 'state')
->where('users.id', '=', Auth::id())
->where('state', '>', '0')
Expand All @@ -37,9 +37,10 @@ public function index()

return $reportSheets;
} else {
return ReportSheet::with('user')->orderBy('start', 'desc')
return ReportSheet::join('users', 'users.id', '=', 'report_sheets.user_id')
->orderBy('start', 'desc')
->orderBy('end', 'desc')
->orderBy('zdp')
->orderBy('users.zdp')
->get();
}
}
Expand Down
6 changes: 3 additions & 3 deletions api/app/Http/Controllers/api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function get($id)

public function index()
{
return User::with(['user_role', 'missions'])->get();
return User::with(['role', 'missions'])->get();
}

public function put($id, Request $request)
Expand Down Expand Up @@ -110,7 +110,7 @@ private function basicUserValidationRules()
'hometown' => 'required|string',
'last_name' => 'required|string',
'phone' => 'required|string',
'regional_center' => 'required|integer',
'regional_center_id' => 'required|integer',
'work_experience' => 'required|string',
'zip' => 'required|integer',
];
Expand All @@ -120,7 +120,7 @@ private function extendedUserValidationRules()
{
return [
'internal_note' => 'string',
'role' => 'required|integer',
'role_id' => 'required|integer',
];
}
}
14 changes: 9 additions & 5 deletions api/app/Mission.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App;

use App\ReportSheet;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

Expand All @@ -11,8 +10,8 @@ class Mission extends Model
use SoftDeletes;

protected $fillable = ['id',
'user',
'specification', // "Pflichtenheft"
'user_id',
'specification_id', // "Pflichtenheft"
'start',
'end',
'draft', // "Aufgebot"
Expand All @@ -31,9 +30,14 @@ class Mission extends Model
'first_time' => 'boolean'
];

public function usermodel()
public function specification()
{
return $this->belongsTo('App\User', 'user');
return $this->belongsTo(Specification::class);
}

public function user()
{
return $this->belongsTo(User::class);
}

public function getFormattedDate($fieldName)
Expand Down
23 changes: 17 additions & 6 deletions api/app/PaymentEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@

class PaymentEntry extends Model
{
protected $fillable = ['id',
'user',
'report_sheet',
'amount',
'iban'
];
protected $fillable = ['amount','iban', 'id', 'payment_id', 'report_sheet_id', 'user_id'];

public function report_sheet()
{
return $this->belongsTo(ReportSheet::class);
}

public function payment()
{
return $this->belongsTo(Payment::class);
}

// TODO drop relation with user
public function user()
{
return $this->belongsTo(User::class);
}
}
Loading

0 comments on commit 4317178

Please sign in to comment.