260326:1347 Fixing Refactor ADR-019 Naming convention uuid #01
This commit is contained in:
@@ -100,18 +100,20 @@ export class ContractService {
|
||||
return contract;
|
||||
}
|
||||
|
||||
async findOneByUuid(uuid: string) {
|
||||
async findOneByPublicId(publicId: string) {
|
||||
const contract = await this.contractRepo.findOne({
|
||||
where: { uuid },
|
||||
where: { publicId },
|
||||
relations: ['project'],
|
||||
});
|
||||
if (!contract)
|
||||
throw new NotFoundException(`Contract UUID ${uuid} not found`);
|
||||
throw new NotFoundException(
|
||||
`Contract with publicId ${publicId} not found`
|
||||
);
|
||||
return contract;
|
||||
}
|
||||
|
||||
async update(uuid: string, dto: UpdateContractDto) {
|
||||
const contract = await this.findOneByUuid(uuid);
|
||||
async update(publicId: string, dto: UpdateContractDto) {
|
||||
const contract = await this.findOneByPublicId(publicId);
|
||||
if (dto.projectId) {
|
||||
dto.projectId = await this.uuidResolver.resolveProjectId(dto.projectId);
|
||||
}
|
||||
@@ -119,8 +121,8 @@ export class ContractService {
|
||||
return this.contractRepo.save(contract);
|
||||
}
|
||||
|
||||
async remove(uuid: string) {
|
||||
const contract = await this.findOneByUuid(uuid);
|
||||
async remove(publicId: string) {
|
||||
const contract = await this.findOneByPublicId(publicId);
|
||||
return this.contractRepo.remove(contract);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,34 +4,18 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
ManyToOne,
|
||||
JoinColumn,
|
||||
BeforeInsert,
|
||||
} from 'typeorm';
|
||||
import { v7 as uuidv7 } from 'uuid';
|
||||
import { Exclude, Expose } from 'class-transformer';
|
||||
import { BaseEntity } from '../../../common/entities/base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Project } from '../../project/entities/project.entity';
|
||||
|
||||
@Entity('contracts')
|
||||
export class Contract extends BaseEntity {
|
||||
export class Contract extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number;
|
||||
|
||||
@Expose({ name: 'id' })
|
||||
@Column({
|
||||
type: 'uuid',
|
||||
unique: true,
|
||||
nullable: false,
|
||||
comment: 'UUID Public Identifier (ADR-019)',
|
||||
})
|
||||
uuid!: string;
|
||||
|
||||
@BeforeInsert()
|
||||
generateUuid(): void {
|
||||
if (!this.uuid) {
|
||||
this.uuid = uuidv7();
|
||||
}
|
||||
}
|
||||
// publicId inherited from UuidBaseEntity (DB column: uuid)
|
||||
|
||||
@Column({ name: 'project_id' })
|
||||
projectId!: number;
|
||||
|
||||
Reference in New Issue
Block a user