A RESTful API for managing library operations including user management, book management, and book borrowing system.
- Runtime Environment: Node.js
- Framework: Express.js
- Language: TypeScript
- Database: PostgreSQL
- ORM: TypeORM
- Other Tools:
- Docker & Docker Compose
- User Management
- List all users
- Get user details with borrowing history
- Create new users
- Book Management
- List all books
- Get book details with ratings
- Create new books
- Borrowing Operations
- Borrow books
- Return books with ratings
- Track borrowing history
- Clone the repository:
git clone https://github.com/safciplak/invent-test-case
cd invent-test-case
yarn- Create
.envfile in root directory
cp .env.example .env- Run with Docker:
docker compose up --buildGET /api/users- List all usersGET /api/users/:id- Get user detailsPOST /api/users- Create new user
GET /api/books- List all booksGET /api/books/:id- Get book detailsPOST /api/books- Create new book
POST /api/borrow- Borrow a bookPOST /api/return- Return a book with rating
-- Users table
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
-- Books table
CREATE TABLE books (
id SERIAL PRIMARY KEY,
name VARCHAR(200) NOT NULL
);
-- Book Borrows table
CREATE TABLE book_borrows (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
book_id INTEGER REFERENCES books(id),
borrow_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
return_date TIMESTAMP,
score INTEGER
);
-- Indexes for better query performance
CREATE INDEX idx_book_borrows_user_id ON book_borrows(user_id);
CREATE INDEX idx_book_borrows_book_id ON book_borrows(book_id);MIT
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
You can run the tests using:
yarn run testThe project includes unit tests and integration tests with Jest. To view the test coverage report:
- Run the coverage command:
yarn test:coverageNote:
- A minimum test coverage of 70-80% or higher is required for all components
- This coverage requirement helps ensure code quality and reliability
- Coverage reports are generated using Jest's built-in coverage reporting tool
- Components falling below the minimum coverage threshold should be improved before merging