From 28b1911c630fcfdb441e3e3b28dca7cb9c8e26b8 Mon Sep 17 00:00:00 2001 From: demo-bot Date: Mon, 11 May 2026 12:06:27 +0000 Subject: [PATCH] feat(scaffold): add src/items/items.service.ts [skip ci] --- src/items/items.service.ts | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/items/items.service.ts diff --git a/src/items/items.service.ts b/src/items/items.service.ts new file mode 100644 index 0000000..93fdcf8 --- /dev/null +++ b/src/items/items.service.ts @@ -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(); + 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 }; + } +}