簡體   English   中英

在api js中傳遞參數

[英]pass parameters in api js

我需要將登錄名和電子郵件傳遞給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)); 隨便你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM