forked from Ayesiza/api-invetory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Ayesiza#8 from Ayesiza/ft-updateStock-172690897
#172690897:Ft update stock
- Loading branch information
Showing
19 changed files
with
258 additions
and
123 deletions.
There are no files selected for viewing
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,11 +1,2 @@ | ||
.env | ||
node_modules | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
const Category = require("../models/categories"); | ||
const { Schema } = require('mongoose'); | ||
|
||
|
||
|
||
module.exports = { | ||
addCategory:(req, res) => { | ||
|
||
const {categoryName , description} = req.body | ||
const newCategory = new Category({categoryName , description}) | ||
newCategory.save() | ||
.then((category) =>{ | ||
if(category) { | ||
return res.status(201).json({message:'add Category', newCategory}) | ||
} | ||
}) | ||
.catch((error) =>{ | ||
console.log(error) | ||
}); | ||
|
||
}, | ||
|
||
allCategory:(req, res)=> { | ||
Category.find({}).then((category)=> { | ||
if(category) { | ||
return res.status(200).json({category}); | ||
}else{ | ||
return res.status(400).json({ message: "No category found" }); | ||
} | ||
}); | ||
}, | ||
|
||
specificCategory:(req,res) =>{ | ||
Category.findById(req.params.id).then((category)=>{ | ||
if(category){res.json({status:200, message:'category Found',category}) | ||
|
||
}else{ | ||
return res.status(404).json({status:404, message:'Category of specific id not found'}) | ||
} | ||
}) | ||
}, | ||
|
||
}; |
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const Inventory = require("../models/inventory"); | ||
const Category = require("../models/categories"); | ||
const Item = require("../models/items"); | ||
const db = require("../config"); | ||
const { Schema } = require('mongoose'); | ||
|
||
|
||
|
||
module.exports = { | ||
addStock:(req, res) => { | ||
|
||
const { item,quantity,categoryName } = req.body | ||
const newStock = new Inventory({item,quantity,categoryName}) | ||
newStock.save() | ||
.then((inventory) =>{ | ||
if(inventory) { | ||
return res.status(201).json({message:'New stock added', newStock}) | ||
} | ||
}) | ||
.catch((error) =>{ | ||
console.log(error) | ||
}); | ||
|
||
}, | ||
|
||
|
||
|
||
getEntireStock:(req, res)=> { | ||
Inventory.find({}).then((inventory)=> { | ||
if(inventory) { | ||
return res.status(200).json({inventory}); | ||
}else{ | ||
return res.status(400).json({ message: "No Inventory found" }); | ||
} | ||
}); | ||
|
||
}, | ||
|
||
deleteStock:(req, res) =>{ | ||
Inventory.findByIdAndDelete(req.params.id).then((inventory) => { | ||
if(inventory){ | ||
return res.status(200).json({message:'Inventory deleted'}) | ||
}else{ | ||
return res.status(404).json({message:'inventory of given ID not found'}) | ||
} | ||
|
||
}) | ||
}, | ||
updateInventory:(req, res) =>{ | ||
Inventory.findByIdAndUpdate (req.params.id,req.body,{new:true}).then((inventory)=>{ | ||
if(inventory){ | ||
return res.status(200).json({message:'Inventory updated',inventory}) | ||
}else{ | ||
return res.status(404).json({message:'inventory of given ID not found'}) | ||
} | ||
|
||
}) | ||
|
||
} | ||
|
||
}; |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Inventory = require("../models/inventory"); | ||
const Category = require("../models/categories"); | ||
const Item = require("../models/items"); | ||
const db = require("../config"); | ||
const { Schema } = require('mongoose'); | ||
|
||
|
||
|
||
module.exports = { | ||
addItems:(req, res) => { | ||
const { itemName, categoryName, price, availability, description,imageUrl} = req.body | ||
const newItem = new Item({itemName,categoryName, price, availability, description,imageUrl}) | ||
newItem.save() | ||
.then((item) =>{ | ||
if(item) { | ||
return res.status(201).json({message:'new stock', newItem}) | ||
} | ||
}) | ||
.catch((error) =>{ | ||
console.log(error) | ||
}); | ||
} , | ||
|
||
}; | ||
|
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 |
---|---|---|
|
@@ -42,13 +42,3 @@ loginUser:(req, res) => { | |
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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
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 |
---|---|---|
|
@@ -23,17 +23,4 @@ module.exports = { | |
|
||
|
||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
|
@@ -22,17 +22,3 @@ module.exports = { | |
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
|
@@ -6,5 +6,3 @@ const Category = mongoose.model("category", categorySchema); | |
|
||
|
||
module.exports = Category; | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const mongoose = require("mongoose"); | ||
const inventorySchema = require("./schemas/inventorySchema"); | ||
|
||
const Inventory = mongoose.model("inventory", inventorySchema); | ||
|
||
|
||
|
||
module.exports = Inventory; |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const mongoose = require("mongoose"); | ||
const itemsSchema =require("./schemas/itemsSchema"); | ||
|
||
const Item = mongoose.model("items", itemsSchema); | ||
|
||
|
||
|
||
module.exports = Item; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const { Schema } =require('mongoose'); | ||
|
||
const categorySchema = new Schema({ | ||
categoryName:{ | ||
type:String, | ||
required:true | ||
}, | ||
description:{ | ||
type:String, | ||
required:true | ||
}, | ||
|
||
inventory:[ | ||
{type: Schema.Types.ObjectId, ref: 'inventory'} | ||
] | ||
|
||
}); | ||
|
||
|
||
module. exports = categorySchema; | ||
|
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const { Schema } = require('mongoose'); | ||
|
||
const inventorySchema = new Schema({ | ||
item:{ | ||
type:String, | ||
required:true | ||
}, | ||
quantity:{ | ||
type:Number, | ||
required:true | ||
|
||
}, | ||
|
||
categoryName:{ | ||
type:String, | ||
required:true | ||
|
||
}, | ||
|
||
|
||
category: | ||
[ | ||
{type: Schema.Types.ObjectId, ref: 'category'} | ||
] | ||
|
||
|
||
}); | ||
|
||
|
||
|
||
module.exports = inventorySchema; |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { Schema } = require('mongoose'); | ||
|
||
const itemsSchema = new Schema({ | ||
itemName:{ | ||
type:String, | ||
required:true | ||
}, | ||
categoryName:{ | ||
type:String, | ||
required:true | ||
}, | ||
price:{ | ||
type:Number, | ||
required:true | ||
}, | ||
availability:{ | ||
type:Boolean, | ||
required:true | ||
}, | ||
description:{ | ||
type:String, | ||
required:true | ||
}, | ||
imageUrl:{ | ||
type:String, | ||
required:true | ||
}, | ||
inventory: [{type:Schema.Types.ObjectId,ref: 'inventory'}], | ||
category: [{type:Schema.Types.ObjectId,ref: 'category'}] | ||
}); | ||
|
||
|
||
|
||
module.exports = itemsSchema; |
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 |
---|---|---|
|
@@ -22,13 +22,3 @@ lastName:{ | |
}); | ||
|
||
module.exports = usersSchema; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Oops, something went wrong.