-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability for employees to upload avatars (#618)
- Loading branch information
Showing
55 changed files
with
1,060 additions
and
995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/Http/Controllers/Company/Employee/EmployeeEditAvatarController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Employee; | ||
|
||
use Inertia\Response; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\AvatarHelper; | ||
use App\Helpers\InstanceHelper; | ||
use App\Models\Company\Employee; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Http\Controllers\Controller; | ||
use App\Services\Company\Adminland\File\UploadFile; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
|
||
class EmployeeEditAvatarController extends Controller | ||
{ | ||
/** | ||
* Update the avatar. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @param int $employeeId | ||
* @return JsonResponse | ||
*/ | ||
public function update(Request $request, int $companyId, int $employeeId): JsonResponse | ||
{ | ||
$loggedCompany = InstanceHelper::getLoggedCompany(); | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
|
||
try { | ||
$employee = Employee::where('company_id', $loggedCompany->id) | ||
->findOrFail($employeeId); | ||
} catch (ModelNotFoundException $e) { | ||
return redirect('home'); | ||
} | ||
|
||
$file = (new UploadFile)->execute([ | ||
'company_id' => $loggedCompany->id, | ||
'author_id' => $loggedEmployee->id, | ||
'uuid' => $request->input('uuid'), | ||
'name' => $request->input('name'), | ||
'original_url' => $request->input('original_url'), | ||
'cdn_url' => $request->input('cdn_url'), | ||
'mime_type' => $request->input('mime_type'), | ||
'size' => $request->input('size'), | ||
'type' => 'avatar', | ||
]); | ||
|
||
$employee->avatar_file_id = $file->id; | ||
$employee->save(); | ||
$employee->refresh(); | ||
|
||
return response()->json([ | ||
'avatar' => AvatarHelper::getImage($employee), | ||
], 200); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.