Are you tired of writing the same CRUD operations repeatedly for your Mongoose models? Say hello to Crudify! This NestJS library is designed to make your life easier by automatically generating RESTful CRUD endpoints for your Mongoose models. And now, with the latest updates, it’s even better! Let’s dive into what’s new in Crudify and how it can transform your development process.
🚀 What's New in Crudify
1. Advanced Query Parser
The new Query Parser in Crudify transforms URL query parameters into MongoDB-compatible queries. This feature supports:
- Filtering with operators like
eq
,ne
,gt
,lt
,in
, and more. - Sorting results by multiple fields.
- Pagination with
skip
andlimit
. - Population of references with nested options for filtering and sorting.
Here’s an example:
/users?name[starts]=John&age[gte]=30&sort=-createdAt&limit=10
This query fetches users whose names start with "John," are 30 years or older, sorted by creation date in descending order, and limited to 10 results.
2. Custom Decorators for Enhanced Flexibility
Easily add custom decorators to your routes, whether globally or individually. Use this feature to apply guards, add Swagger documentation, or manage authorization seamlessly.
@Crudify({
model: { type: User },
routes: {
config: {
findAll: {
decorators: [
ApiOperation({
summary: 'Retrieve all users',
description: 'Fetches all users from the database.',
}),
],
},
},
},
})
@Controller('users')
export class UserController {}
3. Integrated Logger Module
Debugging is now simpler with the new CrudifyLoggerModule
. It intercepts uncaught errors and logs them for you. Configure it to suit your project’s needs, ensuring you never miss an important detail.
@Module({
imports: [
CrudifyLoggerModule.forRoot({
uri: process.env.MONGODB_URI,
dbName: process.env.MONGODB_LOGDB,
}),
],
})
export class AppModule {}
4. Bulk Operations
Streamline your batch processing with new bulk endpoints:
-
POST /your-model/bulk
: Create multiple records. -
PATCH /your-model/bulk
: Update multiple records. -
DELETE /your-model/bulk
: Delete multiple records.
5. Authorization Made Simple
Combine UseGuards
with Crudify to manage route access control effectively. Protect specific routes or entire controllers with your custom authorization logic.
@Crudify({
model: { type: User },
routes: {
config: {
create: {
decorators: [UseGuards(AuthGuard)],
},
},
},
})
class UserController {}
💡 Why Use Crudify?
- Save Time: Focus on building features instead of boilerplate code.
- Customization: Tailor endpoints to your needs with ease.
- Swagger Support: Automatically generate API documentation.
- Seamless NestJS Integration: Fits perfectly into your existing projects.
🚀 Get Started Today
Ready to supercharge your NestJS development? Install Crudify and start building smarter APIs now:
npm install ncrudify
Check out the Crudify GitHub repository for more details, examples, and documentation. Don’t forget to give it a star if you find it helpful!
Let Crudify handle the repetitive tasks so you can focus on what truly matters: creating amazing applications.
Top comments (0)