How to use the http-status.CREATED function in http-status

To help you get started, we’ve selected a few http-status examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github danielfsousa / express-rest-es2017-boilerplate / src / api / controllers / auth.controller.js View on Github external
exports.register = async (req, res, next) => {
  try {
    const userData = omit(req.body, 'role');
    const user = await new User(userData).save();
    const userTransformed = user.transform();
    const token = generateTokenResponse(user, user.token());
    res.status(httpStatus.CREATED);
    return res.json({ token, user: userTransformed });
  } catch (error) {
    return next(User.checkDuplicateEmail(error));
  }
};
github SoftwareEngineeringDaily / software-engineering-daily-api / server / controllers / thread.controller.js View on Github external
create: async (req, res, next) => {
    try {
      const newThread = new Thread(req.body);
      newThread.author = req.user;

      await newThread.save();
      return res.status(httpStatus.CREATED).json(newThread);
    } catch (err) {
      return next(err);
    }
  },
  delete: async (req, res, next) => {
github IBM / taxinomitis / src / lib / restapi / models.ts View on Github external
return res.status(httpstatus.CONFLICT)
                        .send({
                            code: 'MLMOD14',
                            error: err.message,
                            location: err.location,
                        });
            }
            else {
                return errors.unknownError(res, err);
            }
        }
    }
    case 'numbers': {
        try {
            const model = await numbers.trainClassifier(req.project);
            return res.status(httpstatus.CREATED).json(returnNumberClassifier(model));
        }
        catch (err) {
            return errors.unknownError(res, err);
        }
    }
    case 'sounds':
        return errors.notImplemented(res);
    }
}
github hagopj13 / node-express-mongoose-boilerplate / src / controllers / user.controller.js View on Github external
const createUser = catchAsync(async (req, res) => {
  const user = await userService.createUser(req.body);
  res.status(httpStatus.CREATED).send(user.transform());
});
github connect-foundation / 2019-06 / server / src / v1 / users / controller.js View on Github external
const registerUser = async (req, res, next) => {
  let newUser;

  try {
    await validation.register(req.body);
    newUser = await service.register(req.body);
  } catch (error) {
    return next(error);
  }

  delete newUser.password;
  delete newUser.salt;
  delete newUser.imap_password;

  return res.status(status.CREATED).json({ newUser });
};
github kasvith / express-mongo-jwt-boilerplate / src / controllers / auth.controller.js View on Github external
exports.register = async (req, res, next) => {
  try {
    const activationKey = uuidv1()
    const body = req.body
    body.activationKey = activationKey
    const user = new User(body)
    const savedUser = await user.save()
    res.status(httpStatus.CREATED)
    res.send(savedUser.transform())
  } catch (error) {
    return next(User.checkDuplicateEmailError(error))
  }
}
github IBM / taxinomitis / src / lib / restapi / sessionusers.ts View on Github external
.then((user) => {
            return res.status(httpstatus.CREATED).json({
                id : user.id,
                token : user.token,
                sessionExpiry : user.sessionExpiry,
                jwt : auth.generateJwt(user),
            });
        })
        .catch((err) => {
github zenprotocol / explorer / server / components / api / transactions / transactionsController.js View on Github external
create: async function(req, res) {
    const transaction = await transactionsDAL.create(req.body);
    res.status(httpStatus.CREATED).json(jsonResponse.create(httpStatus.CREATED, transaction));
  },
  update: async function(req, res) {
github minhuyen / generator-expressjs-rest / generators / app / templates / backend / src / api / auth / auth.controller.js View on Github external
export const signup = async (req, res, next) => {
  try {
    const data = req.body;
    const result = await authService.signup(data);
    return Response.success(res, result, httpStatus.CREATED);
  } catch (exception) {
    next(exception);
  }
};
github EQuimper / nodejs-api-boilerplate / src / controllers / post.controller.js View on Github external
export async function create(req, res, next) {
  const body = filteredBody(req.body, contants.WHITELIST.posts.create);
  try {
    return res
      .status(HTTPStatus.CREATED)
      .json(await Post.createPost(body, req.user._id));
  } catch (err) {
    err.status = HTTPStatus.BAD_REQUEST;
    return next(err);
  }
}