This commit is contained in:
@@ -7,7 +7,6 @@ import {
|
||||
Param,
|
||||
Delete,
|
||||
UseGuards,
|
||||
ParseIntPipe,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
@@ -22,6 +21,7 @@ import { UpdateContractDto } from './dto/update-contract.dto.js';
|
||||
import { SearchContractDto } from './dto/search-contract.dto.js';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard.js';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator.js';
|
||||
import { ParseUuidPipe } from '../../common/pipes/parse-uuid.pipe';
|
||||
|
||||
@ApiTags('Contracts')
|
||||
@ApiBearerAuth()
|
||||
@@ -45,26 +45,26 @@ export class ContractController {
|
||||
return this.contractService.findAll(query);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get Contract by ID' })
|
||||
findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.contractService.findOne(id);
|
||||
@Get(':uuid')
|
||||
@ApiOperation({ summary: 'Get Contract by UUID' })
|
||||
findOne(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.contractService.findOneByUuid(uuid);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@Patch(':uuid')
|
||||
@RequirePermission('master_data.manage')
|
||||
@ApiOperation({ summary: 'Update Contract' })
|
||||
update(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@Body() dto: UpdateContractDto
|
||||
) {
|
||||
return this.contractService.update(id, dto);
|
||||
return this.contractService.update(uuid, dto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(':uuid')
|
||||
@RequirePermission('master_data.manage')
|
||||
@ApiOperation({ summary: 'Delete Contract' })
|
||||
remove(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.contractService.remove(id);
|
||||
remove(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.contractService.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,15 +87,24 @@ export class ContractService {
|
||||
return contract;
|
||||
}
|
||||
|
||||
async update(id: number, dto: UpdateContractDto) {
|
||||
const contract = await this.findOne(id);
|
||||
async findOneByUuid(uuid: string) {
|
||||
const contract = await this.contractRepo.findOne({
|
||||
where: { uuid },
|
||||
relations: ['project'],
|
||||
});
|
||||
if (!contract)
|
||||
throw new NotFoundException(`Contract UUID ${uuid} not found`);
|
||||
return contract;
|
||||
}
|
||||
|
||||
async update(uuid: string, dto: UpdateContractDto) {
|
||||
const contract = await this.findOneByUuid(uuid);
|
||||
Object.assign(contract, dto);
|
||||
return this.contractRepo.save(contract);
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
const contract = await this.findOne(id);
|
||||
// Schema doesn't have deleted_at for Contract either.
|
||||
async remove(uuid: string) {
|
||||
const contract = await this.findOneByUuid(uuid);
|
||||
return this.contractRepo.remove(contract);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,34 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
BeforeInsert,
|
||||
} from 'typeorm';
|
||||
import { v7 as uuidv7 } from 'uuid';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Project } from '../../project/entities/project.entity';
|
||||
|
||||
@Entity('contracts')
|
||||
export class Contract extends BaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number;
|
||||
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
unique: true,
|
||||
nullable: false,
|
||||
comment: 'UUID Public Identifier (ADR-019)',
|
||||
})
|
||||
uuid!: string;
|
||||
|
||||
@BeforeInsert()
|
||||
generateUuid(): void {
|
||||
if (!this.uuid) {
|
||||
this.uuid = uuidv7();
|
||||
}
|
||||
}
|
||||
|
||||
@Column({ name: 'project_id' })
|
||||
projectId!: number;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user