SonarQ test on PR #1

Open
andrej wants to merge 14 commits from dev into main
Showing only changes of commit e870170da3 - Show all commits

View File

@@ -0,0 +1,45 @@
import { Injectable, NotFoundException } from '@nestjs/common';
export interface Item {
id: number;
name: string;
description: string;
}
@Injectable()
export class ItemsService {
private readonly store = new Map<number, Item>();
private counter = 1;
findAll(): Item[] {
return [...this.store.values()];
}
create(name: string, description = ''): Item {
const item: Item = { id: this.counter++, name, description };
this.store.set(item.id, item);
return item;
}
findOne(id: number): Item {
const item = this.store.get(id);
if (!item) throw new NotFoundException(`Item ${id} not found`);
return item;
}
update(id: number, name?: string, description?: string): Item {
const item = this.findOne(id);
const updated: Item = {
id,
name: name ?? item.name,
description: description ?? item.description,
};
this.store.set(id, updated);
return updated;
}
remove(id: number): { deleted: number } {
this.store.delete(id);
return { deleted: id };
}
}