Express和mongodb(中间值)不是构造函数

时间:2018-11-26 00:20:18

标签: mongodb express react-native redux

我正在尝试在数据库中注册一个新用户。 我也为此使用了redux。

我对错误消息所指示的问题感到困惑。 我遇到500服务器错误,该行应该遵循吗?:

'(中间值)不是构造函数'

为了使您对可能发生的位置有更深入的了解,我粘贴了代码的一些重要部分,这些部分启动了导致此情况的事件序列。

这是我的动作:

 accountApi.register(
  email,
  password,
  firstName,
  lastName,
  (errObj, resObj) => {
    if (errObj) {
      return dispatch({
        type: REGISTER_USER_FAILED,
        payload: new Error(errObj.detail)
      });
    }

    const { token } = resObj;

    storage.save(JWT_TOKEN, token, err => {
      if (err) {
        return dispatch({
          type: REGISTER_USER_FAILED,
          payload: err
        });
      }

      return dispatch({
        type: REGISTER_USER_SUCCESS,
        payload: true
      });
    });
  }
);

这是api路线:

const body = {
email,
password,
firstName,
lastName,
date: today,
};
  const ROUTE = "register";
  const url = BASE_ROUTE + ROUTE;
  client.post({ url, body }, cb);
}

内部API:

async function register(req, res) {
req.checkBody('email').notEmpty().isEmail();
req.checkBody('password')
.notEmpty()
.isAscii()
.isLength({ min: 8 });
req.checkBody('firstName')
.notEmpty()
.isAscii()
.isLength({ min: 3, max: 15 });
req.checkBody('lastName')
.notEmpty()
.isAscii()
.isLength({ min: 3, max: 15 });
 });

 const validationErrors = await req.getValidationResult();
 if (!validationErrors.isEmpty()) {
  return res.status(400).send(responses.validatorResponse(validationErrors));
 }

 const { email, password, firstName, lastName } = req.body;
 const userDoc = await accountManager.register(email, password, firstName, 
 lastName, false);
 return res.status(200).send({ token: jwtHelper.createToken(userDoc) });
 }

在帐户管理员中:

async function register(email, password, firstName, lastName, isAdmin) {
  const associationDoc = await Association.getDocumentByEmail(email);

  if (!associationDoc) {
    throw new new Error('Unable to register user. User is not associated with 
any organization yet.')();
  }

  const teamDoc = await 
Team.getDefaultTeamForOrganization(associationDoc.organizationId);
 const hashedPassword = account.hashPassword(password);

  const data = {
    firstName: firstName.toLowerCase(),
    lastName: lastName.toLowerCase(),
    email,
    isAdmin,
    fullName: `${firstName.toLowerCase()} ${lastName.toLowerCase()}`,
    teamId: teamDoc._id,
    hashedPassword,
    registrationStatus: REGISTRATION_STATUSES.NEW_REGISTRATION,
    lastSeen: dates.today(),
  };

  return User.create(data);
}

内部用户模型:

async function create(data) { return new Model(data).save(); }

我使用邮差发送带有所有正确信息的api调用,但我不断收到此错误消息:

(中间值)不是构造函数

0 个答案:

没有答案