Subscribing to a simple request is the right approach on Angular 2 in this case?

断了今生、忘了曾经 提交于 2019-12-11 10:09:33

问题


I have a Parking System that I use Angular 6 + Laravel for the backend, I have a post that I post some of my problems that were resolved by the DigitalDrifter thank you.

Here is the link: How to Make a Scheduler Task for Every New Record After 20 Minutes in Laravel?

My system is not 100% good because I having a strange behaviour. Every client must go to the Payment Area and validated your entry. When the client show the ticket to the cashier he validated the entry after the payment clicking in a button called "VALIDATE TICKET"

And my code does this in Angular:

validateEntry(ean13: string, value: number) {

    this.spinner.show();
    this.entryService.validateEntry(this.config.role.validateEntryUrl, ean13, value, this.userModel.mov_user_id)
      .pipe(
        catchError(
          (error: any): Observable<any> => {
            this.spinner.hide();
            $('#m_modal_1').modal('hide');
            return this.utilService.errorHandler(error);
          }))
      .subscribe(response => {

      if (response.success != 0) {

        $('#m_modal_1').modal('hide');
        this.spinner.hide();
        swal({
          title: 'Validado!',
          text: response.message,
          type: 'success',
          showCloseButton: true,
          showCancelButton: false,
          showConfirmButton: false
        }).then((result) => {
          $("#mov_ean13_input").focus();
          });


      }else {

        $('#m_modal_1').modal('hide');
        this.spinner.hide();
        swal({
          title: 'Erro!',
          text: response.message,
          type: 'error',
          showCloseButton: true,
          showCancelButton: false,
          showConfirmButton: false
        }).then((result) => {
          $("#mov_ean13_input").focus();
        });

        }


    });


  }

And here is the service on Angular 6 :

public validateEntry(url: string, ean13: string, value: number, userid: number): Observable<any> {

    console.log(userid);

    return this.http.post(this.mainConfig.config.default.mainUrl + url, { ean13: ean13, value: value, userid: userid });

  }

And here is the backend on laravel, this is the code :

  public function validateEntry(Request $request){

                 try{

                       $entryean13  = $request->input('ean13');
                       $value       = $request->input('value');
                       $userid      = $request->input('userid');              

                       $this->mdEntry->validatedEntryByEan($entryean13,$value,$userid); 

                       if(empty($this->mdEntry->checkValidEntry($entryean13))){

                         $response["success"] = 0;
                         $response["message"] = "Ocorreu algum erro no servidor, tente validar novamente";  

                       }else {                           

                         $response["success"] = 1;
                         $response["message"] = "Entrada validada com sucesso";                                       

                       }  

                       return $response;    
                } 
                catch(\Exception $e){

                      $response["success"]         = 0;
                      $response["message"]         = "Aconteceu algum erro no processamento, tente novamente em alguns minutos.";
                      $response["erro"]            = $e->getMessage();  
                      return $response;
                }           
          }

And to finish the code area here is the Eloquent that update my table:

  public function validatedEntryByEan($ean13,$valor,$userid){

               Entry::where('mov_entry_ean13', $ean13 )
               ->update(['validated' => 'S',
                         'value' => $valor,
                         'mov_user_id' => $userid]); 

    }

When going to Laravel I get the entry EAN_13 code, $value and $userid ( Cashier user ) and do an update on the table and validate the entry, the client has 30 minutes to go out.

The problem is 85% are validated but 15% are not and the Cashier always say that they always click the button to validate. Some clients pay and when he will go out to the EXIT TOTEM don't let them go, when I pick the ticket and test it he is not validated.

What I'm missing? Is not a human error, everyone clicks the button. I don't know what is wrong, because when the user clicks I return a box that says "ENTRY IS VALIDATED" when ( response.success != 0 ) on Angular.

I do this check to see if the user will be validated for some tests. Now my question this is the right approach for Subscribe? Do you guys think everytime he clicks the button he goes and does a request? or don't? Sorry it is a very noob question, but I want to this work 100%, I put some try and catch and don't receive any error.

Do you think guys that are a Browser issue? Because I run on a Raspberry Pi 3 on Ubuntu Mate an Angular 6 application on a Chromium, I'm thinking of changing the browser for a test.

来源:https://stackoverflow.com/questions/54246388/subscribing-to-a-simple-request-is-the-right-approach-on-angular-2-in-this-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!