1
|
|
|
import { |
2
|
|
|
Body, |
3
|
|
|
Controller, |
4
|
|
|
Inject, |
5
|
|
|
BadRequestException, |
6
|
|
|
UseGuards, |
7
|
|
|
Put, |
8
|
|
|
Param |
9
|
|
|
} from '@nestjs/common'; |
10
|
|
|
import {AuthGuard} from '@nestjs/passport'; |
11
|
|
|
import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
12
|
|
|
import {ICommandBus} from 'src/Application/ICommandBus'; |
13
|
|
|
import {DailyRateDTO} from '../../DTO/DailyRateDTO'; |
14
|
|
|
import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
15
|
|
|
import {UpdateDailyRateCommand} from 'src/Application/Accounting/Command/DailyRate/UpdateDailyRateCommand'; |
16
|
|
|
import {Roles} from 'src/Infrastructure/User/Decorator/Roles'; |
17
|
|
|
import {UserRole} from 'src/Domain/User/User.entity'; |
18
|
|
|
import {RolesGuard} from 'src/Infrastructure/User/Security/RolesGuard'; |
19
|
|
|
|
20
|
|
|
@Controller('daily_rates') |
21
|
|
|
@ApiUseTags('Accounting') |
22
|
|
|
@ApiBearerAuth() |
23
|
|
|
@UseGuards(AuthGuard('bearer'), RolesGuard) |
24
|
|
|
export class UpdateDailyRateAction { |
25
|
|
|
constructor( |
26
|
|
|
@Inject('ICommandBus') |
27
|
|
|
private readonly commandBus: ICommandBus |
28
|
|
|
) {} |
29
|
|
|
|
30
|
|
|
@Put(':id') |
31
|
|
|
@Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
32
|
|
|
@ApiOperation({title: 'Update daily rate'}) |
33
|
|
|
public async index(@Param() idDto: IdDTO, @Body() dto: DailyRateDTO) { |
34
|
|
|
try { |
35
|
|
|
const {userId, customerId, taskId, amount} = dto; |
36
|
|
|
|
37
|
|
|
const id = await this.commandBus.execute( |
38
|
|
|
new UpdateDailyRateCommand(idDto.id, amount, userId, customerId, taskId) |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
return {id}; |
42
|
|
|
} catch (e) { |
43
|
|
|
throw new BadRequestException(e.message); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|