我需要将登录和电子邮件传递给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);
};
如果我理解正确,您将能够通过并使用如下登录/电子邮件:
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));
解构事件。