Bird
0
0

How can you implement pagination in a NestJS service method that returns a list of items for a CRUD read operation?

hard📝 Conceptual Q9 of 15
NestJS - Database with TypeORM
How can you implement pagination in a NestJS service method that returns a list of items for a CRUD read operation?
AReturn all items and let client handle pagination
BAccept page and limit parameters, calculate offset, and return sliced array or query result
CUse @Delete decorator to paginate results
DOnly return the first item always
Step-by-Step Solution
Solution:
  1. Step 1: Understand pagination parameters

    Pagination requires page number and limit per page to calculate offset.
  2. Step 2: Apply offset and limit to data source

    Use offset = (page - 1) * limit to slice array or query database accordingly.
  3. Final Answer:

    Accept page and limit parameters, calculate offset, and return sliced array or query result -> Option B
  4. Quick Check:

    Pagination = page, limit, offset slicing [OK]
Quick Trick: Calculate offset from page and limit for pagination [OK]
Common Mistakes:
  • Returning all data without slicing
  • Using wrong HTTP decorators
  • Ignoring pagination parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes