值不是字符串 - StrongLoop

Value is not a String - StrongLoop

我正在使用强大的循环来创建 api。但它给我错误。我的 json 文件的属性是:

"properties": {
    "id": {
      "type": "Number"
    },
    "name": {
      "type": "string",
      "required": true
    },
    "language": {
      "type": "string",
      "required": false
    },
    "timezone": {
      "type": "string",
      "required": false
    },
    "labelId": {
      "type": "number",
      "required": false,
      "default": 0
    },
    "street": {
      "type": "string",
      "required": false
    },
    "contact": {
      "type": "number",
      "required": false
    },
    "maincontact": {
      "type": "number",
      "required": false
    },
    "visitorTypes": {
      "type": "array",
      "required": false
    },
    "activeVisitorAvatar": {
      "type": "boolean"
    },
    "activeLegalDocument": {
      "type": "boolean"
    },
    "legalDocuments": {
      "type": "array"
    },
    "logo": {
      "type": "string",
      "required": false
    },
    "logoType": {
      "type": "string",
      "required": false
    },
    "logoSmall": {
      "type": "string",
      "required": false
    },
    "logoSmallType": {
      "type": "string",
      "required": false
    },
    "activeSignOut": {
      "type": "boolean"
    },
    "activePrint": {
      "type": "boolean"
    },
    "activeScanTemperature": {
      "type": "boolean"
    },
    "printerIp": {
      "type": "string"
    },
    "activeVoicePrompt": {
      "type": "boolean"
    },
    "mandatoryCompanyName": {
      "type": "boolean"
    },
    "mandatoryPhoneNumber": {
      "type": "boolean"
    },
    "sliders": {
      "type": "array"
    },
    "slidersCount": {
      "type": "number"
    },
    "accountId": {
      "type": "number"
    },
    "visitorsignouttime": {
      "type": "number"
    },
    "signoutLink": {
      "type": "boolean"
    },
    "signoutnotification": {
      "type": "boolean"
    },
    "deviceofflinenotification": {
      "type": "boolean"
    },
    "deviceonlinenotification": {
      "type": "boolean"
    },
    "emergencyAlert": {
      "type": "object"
    },
    "autoSignOut": {
      "type": "boolean"
    },
    "signOutTime": {
      "type": "string"
    },
    "signOutPin": {
      "type": "boolean"
    },
    "questionsEnabled": {
      "type": "boolean"
    },
    "questions": {
      "type": "array"
    },
    "logicalQuestionnaire": {
      "type": "array"
    },
    "isEnableTemperatureCheck": {
      "type": "boolean"
    },
    "disableTemperatureCheckScreen": {
      "type": "boolean"
    },
    "isEnableQrCodeWithPinInside": {
      "type": "boolean"
    },
    "isEnableComplianceAlerts": {
      "type": "boolean"
    },
    "alertsWatchlistPriority": {
      "type": "number"
    },
    "alertsCompliancePriority": {
      "type": "number"
    },
    "eventNames": {
      "type": "array"
    },
    "rooms": {
      "type": "array"
    },
    "selfie": {
      "type": "boolean"
    },
    "displayCompany": {
      "type": "boolean"
    },
    "pagination": {
      "type": "boolean"
    }
  },

我的body如下:

let body = JSON.stringify({
      id,
      name,
      street,
      timezone: this.timezone,
      activeVisitorAvatar,
      activeLegalDocument,
      legalDocuments,
      visitorTypes,
      activeSignOut,
      activeScanTemperature,
      activePrint,
      printerIp,
      labelId,
      activeVoicePrompt,
      mandatoryCompanyName,
      mandatoryPhoneNumber,
      mandatoryAnswersToQuestions,
      visitorsignouttime,
      signoutLink,
      signoutnotification,
      deviceofflinenotification,
      deviceonlinenotification,
      emergencyMessages: this.getEmergencyMessages(),
      address: this.address,
      autoSignOut,
      signOutTime,
      signOutPin,
      questionsEnabled,
      questions: this.getQuestions(),
      logicalQuestionnaire: this.getLogicalQuestionnaire(),
      accountId,
      isEnableRememberMeForFullUIFlow,
      isEnableTemperatureCheck,
      isEnableQrCodeWithPinInside,
      isEnableComplianceAlerts,
      alertsWatchlistPriority,
      alertsCompliancePriority,
      selfie,
      displayCompany,
      temperatureThreshold: {
        maximum: Number(temperatureMax),
        minimum: Number(temperatureMin),
        displayTextFormat: this.curr.temperatureThreshold.displayTextFormat,
      },
      pagination,
      gdpr: {
        isActive: this.curr.gdpr.isActive,
        days: gdprDays,
      },
      purposes /*filter(purposes, (item) => item.id)*/,
      isEnableIfThenQuestionnaire: isEnableIfThenQuestionnaire,
      visitorQueueDisplay,
      autoRefreshEntries: { enabled: autoRefreshEntries, interval: Number(autoRefreshEntriesInterval) },
      visitor_email,
    });

但是我收到错误消息{"error":{"statusCode":400,"name":"Error","message":"Value is not a string.","stack":"Error: Value is not a string.\n at Object.validate

我卡在这里了!已尝试更改 json 文件中的数据类型但无济于事,也无法判断是哪个参数导致了错误。所有值都来自前端 html 和 angular。我的依赖项如下:

"loopback": "^3.0.0",
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^2.4.0",
"loopback-component-storage": "^3.0.0",
"loopback-connector-mongodb": "3.0.1",

我正在进行的网络请求调用是:

try {
      this.http
        .post('/api/sites/edit?access_token=' + this.token, body, {
          headers: contentHeaders,
        })
        .subscribe(
          (response) => {
            this.hideFlag = true;
            this.toastr.success('Saved!');
            this.http
              .post(
                'api/users/setFeaturesByAccountId',
                {},
                {
                  params: {
                    access_token: this.token,
                    listFeatures: this.listFeature,
                    accountId: this.curr.accountId,
                  },
                },
              )
              .subscribe();
          },
          (error) => {
            this.hideFlag = true;
            this.toastr.error('Error');
            this.showError = error.json().error;
            console.log(error.text());
          },
        );
    } catch (error) {
      console.log(error);
    }

所以错误是 loopback 3 类型转换不正确。我必须检查哪个变量没有正确转换,然后在我的中间件中进行相应的解析。

if(req.body.accountId){
    var numberId = parseInt(req.body.accountId);
    req.body.accountId = numberId;
}

这不是一个完美的解决方案,而是一种变通方法!