Refactor driving license retrieval and display
This commit refactors the code related to retrieving and displaying driving license information. The changes include: - Replacing the previous query with a more efficient join query - Updating the scan URL to use the new scan_uuid property - Updating the scan URL in the frontend component to use the new scan_url property
This commit is contained in:
parent
75f495e574
commit
e7f65ab732
|
@ -63,15 +63,19 @@ class UserController extends Controller
|
|||
|
||||
User::where('id', $request->user()->id)->update(['last_access' => now()]);
|
||||
|
||||
//TODO: do not display useless or hidden info to the user about documentFile (like filePath and id) but only the url (see below)
|
||||
$user->driving_license = Document::where('added_by', $user->id)
|
||||
->where('type', 'driving_license')
|
||||
->with('documentFile')
|
||||
->first();
|
||||
$dl_tmp = Document::where('documents.added_by', $user->id)
|
||||
->where('documents.type', 'driving_license')
|
||||
->join('document_files', 'document_files.id', '=', 'documents.document_file_id')
|
||||
->select('documents.doc_type', 'documents.doc_number', 'documents.expiration_date', 'document_files.uuid as scan_uuid')
|
||||
->get();
|
||||
|
||||
if(!is_null($user->driving_license) && !is_null($user->driving_license->documentFile)) {
|
||||
$user->driving_license->documentFile->url = URL::temporarySignedRoute(
|
||||
'driving_license_scan_serve', now()->addMinutes(2), ['uuid' => $user->driving_license->documentFile->uuid]
|
||||
if($dl_tmp->count() > 0) {
|
||||
$user->driving_license = $dl_tmp[0];
|
||||
}
|
||||
|
||||
if(!is_null($user->driving_license) && !is_null($user->driving_license->scan_uuid)) {
|
||||
$user->driving_license->scan_url = URL::temporarySignedRoute(
|
||||
'driving_license_scan_serve', now()->addMinutes(2), ['uuid' => $user->driving_license->scan_uuid]
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ export class EditUserComponent implements OnInit {
|
|||
number: this.user.driving_license ? this.user.driving_license.doc_number : null,
|
||||
type: this.user.driving_license ? this.user.driving_license.doc_type : null,
|
||||
expiration_date: (this.user.driving_license && this.user.driving_license.expiration_date) ? new Date(this.user.driving_license.expiration_date) : null,
|
||||
scan: this.user.driving_license ? this.user.driving_license.uuid : null
|
||||
scan: this.user.driving_license ? this.user.driving_license.scan_uuid : null
|
||||
},
|
||||
suit_size: this.user.suit_size,
|
||||
boot_size: this.user.boot_size
|
||||
|
@ -104,8 +104,8 @@ export class EditUserComponent implements OnInit {
|
|||
this.update_date = convertToItalianDate(this.user.updated_at);
|
||||
this.last_access_date = convertToItalianDate(this.user.last_access);
|
||||
|
||||
if(this.user.driving_license && this.user.driving_license.document_file) {
|
||||
this.dlCurrScanUrl = this.api.apiEndpoint(this.user.driving_license.document_file.url);
|
||||
if(this.user.driving_license && this.user.driving_license.scan_uuid) {
|
||||
this.dlCurrScanUrl = this.api.apiEndpoint(this.user.driving_license.scan_url);
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
|
|
Loading…
Reference in New Issue