AfroCrud
Usage
Mongoose model file:
const NoteModelSchema = new mongoose.Schema({
text: {
type: String
},
title:{
type: String,
default: "Untitled"
}
}, {timestamps: true});
export const Notes = mongoose.model("Notes", NoteModelSchema);
Joi schema file:
export const NoteJoiSchema = Joi.object({
title: Joi.string().allow("").default("Untitled"),
text: Joi.string().min(3).default("Foo")
});
Create routes:
import { AfroCrud } from "afrocrud";
import { Notes } from "./notes.model.js";
import { NoteJoiSchema } from "./notes.schema.js";
const notesRoutes = new AfroCrud(Notes, NoteJoiSchema);
app.use("/notes", notesRoutes.router);