40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
import { BaseRepository } from '#application/base/baseRepository'
|
|
import { UUID } from '#application/types'
|
|
import { Item } from '#entities/item'
|
|
|
|
class ItemRepository extends BaseRepository {
|
|
async getById(id: UUID): Promise<any> {
|
|
try {
|
|
const repository = this.getEntityManager().getRepository(Item)
|
|
return await repository.findOne({ id })
|
|
} catch (error: any) {
|
|
this.logger.error(`Failed to get item by ID: ${error instanceof Error ? error.message : String(error)}`)
|
|
return null
|
|
}
|
|
}
|
|
|
|
async getByIds(ids: UUID[]): Promise<any> {
|
|
try {
|
|
const repository = this.getEntityManager().getRepository(Item)
|
|
return await repository.find({
|
|
id: ids
|
|
})
|
|
} catch (error: any) {
|
|
this.logger.error(`Failed to get items by IDs: ${error instanceof Error ? error.message : String(error)}`)
|
|
return null
|
|
}
|
|
}
|
|
|
|
async getAll(): Promise<any> {
|
|
try {
|
|
const repository = this.getEntityManager().getRepository(Item)
|
|
return await repository.findAll()
|
|
} catch (error: any) {
|
|
this.logger.error(`Failed to get all items: ${error instanceof Error ? error.message : String(error)}`)
|
|
return null
|
|
}
|
|
}
|
|
}
|
|
|
|
export default ItemRepository
|