小编Ant*_*chd的帖子

Sequelize - 用不是Sequelize.Model子类的东西调用

我正在开发应用程序但是我使用Node.js和Sequelize for Postgresql有这个问题:

      throw new Error(this.name + '.' + Utils.lowercaseFirst(Type.toString()) + ' called with something that\'s not a subclass of Sequelize.Model');
      ^

Error: Expense.class BelongsTo extends Association {
  constructor(source, target, options) {
    super(source, target, options);

    <....LOT OF CODE FROM SEQUELIZE ....>

    if ((fieldsOrOptions || {}).transaction instanceof Transaction) {
      options.transaction = fieldsOrOptions.transaction;
    }
    options.logging = (fieldsOrOptions || {}).logging;

    return association.target.create(values, fieldsOrOptions).then(newAssociatedObject =>
      sourceInstance[association.accessors.set](newAssociatedObject, options)
    );
  }
} called with something that's not a subclass of Sequelize.Model
Run Code Online (Sandbox Code Playgroud)

我不明白这个错误,尤其是最后一行"使用不是Sequelize.Model的子类的东西调用".这是模型:

用户模型

const models = …
Run Code Online (Sandbox Code Playgroud)

node.js sequelize.js

8
推荐指数
1
解决办法
2810
查看次数

Mapbox gl&directions API调用 - 不显示路由

我有一个带有多个标记的应用程序,用于显示旅行.每个标记都是一个步骤,我想在每个标记之间创建一条路径,跟随标记(下一步).

为此,我现在有这个代码:

$(document).ready(function() {
  var map;
  var directions;

  // token access for MAPBOX GL
  mapboxgl.accessToken = 'pk.eyJ1IjoiYW50b3RvIiwiYSI6ImNpdm15YmNwNTAwMDUyb3FwbzlzeWluZHcifQ.r44fcNU5pnX3-mYYM495Fw';

  // generate map
  var map = new mapboxgl.Map({
    container: 'map',
    style: 'mapbox://styles/mapbox/streets-v10',
    center: [-96, 37.8],
    zoom: 5
  });

  // center map on selected marker
  map.on('click', 'markers', function (e) {
    map.flyTo({center: e.features[0].geometry.coordinates});
  });

  // change mouse action on enter / leave in marker
  map.on('mouseenter', 'markers', function () {
    map.getCanvas().style.cursor = 'pointer';
  });

  map.on('mouseleave', 'markers', function () {
    map.getCanvas().style.cursor = '';
  });

  $.ajax({
    dataType: 'json', …
Run Code Online (Sandbox Code Playgroud)

javascript mapbox mapbox-gl-js

5
推荐指数
1
解决办法
709
查看次数

Node Express和pg-promise-db.any不是函数

我有这个错误:

TypeError: db.any is not a function
Run Code Online (Sandbox Code Playgroud)

我正在使用带有pg-promise和express的节点JS。这是query.js文件(db):

const promise = require('bluebird');

var options = {
    promiseLib: promise
};

var pgp = require('pg-promise')(options);
var connectionString = 'postgres://localhost:5432/spendy';
var db = pgp(connectionString);

console.log('connexion ok');
Run Code Online (Sandbox Code Playgroud)

控制器:

const db = require('../queries');

module.exports = {
    getAllUsers: function(req, res, next) {
        db.any('select * from users')
            .then((data) => {
                res.status(200)
                    .json({
                        status: 'success',
                        data: data,
                        message: 'Retrieve all users'
                    });
            })
            .catch((err) => {
                console.log(err);
                return next(err);
            });
    }
}
Run Code Online (Sandbox Code Playgroud)

和路由文件:

var express = require('express');
var …
Run Code Online (Sandbox Code Playgroud)

postgresql node.js express bluebird pg-promise

3
推荐指数
1
解决办法
1319
查看次数

节点js JWT获取当前用户

我在使用API​​的Node JS,JWT和Sequelize进行身份验证的应用程序上工作,而我在前端使用React JS / redux。我已经成功实现了该应用程序的登录/注销/注册部分,但是现在我需要访问已登录的current_user。

我在本地存储中放置了一个JWT,但是我想访问用户ID,用户电子邮件,用户名以及有关当前登录用户的更多信息。

我应该使用Cookies吗?LocalStorage?还是应该在API中创建currentUser方法?

如果有人可以帮助我找到一些有用的资源或建议,我会感到迷茫!

谢谢 !

node.js jwt

2
推荐指数
1
解决办法
2660
查看次数

使用同步 StepFunctions 处理 API Gateway 中的错误

我正在开发一个具有以下工作流程的项目:API 网关(使用开放 api 定义)触发来自 AWS 的 Step 函数。有 2 个步骤,如果出现错误,状态机定义中有一个 catch 块。

但我面临错误处理的问题。即使我的代码抛出错误(例如 400),我的 Postman(或其他 REST API 测试工具)也会响应 200。我想要 500/400...

这是代码:

Step 函数定义为无服务器

stepFunctions:
  stateMachines:
    PostPayment:
      name: testfunction
      type: EXPRESS
      definition:
        Comment: 'test'
        StartAt: Function1
        States:
          Function1:
            Type: Task
            Resource: !GetAtt Function1.Arn
            Catch:
              - ErrorEquals: ['HandledError']
                Next: Fallback
            Next: Function2
          Function2:
            Type: Task
            Resource: !GetAtt Function2.Arn
            Catch:
              - ErrorEquals: ['HandledError']
                Next: Fallback
            End: true
          Fallback:
            Type: Fail
            Cause: "Error occured",
            Error: "Error"
Run Code Online (Sandbox Code Playgroud)

这是我的 openapi yml

x-amazon-apigateway-request-validator: all
x-amazon-apigateway-integration:
  requestParameters:
    integration.request.path.id: …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-api-gateway openapi aws-step-functions

1
推荐指数
1
解决办法
1763
查看次数

Ruby on rails - 没有找到InvitesController #create的模板

我想用rails 5和mongoid创建一个邀请系统.但是,当我想发送电子邮件时,我有这个错误:

Recipient can't be blank
something goes wrong
Recipient can't be blank
No template found for InvitesController#create, rendering head :no_content
Completed 204 No Content in 137ms
Run Code Online (Sandbox Code Playgroud)

这是代码:

invite.rb

class Invite
  include Mongoid::Document
  include Mongoid::Timestamps

  field :email, type: String
  field :token, type: String

  belongs_to :project
  belongs_to :sender_id, :class_name => 'User', inverse_of: :recipient_id
  belongs_to :recipient_id, :class_name => 'User', inverse_of: :sender_id

  before_create :generate_token

  def generate_token
    self.token = Digest::SHA1.hexdigest([self.project_id, Time.now, rand].join)
  end
end
Run Code Online (Sandbox Code Playgroud)

project.rb

class Project
  include Mongoid::Document
  include Mongoid::Timestamps

  # Principle informations …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

0
推荐指数
1
解决办法
3546
查看次数