crud-api-express 1.0.2 → 1.0.4
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 +1 -1
- package/readme.md +9 -14
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -35,44 +35,38 @@ Here's a basic example of how to use CrudController:
|
|
|
35
35
|
|
|
36
36
|
import express from 'express';
|
|
37
37
|
import mongoose from 'mongoose';
|
|
38
|
-
import CrudController from 'crud-api-express';
|
|
38
|
+
import CrudController from 'crud-api-express';
|
|
39
|
+
|
|
39
40
|
|
|
40
|
-
// Define Mongoose schema and model
|
|
41
41
|
const Schema = mongoose.Schema;
|
|
42
42
|
|
|
43
43
|
const ExampleSchema = new Schema({
|
|
44
|
-
title: { type: String, required: true, trim: true },
|
|
45
44
|
type: { type: String, default: 'Percentage', enum: ['Percentage', 'Flat'] },
|
|
46
|
-
value: { type: Number, required: true },
|
|
47
45
|
status: { type: String, default: 'Active', trim: true },
|
|
48
46
|
expiry_date: { type: Date, index: true, trim: true },
|
|
49
47
|
}, { timestamps: true, versionKey: false });
|
|
50
48
|
|
|
51
49
|
const ExampleModel = mongoose.model('Example', ExampleSchema);
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
|
|
54
52
|
const exampleController = new CrudController(ExampleModel, 'examples', {
|
|
55
53
|
// Optional configuration options here
|
|
56
54
|
});
|
|
57
55
|
|
|
58
|
-
// MongoDB Atlas connection URI
|
|
59
|
-
const mongoURI = 'mongodb+srv';
|
|
60
56
|
|
|
61
|
-
|
|
57
|
+
const mongoURI = 'mdhd';
|
|
58
|
+
|
|
59
|
+
|
|
62
60
|
mongoose.connect(mongoURI, { useNewUrlParser: false, useUnifiedTopology: false })
|
|
63
61
|
.then(() => {
|
|
64
62
|
console.log('Connected to MongoDB Atlas');
|
|
65
|
-
|
|
63
|
+
|
|
66
64
|
const app = express();
|
|
67
65
|
|
|
68
|
-
// Middleware to parse JSON bodies
|
|
69
66
|
app.use(express.json());
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
// Mount the CrudController router
|
|
73
68
|
app.use('/api', exampleController.getRouter());
|
|
74
69
|
|
|
75
|
-
// Start the server
|
|
76
70
|
const PORT = process.env.PORT || 3000;
|
|
77
71
|
app.listen(PORT, () => {
|
|
78
72
|
console.log(`Server is running on port ${PORT}`);
|
|
@@ -80,10 +74,11 @@ mongoose.connect(mongoURI, { useNewUrlParser: false, useUnifiedTopology: false }
|
|
|
80
74
|
})
|
|
81
75
|
.catch(err => {
|
|
82
76
|
console.error('Error connecting to MongoDB Atlas:', err.message);
|
|
83
|
-
process.exit(1);
|
|
77
|
+
process.exit(1);
|
|
84
78
|
});
|
|
85
79
|
|
|
86
80
|
|
|
81
|
+
|
|
87
82
|
# API
|
|
88
83
|
|
|
89
84
|
model: Mongoose model for CRUD operations.
|