util#isUndefined TypeScript Examples

The following examples show how to use util#isUndefined. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserController.ts    From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static newUser = async (req: Request, res: Response) => {
    let username = req.body.user;
    let password = req.body.password;
    let role = req.body.role;

    //    console.log(req.body)

    if (isUndefined(username)) {
      res.status(400).send("user missing");
      return;
    }
    if (isUndefined(password)) {
      res.status(400).send("password missing");
      return;
    }
    if (isUndefined(role)) {
      res.status(400).send("role missing");
      return;
    }

    let user = new User();
    user.name = username;
    user.password = password;
    user.role = role;

    const errors = await validate(user);
    if (errors.length > 0) {
      res.status(400).send(errors);
      return;
    }

    user.hashPassword();

    const userRepository = getRepository(User);
    try {
      await userRepository.save(user);
    } catch (e) {
      res.status(409).send("Username already in use");
      return;
    }

    res.status(201).send("User created");
  };