WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

another classic emily issue! no idea!!! #19

Closed emilybarwinczak closed 2 years ago

emilybarwinczak commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

ana and i have the SAME code and this is the error i'm getting when trying to post a review in postman

Post any code you think might be relevant (one fenced block per file)

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

image

What is your best guess as to the source of the problem?

What things have you already tried to solve the problem?

timmshinbone commented 2 years ago

Share your models and the body of your postman reqeust

emilybarwinczak commented 2 years ago

models/destination.js

const mongoose = require('mongoose')
const businessSchema = require('./business')
const reviewSchema = require('./review')
const Schema = mongoose.Schema

const destinationSchema = new Schema(
    {
        city: {
            type: String,
            required: true,
        },
        state: {
            type: String,
        },
        country: {
            type: String,
        },
        lgbtRating: {
            type: Number
        },
        image_url: String,
        description: String,
        owner: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        },
        business: [businessSchema],
        reviews: [reviewSchema],
        roadGoatId: {
            type: String
        }
    },
    {
        timestamps: true,
    }
)

module.exports = mongoose.model('Destination', destinationSchema)

models/review.js

const mongoose = require('mongoose')
const Schema = mongoose.Schema

const reviewSchema = new Schema(
    {
        // want to create a refernece  to the username by the objectId
        username: {
            type: Schema.Types.ObjectId,
            ref: 'user'
        },
        body: String,
    },
    {
        timestamps: true
    }
)

module.exports = reviewSchema

postman request to post a review:

{
    "review" : {
        "username": "louieisadog",
        "body": "i love this place"
        }
}
timmshinbone commented 2 years ago

ok cool, so, the data type your review's username is looking for is the id of a user, not a string of their username which is what you're sending via postman

emilybarwinczak commented 2 years ago

so I had been comparing mine to Ana's and theirs was working but turns out it was because their username was 12 characters... womp ok thank you goodbye!!!