Se Crea Modelo User, Carga El Cliente Con La Cedula en Pantalla Cola
Se Crea Modelo User, Carga El Cliente Con La Cedula en Pantalla Cola
.gitignore
... ... @@ -11,3 +11,4 @@ Homestead.yaml
11 11 npm-debug.log
12 12 yarn-error.log
13 13 ttoatlantico-firebase-adminsdk-r9xuq-3b6344c665.json
14 + notas.txt
app/Branch.php
... ... @@ -2,7 +2,9 @@
2 2
3 3 namespace App;
4 4
5 - class Branch extends Model
5 + use App\Support\LarafireModel;
6 +
7 + class Branch extends LarafireModel
6 8 {
7 9 protected $collectionName = 'branchs';
8 10 }
app/Client.php
app/Company.php
app/Employee.php
... ... @@ -2,7 +2,9 @@
2 2
3 3 namespace App;
4 4
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 1/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
app/Http/Controllers/API/ClientController.php
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\API;
4 4
5 5 use App\Client;
6 6 use App\Http\Controllers\Controller;
7 + use App\User;
7 8 use Illuminate\Http\Request;
8 9
9 10 class ClientController extends Controller
... ... @@ -13,4 +14,25 @@ class ClientController extends Controller
13 14 $clients = Client::all();
14 15 return response()->json(['status' => 'success', 'data' => $clients->toArray()]);
15 16 }
17 +
18 + public function findByIdentification(Request $request, $identification)
19 + {
20 + $data = $request->validate([
21 + 'identificationType' => 'required',
22 + ]);
23 +
24 + $fullId = $data['identificationType'].$identification;
25 +
26 + $client = Client::first('identification', '=', $fullId);
27 +
28 + $userClient = $client ? User::find($client->get('uid')) : null;
29 +
30 + return response()->json([
31 + 'status' => 'success',
32 + 'data' => [
33 + 'client' => $client ? $client->toArray() : null,
34 + 'userClient' => $userClient ? $userClient->toArray() : null,
35 + ]
36 + ]);
37 + }
16 38 }
app/Http/Controllers/QueueController.php
... ... @@ -41,8 +41,8 @@ class QueueController extends Controller
41 41 'isPriority' => (bool)$request->has('is-priority'),
42 42 'state' => $data['state'],
43 43 'uid' => $data['uid'],
44 - 'createBy' => $data['uid'],
45 - 'createAt' => date_create(),
44 + 'createdBy' => $data['uid'],
45 + 'createdAt' => date_create(),
46 46 'order' => Queue::getNextOrder()
47 47 ]);
48 48
... ...
app/Http/Controllers/UserController.php
... ... @@ -2,8 +2,8 @@
2 2
3 3 namespace App\Http\Controllers;
4 4
5 - use App\User;
6 5 use App\Http\Requests\UserRequest;
6 + use App\User;
7 7 use Illuminate\Support\Facades\Hash;
8 8
9 9 class UserController extends Controller
... ... @@ -14,7 +14,7 @@ class UserController extends Controller
14 14 * @param \App\User $model
15 15 * @return \Illuminate\View\View
16 16 */
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 2/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
app/Queue.php
... ... @@ -2,7 +2,9 @@
2 2
3 3 namespace App;
4 4
5 - class Queue extends Model
5 + use App\Support\LarafireModel;
6 +
7 + class Queue extends LarafireModel
6 8 {
7 9 protected $collectionName = 'queues';
8 10
... ...
app/Service.php
... ... @@ -2,7 +2,9 @@
2 2
3 3 namespace App;
4 4
5 - class Service extends Model
5 + use App\Support\LarafireModel;
6 +
7 + class Service extends LarafireModel
6 8 {
7 9 protected $collectionName = 'services';
8 10 }
app/Model.php → app/Support/LarafireModel.php
1 1 <?php
2 2
3 - namespace App;
3 + namespace App\Support;
4 4
5 - use Google\Cloud\Firestore\DocumentSnapshot;
6 - use Kreait\Firebase\Firestore;
7 -
8 - class Model
5 + class LarafireModel
9 6 {
10 7 private $firestore;
11 - private $collection;
12 8 private $snapshot;
13 9 protected $collectionName;
14 10 private static $isInstance = false;
... ... @@ -52,7 +48,11 @@ class Model
52 48 {
53 49 $instance = self::getNewInstance();
54 50
55 - $instance->setSnapshot($instance->collection->document($id)->snapshot());
51 + $snapshot = $instance->collection->document($id)->snapshot();
52 +
53 + if ($snapshot->exists()) $instance->setSnapshot($snapshot);
54 + else $instance = null;
55 +
56 56 return $instance;
57 57 }
58 58
... ... @@ -73,7 +73,7 @@ class Model
73 73 if (count($results) > 0) {
74 74 $instance->setSnapshot($results[0]);
75 75 } else {
76 - $instance->setSnapshot(null);
76 + $instance = null;
77 77 }
78 78
79 79 return $instance;
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 3/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
... ...
app/Support/LarafireUserModel.php 0 → 100644
1 + <?php
2 +
3 + namespace App\Support;
4 +
5 + use Kreait\Firebase\Auth\UserRecord;
6 +
7 + class LarafireUserModel
8 +{
9 + // private $firestore;
10 + // private $snapshot;
11 + // protected $collectionName;
12 + private $auth;
13 + public $firebaseObject;
14 + private static $isInstance = false;
15 +
16 + public function __construct()
17 + {
18 + // $this->firestore = app('firebase.firestore');
19 + // $this->collection = $this->firestore->database()->collection($this->collectionName);
20 + $this->auth = app('firebase.auth');
21 + self::$isInstance = true;
22 + }
23 +
24 +
25 +
26 + // STATIC METHODS
27 +
28 + private static function getNewInstance()
29 + {
30 + $className = get_called_class();
31 + return new $className;
32 + }
33 +
34 + public static function all()
35 + {
36 + $instance = self::getNewInstance();
37 + $rows = $instance->auth->listUsers();
38 + return collect(iterator_to_array($rows));
39 + }
40 +
41 + public static function find($id)
42 + {
43 + $instance = self::getNewInstance();
44 +
45 + try {
46 + $user = $instance->auth->getUser($id);
47 + } catch (\Exception $ex) {
48 + if (\Str::startsWith($ex->getMessage(), 'No user with uid')) return null;
49 + else throw $ex;
50 + }
51 +
52 + $instance->firebaseObject = $user;
53 +
54 + return $instance;
55 + }
56 +
57 + public static function where($field, $operation, $value)
58 + {
59 + $instance = self::getNewInstance();
60 +
61 + if (!self::$isInstance) $instance = $this;
62 +
63 + if (!$instance->firebaseObject) $instance->firebaseObject = $instance->all();
64 +
65 + $instance->firebaseObject = $instance->firebaseObject->where($field, $operation, $value);
66 +
67 + return $instance;
68 + }
69 +
70 + public static function first($field, $operation, $value)
71 + {
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 4/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
72 + $instance = self::getNewInstance();
73 +
74 + if (!self::$isInstance) $instance = $this;
75 +
76 + $result = $instance->whereRecords($field, $operation, $value)->first();
77 +
78 + if ($result) $instance->firebaseObject = $result;
79 + else $instance = null;
80 +
81 + return $instance;
82 + }
83 +
84 + public static function whereRecords($field, $operation, $value)
85 + {
86 + $rows = self::where($field, $operation, $value)->firebaseObject;
87 +
88 + return $rows;
89 + }
90 +
91 +
92 + // INSTANCE METHODS
93 +
94 + public function get($field)
95 + {
96 + if (!$this->firebaseObject) throw new \Exception('No Firebase object set yet');
97 + if ($field == 'id') $field = 'uid';
98 + return $this->firebaseObject->$field;
99 + }
100 +
101 + public function data()
102 + {
103 + if (!$this->firebaseObject) throw new \Exception('No Firebase object set yet');
104 +
105 + return collect($this->firebaseObject)->toArray();
106 + }
107 +
108 + public function toArray()
109 + {
110 + return $this->data();
111 + }
112 +
113 +
114 +
115 + // MUTATION
116 +
117 + // public static function create($data)
118 + // {
119 + // $instance = self::getNewInstance();
120 + // $instance->setSnapshot($instance->collection->add($data)->snapshot());
121 + // return $instance;
122 + // }
123 +}
app/User.eloquent.php 0 → 100644
1 + <?php
2 +
3 + namespace App;
4 +
5 + use Illuminate\Contracts\Auth\MustVerifyEmail;
6 + use Illuminate\Foundation\Auth\User as Authenticatable;
7 + use Illuminate\Notifications\Notifiable;
8 +
9 + // class User extends Authenticatable
10 + // {
11 + // use Notifiable;
12 + //
13 + // /**
14 + // * The attributes that are mass assignable.
15 + // *
16 + // * @var array
17 + // */
18 + // protected $fillable = [
19 + // 'name', 'email', 'password',
20 + // ];
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 5/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
21 + //
22 + // /**
23 + // * The attributes that should be hidden for arrays.
24 + // *
25 + // * @var array
26 + // */
27 + // protected $hidden = [
28 + // 'password', 'remember_token',
29 + // ];
30 + //
31 + // /**
32 + // * The attributes that should be cast to native types.
33 + // *
34 + // * @var array
35 + // */
36 + // protected $casts = [
37 + // 'email_verified_at' => 'datetime',
38 + // ];
39 + // }
app/User.php
... ... @@ -2,38 +2,9 @@
2 2
3 3 namespace App;
4 4
5 - use Illuminate\Contracts\Auth\MustVerifyEmail;
6 - use Illuminate\Foundation\Auth\User as Authenticatable;
7 - use Illuminate\Notifications\Notifiable;
5 + use App\Support\LarafireUserModel;
8 6
9 - class User extends Authenticatable
7 + class User extends LarafireUserModel
10 8 {
11 - use Notifiable;
12 -
13 - /**
14 - * The attributes that are mass assignable.
15 - *
16 - * @var array
17 - */
18 - protected $fillable = [
19 - 'name', 'email', 'password',
20 - ];
21 -
22 - /**
23 - * The attributes that should be hidden for arrays.
24 - *
25 - * @var array
26 - */
27 - protected $hidden = [
28 - 'password', 'remember_token',
29 - ];
30 -
31 - /**
32 - * The attributes that should be cast to native types.
33 - *
34 - * @var array
35 - */
36 - protected $casts = [
37 - 'email_verified_at' => 'datetime',
38 - ];
9 + //
39 10 }
public/js/master.js 0 → 100644
1 + window.Progress = {
2 + start() {
3 + document.querySelector('body').style.cursor = 'wait';
4 + NProgress.start();
5 + },
6 + done() {
7 + document.querySelector('body').style.cursor = 'initial';
8 + NProgress.done();
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 6/7
29/6/2020 Se crea modelo user, carga el cliente con la cedula en pantalla cola (56339d68) · Commits · Guillermo Agudelo / transito-backup · GitLab
9 + }
10 +}
resources/views/layouts/app.blade.php
resources/views/queue/index.blade.php
routes/api.php
... ... @@ -27,5 +27,7 @@ Route::group([
27 27 'as' => 'clients.',
28 28 ], function () {
29 29 Route::get('all', 'ClientController@all')->name('all');
30 + Route::get('find-by-identification/{identification}', 'ClientController@findByIdentification')
31 + ->name('find-by-identification');
30 32 });
31 33 });
routes/web.php
... ... @@ -28,6 +28,7 @@ Route::get('/home', 'HomeController@index')->middleware('auth')->name('home');
28 28
29 29 Route::group(['middleware' => 'auth'], function () {
30 30 Route::resource('user', 'UserController', ['except' => ['show']]);
31 +
31 32 Route::get('profile', ['as' => 'profile.edit', 'uses' => 'ProfileController@edit']);
32 33 Route::put('profile', ['as' => 'profile.update', 'uses' => 'ProfileController@update']);
33 34 Route::put('profile/password', ['as' => 'profile.password', 'uses' =>
'ProfileController@password']);
... ...
https://gitlab.com/guille.agudelo/transito/-/commit/56339d6883e286db82b1ff7429db92f69852823d 7/7