Skip to content

Commit

Permalink
test: test profile picture endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniiairapetian committed Jun 1, 2024
1 parent 0277b56 commit aa96573
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const Anime = Models.Anime;
const TVseries = Models.TVseries;
const Users = Models.User;
require('dotenv').config();
const router = require('express').Router();

const { check, validationResult } = require('express-validator');
mongoose.connect(process.env.CONNECTION_URI, { useNewUrlParser: true, useUnifiedTopology: true });
// mongodb://localhost:27017/replaydb
Expand Down Expand Up @@ -772,6 +774,26 @@ app.delete("/users/:id/watched/:tvseries/:tvID", passport.authenticate('jwt', {
* @async
*/

router.route('/add').post(upload.single('photo'), async (req, res) => {
await Users.findOneAndUpdate({ Username: req.params.id }, {


$set:
{

photo: req.file.filename
}
},
{ new: true }) // This line makes sure that the updated document is returned
.then((updatedUser) => {
res.status(201).json(updatedUser);
})
.catch((err) => {
console.error(err);
res.status(500).send('Error: ' + err);
});
});

app.delete("/users/:id", passport.authenticate('jwt', { session: false }), async (req, res) => {
await Users.findOneAndRemove({ Username: req.params.id })
.then((user) => {
Expand Down

0 comments on commit aa96573

Please sign in to comment.