在api js中传递参数

问题描述 投票:1回答:1

我需要将登录和电子邮件传递给const validateUser,但我不知道我该怎么做

import { UserEntityModel } from './model';
const port: string = '3000';
const baseUrl: string = `http://localhost:${port}`;
const usersUrl: string = `${baseUrl}/users`;

在这里,我通过登录和电子邮件

export const validateUserInDB = ({login, email}: UserEntityModel): Promise<boolean> => {
 return fetch(usersUrl)
  .then(checkStatus)
  .then(parseJSON)
  .then(resolveUsers)
  .then(validateUser);
};

...

我需要在这里使用它

const validateUser = (data)  => {
  const userProfile = data.find((profile) =>
    profile.login.toUpperCase() === this.login.toUpperCase() ||
    profile.email.toUpperCase() === this.email.toUpperCase());
  return (userProfile !== void (0) && userProfile !== null);
};
javascript api typescript server
1个回答
0
投票

如果我理解正确,您将能够通过并使用如下登录/电子邮件:

export const validateUserInDB = ({login, email}: UserEntityModel): Promise<boolean> => {

 return fetch(usersUrl)
  .then(checkStatus)
  .then(parseJSON)
  .then(resolveUsers)
  .then(data => validateUser(data, {login, email})); // pass login/email explicitly
};

const validateUser = (data, {login, email})  => {
  const userProfile = data.find((profile) =>
    profile.login.toUpperCase() === login.toUpperCase() ||
    profile.email.toUpperCase() === email.toUpperCase());

  return (userProfile !== void (0) && userProfile !== null);
};

或者也许没有你喜欢的.then(data => validateUser(data, login, email));解构事件。

© www.soinside.com 2019 - 2024. All rights reserved.