Zum Inhalt springen

basiC

Mitglieder
  • Gesamte Inhalte

    1
  • Benutzer seit

  • Letzter Besuch

  1. Hi Ich kann normal einen Post erstellen. Ich erstelle es mit einem Autorisierungs-JWT-Token, mein Forum Schema hat ein CreatedBy Attribut, sodass in meinem Token auch meine userID enthalten ist. Ich möchte nur wissen, wie ich mit JWT Token einmal alle Posts finden kann, die von Admin erstellt wurden und zweitens, die von einem anderen Benutzer erstellt wurden. Ich habe zwei HTTP-Anfragen. Zuerst: GET http://localhost:8080/forum/getpostsadmin Authorization: Bearer {token} exports.getByToken = async(req,res) => { Forum.find({_id: req.params._id}, function(err, docs) { if (err) { res.json(err); } else { res.json(docs); } }); }; GET http://localhost:8080/forum/getOwner Authorization: Bearer {token} Content-Type: application/json { "ownerID": "another User" } exports.getByOwnerID = async (req, res, next) => { Forum.find({ createdBy: req.body.createdBy }) .then(doc => { if(!doc) { return res.status(400).end();} return res.status(200).json(doc); }) .catch(err => next(err)); } Forum Schema: const forumSchema = ({ forumName: { type: String, required: true, }, forumDescription: { type: String, required: true, }, createdBy: { type: Schema.Types.ObjectId, ref: 'User' }, published_on: { type: String, default: moment().format("LLL") }, }); Falls weitere Fragen offen sind würde ich SIe beantworten.

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...