Skip to content

Commit

Permalink
backend initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
bholeneha committed Mar 9, 2023
1 parent 3b8c335 commit 4e600e5
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/node_modules
/.pnp
.pnp.js
.env
seed.js

# testing
/coverage
Expand All @@ -21,3 +23,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

9 changes: 9 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const mongoose = require('mongoose');

mongoose.connect(process.env.DATABASE_URL);

const db = mongoose.connection;

db.on('connected', function () {
console.log(`Connected to ${db.name} at ${db.host}:${db.port}`);
});
14 changes: 14 additions & 0 deletions models/category.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const categorySchema = new Schema({
name: { type: String, required: true },
// products: [
// {
// type: mongoose.Schema.Types.ObjectId,
// ref: "Product"
// }
// ]
});

module.exports = mongoose.model('Category', categorySchema);
20 changes: 20 additions & 0 deletions models/product.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const shadeSchema = new Schema({
name: { type: String, required: true },
categories: [{ type: Schema.Types.ObjectId, ref: 'Category' }],
size: { type: Number, required: true },
description: { type: String, required: true },
price: { type: Number }
})

const productSchema = new Schema({
name: { type: String, required: true },
categories: [{ type: Schema.Types.ObjectId, ref: 'Category' }],
size: { type: Number, required: true },
description: { type: String, required: true },
price: { type: Number, required: true, default: 0 }
});

module.exports = mongoose.model('Product', productSchema);
225 changes: 221 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4e600e5

Please sign in to comment.