| Total Complexity | 4 | 
| Total Lines | 36 | 
| Duplicated Lines | 0 % | 
| Changes | 0 | ||
| 1 | import {QueryHandler} from '@nestjs/cqrs'; | 
            ||
| 8 | |||
| 9 | @QueryHandler(GetQuotesQuery)  | 
            ||
| 10 | export class GetQuotesQueryHandler { | 
            ||
| 11 | constructor(  | 
            ||
| 12 |     @Inject('IQuoteRepository') | 
            ||
| 13 | private readonly quoteRepository: IQuoteRepository  | 
            ||
| 14 |   ) {} | 
            ||
| 15 | |||
| 16 |   public async execute(query: GetQuotesQuery): Promise<QuoteView[]> { | 
            ||
| 17 | const quotes = await this.quoteRepository.findAll();  | 
            ||
| 18 | const results: QuoteView[] = [];  | 
            ||
| 19 | |||
| 20 |     for (const quote of quotes) { | 
            ||
| 21 | const project = quote.getProject();  | 
            ||
| 22 | const customer = quote.getCustomer();  | 
            ||
| 23 | let amountExcludingVat = 0;  | 
            ||
| 24 | |||
| 25 |       for (const item of quote.getItems()) { | 
            ||
| 26 | amountExcludingVat +=  | 
            ||
| 27 | (item.getQuantity() / 100) * (item.getDailyRate() / 100);  | 
            ||
| 28 | }  | 
            ||
| 29 | |||
| 30 | results.push(  | 
            ||
| 31 | new QuoteView(  | 
            ||
| 32 | quote.getId(),  | 
            ||
| 33 | quote.getQuoteId(),  | 
            ||
| 34 | quote.getStatus(),  | 
            ||
| 35 | quote.getCreatedAt(),  | 
            ||
| 36 | amountExcludingVat * 1.2,  | 
            ||
| 37 | new CustomerView(customer.getId(), customer.getName()),  | 
            ||
| 38 | project ? new ProjectView(project.getId(), project.getName()) : null  | 
            ||
| 39 | )  | 
            ||
| 40 | );  | 
            ||
| 41 | }  | 
            ||
| 42 | |||
| 43 | return results;  | 
            ||
| 44 | }  | 
            ||
| 46 |