Performance: CRUD operations
CRUD operations impact server response time and client rendering speed, affecting how quickly users see and interact with data changes.
async updateUser(id: string, data: UpdateUserDto) { const result = await this.userRepository.update(id, data); if (result.affected === 0) throw new NotFoundException(); return { id, ...data }; }
async updateUser(id: string, data: UpdateUserDto) { const user = await this.userRepository.findOneBy({ id }); if (!user) throw new NotFoundException(); Object.assign(user, data); await this.userRepository.save(user); return user; }
| Pattern | Database Queries | Server Response Time | Client Update Cost | Verdict |
|---|---|---|---|---|
| Fetch then update entity | 2 queries | Higher latency | Moderate | [X] Bad |
| Direct update query | 1 query | Lower latency | Moderate | [OK] Good |
id in a NestJS controller method?/items/5 and the service deletes the item successfully?
@Delete(':id')
async remove(@Param('id') id: string) {
await this.itemsService.delete(id);
return { message: `Item ${id} deleted` };
} @Put(':id')
async update(@Body() updateDto: UpdateItemDto) {
return this.itemsService.update(updateDto.id, updateDto);
}id from the URL and new data from the request body. Which of the following method signatures correctly follows NestJS CRUD patterns?Pass the test and this pattern moves unknown