Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
Empty file added .gitignore
Empty file.
3 changes: 3 additions & 0 deletions config/config.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
NODE_ENV = development
PORT = 8080
MONGO_URI = mongodb+srv://selimzr:[email protected]/Assignment?retryWrites=true&w=majority
20 changes: 20 additions & 0 deletions config/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Our connection with database

const mongoose = require('mongoose');

const connectDB = async () => {
try {
const conct = await mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true
});

console.log(`MongoDB Connected: ${conct.connection.host}`);
} catch (err) {
console.log(`Error: ${err.message}`);
process.exit(1);
}
}

module.exports = connectDB;
14 changes: 14 additions & 0 deletions middlewares/verifyToken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const jwt=require("jsonwebtoken");
const secret=process.env.SECRET || 'secret';

const verifyToken = (req, res, next) => {
try {
let decodedToken=jwt.verify(req.get('Authorization'), secret);
req.decodedToken=decodedToken;
next();
} catch (error) {
res.status(401).send({status:401,message:"Unauthorized"});
}
}

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

const categorySchema=mongoose.Schema({
name:String,
user_id:{
type:mongoose.Schema.Types.ObjectId,
ref:'users'
},
createdAt:{
type:Date,
default:Date.now()

},
updatedAt:{
type:Date,
default:Date.now()
}


})

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

const itemSchema=mongoose.Schema({

name:String,
user_id:{
type:mongoose.Schema.Types.ObjectId,
ref:'users'

},
category_id:{
type:mongoose.Schema.Types.ObjectId,
ref:'categorys'
},
note:String


,
image:String,

createdAt:{
type:Date,
default:Date.now()

},
updatedAt:{
type:Date,
default:Date.now()
}
});

module.exports=mongoose.model('item',itemSchema)
23 changes: 23 additions & 0 deletions models/list.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const mongoose=require('mongoose');

const listSchema=mongoose.Schema({
name:{
type:String,
required:true
},
user_id:{
type:mongoose.Schema.Types.ObjectId,
ref:'users'
},
createdAt:{
type:Date,
default:Date.now()
},
updatedAt:{
type:Date,
default:Date.now()
},
items:[{type:mongoose.Schema.Types.ObjectId,ref:'items'}]

})
module.exports=mongoose.model('list',listSchema);
22 changes: 22 additions & 0 deletions models/user.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// user datamodel

const mongoose = require("mongoose");

const userSchema=new mongoose.Schema({
email: {
type: String,
required: true,
unique: true,
trim: true,
lowercase: true,
},

password: {
type: String,
required: true,
trim: true,
},
userName: { type: String, required: true, trim: true },
});

module.exports=mongoose.model('user',userSchema);
15 changes: 15 additions & 0 deletions node_modules/.bin/detect-libc

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

17 changes: 17 additions & 0 deletions node_modules/.bin/detect-libc.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/detect-libc.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/is-ci

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

17 changes: 17 additions & 0 deletions node_modules/.bin/is-ci.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/is-ci.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/mime

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

17 changes: 17 additions & 0 deletions node_modules/.bin/mime.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/mime.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/mkdirp

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

17 changes: 17 additions & 0 deletions node_modules/.bin/mkdirp.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/mkdirp.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/node-pre-gyp

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

17 changes: 17 additions & 0 deletions node_modules/.bin/node-pre-gyp.cmd

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

Loading