在这种情况下,订阅简单的请求对Angular 2是正确的方法吗?

时间:2019-01-18 00:56:30

标签: javascript angular laravel rxjs

我有一个用于后端的Angular 6 + Laravel停车系统,我有一个帖子,我张贴了一些由DigitalDrifter解决的问题,谢谢。

以下是链接:How to Make a Scheduler Task for Every New Record After 20 Minutes in Laravel?

我的系统不是100%良好,因为我的行为异常。每个客户都必须去付款区并确认您的输入。当客户向收银员出示票证时,他在付款后单击名为“验证票证”的按钮来验证该条目

我的代码在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();
        });

        }


    });


  }

这是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 });

  }

这是laravel的后端,这是代码:

  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]); 

    }

去Laravel时,我得到条目EAN_13代码,$ value和$ userid(收银员用户),并在表上进行更新并验证条目,   客户有30分钟的时间外出。

问题是85%的用户通过了验证,但15%的用户没有通过验证,收银员总是说他们总是单击按钮进行验证。一些客户付款,何时付款   他会出门退出,不要让他们走,当我拿票并测试时,他没有通过验证。

我缺少什么?不是人为错误,每个人都单击按钮。我不知道这是什么问题,因为当用户单击Angular上的(response.success!= 0)时,当用户单击时,我会返回一个框,上面写着“输入有效”。

我这样做是为了检查用户是否可以通过某些测试。现在我的问题是这是否是订阅的正确方法?你们是否认为每次他单击他要执行的按钮并提出请求?还是不?抱歉,这是一个非常菜鸟般的问题,但是我想100%地完成这项工作,所以我尝试了一下,并没有收到任何错误。

您认为是浏览器问题的人吗?因为我在Ubuntu上的Raspberry Pi 3上运行,并在Chromium上使用Angular 6应用程序,所以我正在考虑更改浏览器以进行测试。

0 个答案:

没有答案