Total Complexity | 5 |
Complexity/F | 1 |
Lines of Code | 54 |
Function Count | 5 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Injectable } from '@nestjs/common'; |
||
2 | import { Repository } from 'typeorm'; |
||
3 | import { InjectRepository } from '@nestjs/typeorm'; |
||
4 | import { ShippingCost } from 'src/Domain/Order/ShippingCost.entity'; |
||
5 | import { IShippingCostRepository } from 'src/Domain/Order/Repository/IShippingCostRepository'; |
||
6 | |||
7 | @Injectable() |
||
8 | export class ShippingCostRepository implements IShippingCostRepository { |
||
9 | constructor( |
||
10 | @InjectRepository(ShippingCost) |
||
11 | private readonly repository: Repository<ShippingCost> |
||
12 | ) {} |
||
13 | |||
14 | public save(shippingCost: ShippingCost): Promise<ShippingCost> { |
||
15 | return this.repository.save(shippingCost); |
||
16 | } |
||
17 | |||
18 | public remove(shippingCost: ShippingCost): void { |
||
19 | this.repository.delete(shippingCost.getId()); |
||
20 | } |
||
21 | |||
22 | public findOneByWeight(weight: number): Promise<ShippingCost | undefined> { |
||
23 | return this.repository |
||
24 | .createQueryBuilder('shippingCost') |
||
25 | .select([ 'shippingCost.id' ]) |
||
26 | .where('shippingCost.weight = :weight', { weight }) |
||
27 | .getOne(); |
||
28 | } |
||
29 | |||
30 | public findOneById(id: string): Promise<ShippingCost | undefined> { |
||
31 | return this.repository |
||
32 | .createQueryBuilder('shippingcost') |
||
33 | .select([ |
||
34 | 'shippingcost.id', |
||
35 | 'shippingcost.weight', |
||
36 | 'shippingcost.price' |
||
37 | ]) |
||
38 | .where('shippingcost.id = :id', { id }) |
||
39 | .getOne(); |
||
40 | } |
||
41 | |||
42 | public findShippingCosts(): Promise<ShippingCost[]> { |
||
43 | return this.repository |
||
44 | .createQueryBuilder('shippingcost') |
||
45 | .select([ |
||
46 | 'shippingcost.id', |
||
47 | 'shippingcost.price', |
||
48 | 'shippingcost.weight' |
||
49 | ]) |
||
50 | .orderBy('shippingcost.weight', 'ASC') |
||
51 | .getMany(); |
||
52 | } |
||
53 | } |
||
54 |