100xdevs-cohort-2 / assignments

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

week-3 > 03-mongo > Readme.md | missing purchased property in Schema

piyush-ramnani opened this issue · comments

ISSUE:
In the POST route while registering the user, it is not specified that the user should have a third property as purchased of type array. As the user purchases the course, it should have a purchased property set while signing up where all the purchases would be saved.

User Routes

GET: /users/purchasedCourses
Description: Lists all the courses purchased by the user. Input: Headers: { 'username': 'username', 'password': 'password' } Output: { purchasedCourses: [ { id: 1, title: 'course title', description: 'course description', price: 100, imageLink: 'https://linktoimage.com/', published: true }, ... ] }

POST: /users/signup
Description: Creates a new user account. Input: { username: 'user', password: 'pass' } Output: { message: 'User created successfully' }


SOLUTION:

USER SCHEMA should be:

const UserSchema = new mongoose.Schema({
// Schema definition here
username: String,
password: String,
purchased: Array,
});

&&

POST: /users/signup
Description: Creates a new user account. Input: { username: 'user', password: 'pass' }
newUser = {
username: req.headers.username,
password: req.headers.password,
purchased: [],
}
Output: { message: 'User created successfully' }