Open ArfatSalman opened 3 years ago
Return the products filtered by categories and other filter criteria (rating, brands, etc...)
We are using MongoDB Atlas as our DB service. We have integrated MongoDB atlas with our API and created new set routes. We are using v1 for the new API routes e.g. https://little-tags-pesto.herokuapp.com/v1/products
We have the following collections defined in our database:
const ProductSchema = new Schema({
title: {
type: String,
required: true,
},
image: {
type: String,
required: true,
},
brand: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
rating: Number,
noOfReview: Number,
stock: Number,
features: [
{
type: {
type: String,
required: true,
},
value: [String],
},
],
gallery: [
{
title: {
type: String,
required: true,
},
image: {
type: String,
required: true,
},
},
],
originalPrice: Number,
currentPrice: Number,
offer: Number,
currency: {
type: String,
enum: ['INR', 'USD'],
default: 'INR',
},
category: {
name: {
type: String,
required: true,
},
categoryId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Category',
},
},
});
const CategorySchema = Schema(
{
name: {
type: String,
required: true,
},
image: {
type: String,
},
description: {
type: String,
},
},
{
timestamps: true,
}
);
const OrderSchema = Schema(
{
status: {
type: String,
required: true,
enum: ['active', 'processing', 'complete'],
},
modifiedOn: { type: Date, default: Date.now },
products: [
{
productId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
},
quantity: {
type: Number,
required: true,
},
name: String,
price: Number,
},
],
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User',
},
shippingAddress: {
id: 1,
fullName: { type: String, required: true },
mobileNumber: { type: String, required: true },
address: { type: String, required: true },
state: { type: String, required: true },
city: { type: String, required: true },
pin: { type: Number, required: true },
},
paymentMethod: {
type: String,
required: true,
},
paymentResult: {
id: { type: String },
status: { type: String },
update_time: { type: String },
email_address: { type: String },
},
shippingPrice: {
type: Number,
required: true,
default: 0.0,
},
totalPrice: {
type: Number,
required: true,
default: 0.0,
},
isPaid: {
type: Boolean,
required: true,
default: false,
},
paidAt: {
type: Date,
},
isDelivered: {
type: Boolean,
required: true,
default: false,
},
deliveredAt: {
type: Date,
},
},
{
timestamps: true,
}
);
const UserSchema = Schema(
{
username: {
type: String,
required: true,
},
password: {
type: String,
required: true,
},
lastName: {
type: String,
required: true,
},
firstName: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
},
{ timestamps: true }
);
We still need to work upon the user schema to add wishlist and cart properties.
Instructions
Since you have built the frontend, and you have used fake data till now, now is the time to decide what data your database will store and what the shape of the data is going be.
For this issue, you have to decide on which type DB to use (for ex - SQL / Mongo / Neo4J etc) and what tables (or collections) you app is going to have. Apart from that, also describe the fields of the tables and their types. Ensure to list down constraints such as Foreign Key. In short, you have
Since the back-end is an REST-based service, what URLs will your backend expose? Try to write all the end points and how many HTTP verbs they support.
Requirements
Resources
Please ensure that you read these articles well.