Tracking Reading Progress

Introduction: Why Track Reading Progress?

Welcome back! In the last lessons, you learned how to create and manage resources like users and books in your API using NestJS. Now, let’s take the next step and add a feature that makes our application more useful: tracking reading progress.

Imagine you are using a reading tracker app. You want to know how far you’ve read in each book and maybe even pick up right where you left off. This is a common feature in many reading and learning apps. When you stop at page 52, you want the app to remember that exact page, so next time you resume reading — boom, you're right there. That’s exactly what our ReadingSession is doing in this lesson. You will learn how to build this feature by connecting users, books, and their reading sessions together.

By the end of this lesson, you will know how to update and track a user’s reading progress for a specific book using modules and DTOs in NestJS.

Quick Recap: Project Structure and Data

Before we dive in, let’s quickly remind ourselves of the project setup. You already have modules for users and books, and a simple mock database to store data. Here’s a summary of the main app module and the mock data structure:

TypeScript
// src/app.module.ts
import { Module, Global } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UsersModule } from './users/users.module';
import { DatabaseService } from './database/database.service';
import { BooksModule } from './books/books.module';
import { ReadingModule } from './reading/reading.module';

@Global()
@Module({
  imports: [UsersModule, BooksModule, ReadingModule],
  controllers: [AppController],
  providers: [AppService, DatabaseService],
  exports: [DatabaseService],
})
export class AppModule {}
// src/database/mock-db.ts
export interface User { id: string; name: string; }

export interface Book { id: string; title: string; author: string; }

export interface ReadingSession { userId: string; bookId: string; currentPage: number; }

import { v4 as uuidv4 } from 'uuid';

export const users: User[] = [
  { id: uuidv4(), name: 'Alice' },
  { id: uuidv4(), name: 'Bob' },
];

export const books: Book[] = [
  { id: uuidv4(), title: 'The Hobbit', author: 'J.R.R. Tolkien' },
  { id: uuidv4(), title: 'Dune', author: 'Frank Herbert' },
];

export const readingSessions: ReadingSession[] = [
  { userId: users[0].id, bookId: books[0].id, currentPage: 50 },
];

This setup allows us to keep track of users, books, and reading sessions. The ReadingSession ties a user to a book and records their current page.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal