-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f0a706
commit 17325f6
Showing
106 changed files
with
361 additions
and
363 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
const User = require("../model/user"); | ||
const User = require('../model/user'); | ||
|
||
module.exports.login = (req, res) => { | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
const username = req.body.username; | ||
const password = req.body.password; | ||
|
||
if (username && password) { | ||
User.findOne({ | ||
username, | ||
}) | ||
.then((user) => { | ||
if (!user) { | ||
res.json({ | ||
status: "Error", | ||
msg: "username or password is incorrect", | ||
}); | ||
} else { | ||
res.json({ | ||
token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
} | ||
if (username && password) { | ||
User.findOne({ | ||
username, | ||
}) | ||
.then((user) => { | ||
if (!user) { | ||
res.status(401).json({ | ||
status: 'Error', | ||
msg: 'username or password is incorrect', | ||
}); | ||
} else { | ||
res.json({ | ||
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9', | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,110 @@ | ||
const Cart = require('../model/cart') | ||
const Cart = require('../model/cart'); | ||
|
||
module.exports.getAllCarts = (req,res) => { | ||
const limit = Number(req.query.limit) || 0 | ||
const sort = req.query.sort=="desc"?-1:1 | ||
const startDate = req.query.startdate || new Date('1970-1-1') | ||
const endDate = req.query.enddate || new Date() | ||
module.exports.getAllCarts = (req, res) => { | ||
const limit = Number(req.query.limit) || 0; | ||
const sort = req.query.sort == 'desc' ? -1 : 1; | ||
const startDate = req.query.startdate || new Date('1970-1-1'); | ||
const endDate = req.query.enddate || new Date(); | ||
|
||
console.log(startDate,endDate) | ||
|
||
Cart.find({ | ||
date:{ $gte:new Date(startDate), $lt:new Date(endDate)} | ||
}) | ||
.select('-_id -products._id') | ||
.limit(limit) | ||
.sort({id:sort}) | ||
.then(carts=>{ | ||
res.json(carts) | ||
}) | ||
.catch(err=>console.log(err)) | ||
} | ||
console.log(startDate, endDate); | ||
|
||
Cart.find({ | ||
date: { $gte: new Date(startDate), $lt: new Date(endDate) }, | ||
}) | ||
.select('-_id -products._id') | ||
.limit(limit) | ||
.sort({ id: sort }) | ||
.then((carts) => { | ||
res.json(carts); | ||
}) | ||
.catch((err) => console.log(err)); | ||
}; | ||
|
||
module.exports.getCartsbyUserid = (req,res) => { | ||
const userId = req.params.userid | ||
const startDate = req.query.startdate || new Date('1970-1-1') | ||
const endDate = req.query.enddate || new Date() | ||
module.exports.getCartsbyUserid = (req, res) => { | ||
const userId = req.params.userid; | ||
const startDate = req.query.startdate || new Date('1970-1-1'); | ||
const endDate = req.query.enddate || new Date(); | ||
|
||
console.log(startDate,endDate) | ||
Cart.find({ | ||
userId, | ||
date:{ $gte:new Date(startDate), $lt:new Date(endDate)} | ||
}) | ||
.select('-_id -products._id') | ||
.then(carts=>{ | ||
res.json(carts) | ||
}) | ||
.catch(err=>console.log(err)) | ||
} | ||
console.log(startDate, endDate); | ||
Cart.find({ | ||
userId, | ||
date: { $gte: new Date(startDate), $lt: new Date(endDate) }, | ||
}) | ||
.select('-_id -products._id') | ||
.then((carts) => { | ||
res.json(carts); | ||
}) | ||
.catch((err) => console.log(err)); | ||
}; | ||
|
||
module.exports.getSingleCart = (req,res) => { | ||
const id = req.params.id | ||
Cart.findOne({ | ||
id | ||
}) | ||
.select('-_id -products._id') | ||
.then(cart => res.json(cart)) | ||
.catch(err=> console.log(err)) | ||
} | ||
module.exports.getSingleCart = (req, res) => { | ||
const id = req.params.id; | ||
Cart.findOne({ | ||
id, | ||
}) | ||
.select('-_id -products._id') | ||
.then((cart) => res.json(cart)) | ||
.catch((err) => console.log(err)); | ||
}; | ||
|
||
module.exports.addCart = (req,res) => { | ||
if (typeof req.body == undefined) { | ||
res.json({ | ||
status: "error", | ||
message: "data is undefined" | ||
}) | ||
} else { | ||
console.log(req.body.date) | ||
let cartCount = 0; | ||
Cart.find().countDocuments(function (err, count) { | ||
cartCount = count | ||
}) | ||
module.exports.addCart = (req, res) => { | ||
if (typeof req.body == undefined) { | ||
res.json({ | ||
status: 'error', | ||
message: 'data is undefined', | ||
}); | ||
} else { | ||
// let cartCount = 0; | ||
// Cart.find().countDocuments(function (err, count) { | ||
// cartCount = count | ||
// }) | ||
|
||
.then(() => { | ||
const cart = new Cart({ | ||
id: cartCount + 1, | ||
userId: req.body.userId, | ||
date:req.body.date, | ||
products:req.body.products | ||
}) | ||
// cart.save() | ||
// .then(cart => res.json(cart)) | ||
// .catch(err => console.log(err)) | ||
// .then(() => { | ||
const cart = { | ||
id: 11, | ||
userId: req.body.userId, | ||
date: req.body.date, | ||
products: req.body.products, | ||
}; | ||
// cart.save() | ||
// .then(cart => res.json(cart)) | ||
// .catch(err => console.log(err)) | ||
|
||
res.json(cart) | ||
}) | ||
res.json(cart); | ||
// }) | ||
|
||
//res.json({...req.body,id:Cart.find().count()+1}) | ||
} | ||
} | ||
//res.json({...req.body,id:Cart.find().count()+1}) | ||
} | ||
}; | ||
|
||
|
||
module.exports.editCart = (req,res) => { | ||
if (typeof req.body == undefined || req.params.id == null) { | ||
res.json({ | ||
status: "error", | ||
message: "something went wrong! check your sent data" | ||
}) | ||
} else { | ||
res.json({ | ||
id:req.params.id, | ||
userId: req.body.userId, | ||
date:req.body.date, | ||
products:req.body.products | ||
}) | ||
} | ||
} | ||
module.exports.editCart = (req, res) => { | ||
if (typeof req.body == undefined || req.params.id == null) { | ||
res.json({ | ||
status: 'error', | ||
message: 'something went wrong! check your sent data', | ||
}); | ||
} else { | ||
res.json({ | ||
id: req.params.id, | ||
userId: req.body.userId, | ||
date: req.body.date, | ||
products: req.body.products, | ||
}); | ||
} | ||
}; | ||
|
||
module.exports.deleteCart = (req, res) => { | ||
if (req.params.id == null) { | ||
res.json({ | ||
status: "error", | ||
message: "cart id should be provided" | ||
}) | ||
} else { | ||
Cart.findOne({id:req.params.id}) | ||
.select('-_id -products._id') | ||
.then(cart=>{ | ||
res.json(cart) | ||
}) | ||
.catch(err=>console.log(err)) | ||
} | ||
} | ||
if (req.params.id == null) { | ||
res.json({ | ||
status: 'error', | ||
message: 'cart id should be provided', | ||
}); | ||
} else { | ||
Cart.findOne({ id: req.params.id }) | ||
.select('-_id -products._id') | ||
.then((cart) => { | ||
res.json(cart); | ||
}) | ||
.catch((err) => console.log(err)); | ||
} | ||
}; |
Empty file.
Oops, something went wrong.