Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //tworzenie
- router.post('/', (req, res, next) => {
- Photo.findById(req.body.photoId)
- .then(photo => {
- if (!photo) {
- return res.status(404).json({
- message: "Photo not found"
- });
- }
- const user = new User({
- _id: new mongoose.Types.ObjectId(),
- name: req.body.name,
- email: req.body.email,
- password: req.body.password,
- photo: req.body.photoId, //wpisuje photoId w Body w postmanie
- });
- return user.save();
- })
- .then(result => {
- console.log(result);
- res.status(201).json({
- message: 'Post user',
- createdUser: {
- _id: result._id,
- name: result.name,
- email: result.email,
- password: result.password,
- photo: result.photo,
- },
- request: {
- type: "GET",
- url: 'http://localhost:3000/user/' + result._id
- }
- });
- })
- .catch(err => {
- console.log(err);
- res.status(500).json({
- error: err
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement