Last active
June 26, 2021 16:06
-
-
Save samueleresca/fb5d7b780c2ba0eb6a032904774669b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component} from '@nestjs/common'; | |
import {InjectRepository} from '@nestjs/typeorm'; | |
import {ILabelService} from './ILabelService'; | |
import {Repository} from 'typeorm'; | |
import {Label} from '../Models/Label'; | |
@Component() | |
export class LabelsService implements ILabelService { | |
private readonly labelRepository: Repository<Label>; | |
constructor(@InjectRepository(Label) | |
labelRepository: Repository<Label>) { | |
this.labelRepository = labelRepository; | |
} | |
async FindAll(): Promise<Label[]> { | |
return await this.labelRepository.find(); | |
} | |
async Find(code: string): Promise<Label> { | |
return await this.labelRepository.findOne({Code: code}); | |
} | |
async Where(label: Label): Promise<Label> { | |
return await this.labelRepository.findOne(label); | |
} | |
async Insert(label: Label): Promise<Label> { | |
await this.labelRepository.save(label); | |
return label; | |
} | |
async Update(id: number, label: Label): Promise<Label> { | |
try { | |
await this.labelRepository.updateById(id, label); | |
return label; | |
} catch (e) { | |
} | |
} | |
async Delete(id: number): Promise<Label> { | |
try { | |
const toDelete = this.labelRepository.findOneById(id); | |
await this.labelRepository.deleteById(id); | |
return toDelete; | |
} catch (e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment