practice-anil-khamitkar 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,18 @@
1
1
  {
2
2
  "name": "practice-anil-khamitkar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "keywords": [],
10
+ "author": "",
11
+ "license": "ISC",
12
+ "type": "commonjs",
13
+ "dependencies": {
14
+ "express": "^5.3.0",
15
+ "mongoose": "^9.12.3",
16
+ "nodemon": "^3.1.14"
17
+ }
18
+ }
package/server.js ADDED
@@ -0,0 +1,9 @@
1
+ const PORT = 2000;
2
+ const app = require("./src/app");
3
+ const connectDb = require("./src/db/db")
4
+
5
+ connectDb();
6
+
7
+ app.listen(PORT,()=>{
8
+ console.log(`Server has started on PORT : ${PORT}`)
9
+ });
package/src/app.js ADDED
@@ -0,0 +1,82 @@
1
+ const express=require("express");
2
+ const app = express();
3
+ app.use(express.json());
4
+
5
+ const noteModel = require("./model/note.model");
6
+
7
+
8
+ app.get("/notes",async (req,res)=>{
9
+ const notes = await noteModel.find(); // Array of Objects
10
+ res.status(200).json({
11
+ notes
12
+ });
13
+ });
14
+
15
+ app.post("/notes",async (req,res)=>{
16
+ try{
17
+ const notes = req.body;
18
+ const create = await noteModel.create({
19
+ title:notes.title,
20
+ description:notes.description,
21
+ price:notes.price
22
+ });
23
+
24
+ res.status(201).json({
25
+ "msg" : "Notes Created Successfully",
26
+ "notes": notes,
27
+ "Create":create
28
+ });
29
+ }catch(e){
30
+ console.log("Error in posting Notes");
31
+ console.log(e);
32
+ }
33
+
34
+ });
35
+
36
+
37
+ app.get("/notes/:id",async (req,res)=>{
38
+ const id = req.params.id;
39
+ const note = await noteModel.find({
40
+ _id:id
41
+ });
42
+ if(note.length > 0){
43
+ return res.json({
44
+ note
45
+ });
46
+ }
47
+ return res.json({
48
+ "msg":`Notes With Id:${id} Not Found`
49
+ })
50
+
51
+
52
+ })
53
+
54
+
55
+ app.put("/notes/:id",async (req,res)=>{
56
+ const id = req.params.id;
57
+ const notes = req.body;
58
+ await noteModel.findOneAndUpdate({
59
+ _id:id
60
+ },{
61
+ title:notes.title,
62
+ description:notes.description,
63
+ price:notes.price
64
+ });
65
+ return res.status(200).json({
66
+ msg:"Updated successfully"
67
+ })
68
+ });
69
+
70
+
71
+ app.delete("/notes/:id",async (req,res)=>{
72
+ const id = req.params.id;
73
+ await noteModel.findOneAndDelete({
74
+ _id:id
75
+ })
76
+ res.json({
77
+ msg:"Notes Deleted Succesfully"
78
+ })
79
+ })
80
+
81
+
82
+ module.exports = app;
package/src/db/db.js ADDED
@@ -0,0 +1,15 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const URL = "mongodb://localhost:27017/practicedb";
4
+
5
+ async function connectDb() {
6
+ try{
7
+ await mongoose.connect(URL);
8
+ console.log("Database connected succesfully");
9
+ }catch(e){
10
+ console.log("DB connection Failed");
11
+ console.log("Error: ",e);
12
+ }
13
+ }
14
+
15
+ module.exports=connectDb;
@@ -0,0 +1,13 @@
1
+ const mongoose = require("mongoose");
2
+
3
+ const noteSchema = new mongoose.Schema({
4
+ title: {type:String , unique:true},
5
+ description: String,
6
+ price:Number
7
+ });
8
+
9
+ const noteModel = mongoose.model("notes",noteSchema);
10
+
11
+
12
+
13
+ module.exports=noteModel;
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.