forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathitems.service.ts
More file actions
46 lines (40 loc) · 1.44 KB
/
Copy pathitems.service.ts
File metadata and controls
46 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Item } from '../../entities/item.entity';
import { CreateItemDto } from './dto/create-item.dto';
import { UpdateItemDto } from './dto/update-item.dto';
@Injectable()
export class ItemsService {
constructor(
@InjectRepository(Item)
private readonly itemRepository: Repository<Item>,
) { }
async create(createItemDto: CreateItemDto): Promise<Item> {
const item = this.itemRepository.create(createItemDto);
return await this.itemRepository.save(item);
}
async findAllBySplitId(splitId: string): Promise<Item[]> {
return await this.itemRepository.find({
where: { splitId },
});
}
async findOne(id: string): Promise<Item> {
const item = await this.itemRepository.findOne({
where: { id },
});
if (!item) {
throw new NotFoundException(`Item with ID ${id} not found`);
}
return item;
}
async update(id: string, updateItemDto: UpdateItemDto): Promise<Item> {
const item = await this.findOne(id);
Object.assign(item, updateItemDto);
return await this.itemRepository.save(item);
}
async remove(id: string): Promise<void> {
const item = await this.findOne(id);
await this.itemRepository.remove(item);
}
}