Skip to content

pushkar462/OOPScrud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Farmer CRUD Backend

A full CRUD backend for managing farmer records built with Node.js, Express, TypeScript and MongoDB. Uses a clean OOP structure with controllers, services and repositories.

Features

  • CRUD: Create, get single, list, update, delete farmers
  • Search: Search by name, village or crop
  • Filter: Filter by village and crop
  • Sorting: Sort by any field (prefix with - for descending)
  • Pagination: Page and limit query params
  • Validation: Request validation with express-validator
  • Error handling: Centralised error middleware with clear messages
  • Authentication: JWT-based auth; register and login to get a token; farmer routes are protected

Structure

  • controllers – handle HTTP, delegate to services
  • services – business logic, call repositories
  • repositories – data access (Mongoose)
  • models – Mongoose schemas
  • middleware – auth, validation, error handling
  • validators – express-validator rules
  • utils – interfaces, custom errors

Setup

  1. Clone the repo and install dependencies:
npm install
  1. Copy .env.example to .env and set:
  • PORT – server port (default 8080)
  • MONGODB_URI – MongoDB connection string
  • JWT_SECRET – secret for signing JWTs
  1. Run the app:
npm run dev

API

Auth (no token)

  • POST /auth/register – body: { "email": "...", "password": "..." } – returns { "token": "..." }
  • POST /auth/login – body: { "email": "...", "password": "..." } – returns { "token": "..." }

Farmers (require header: Authorization: Bearer <token>)

  • POST /farmers – create farmer – body: { "name", "village", "crop", "landArea", "phone" }
  • GET /farmers – list with query: ?search=&village=&crop=&sort=-createdAt&page=1&limit=10
  • GET /farmers/:id – get one farmer
  • PATCH /farmers/:id – update farmer (partial body)
  • DELETE /farmers/:id – delete farmer

Tech stack

Node.js, Express, TypeScript, Mongoose, bcryptjs, jsonwebtoken, express-validator.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors