Completed
Push — master ( b46f0e...3db42d )
by Mathieu
13s
created

server/src/Infrastructure/File/Repository/FileRepository.ts   A

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 28
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 22
mnd 0
bc 0
fnc 3
dl 0
loc 28
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10

3 Functions

Rating   Name   Duplication   Size   Complexity  
A FileRepository.save 0 3 1
A FileRepository.remove 0 3 1
A FileRepository.findOneById 0 6 1
1
import {InjectRepository} from '@nestjs/typeorm';
2
import {Repository} from 'typeorm';
3
import {IFileRepository} from 'src/Domain/File/Repository/IFileRepository';
4
import {File} from 'src/Domain/File/File.entity';
5
6
export class FileRepository implements IFileRepository {
7
  constructor(
8
    @InjectRepository(File)
9
    private readonly repository: Repository<File>
10
  ) {}
11
12
  public save(file: File): Promise<File> {
13
    return this.repository.save(file);
14
  }
15
16
  public remove(file: File): void {
17
    this.repository.delete(file.getId());
18
  }
19
20
  public findOneById(id: string): Promise<File | undefined> {
21
    return this.repository
22
      .createQueryBuilder('file')
23
      .select(['file.id', 'file.name', 'file.mimeType', 'file.uploadedAt'])
24
      .where('file.id = :id', {id})
25
      .getOne();
26
  }
27
}
28