This commit is contained in:
@@ -13,7 +13,6 @@ import { ShopDrawingRevision } from './entities/shop-drawing-revision.entity';
|
||||
import { ContractDrawing } from './entities/contract-drawing.entity';
|
||||
import { Attachment } from '../../common/file-storage/entities/attachment.entity';
|
||||
import { User } from '../user/entities/user.entity';
|
||||
import { Project } from '../project/entities/project.entity';
|
||||
|
||||
// DTOs
|
||||
import { CreateShopDrawingDto } from './dto/create-shop-drawing.dto';
|
||||
@@ -22,6 +21,7 @@ import { SearchShopDrawingDto } from './dto/search-shop-drawing.dto';
|
||||
|
||||
// Services
|
||||
import { FileStorageService } from '../../common/file-storage/file-storage.service';
|
||||
import { UuidResolverService } from '../../common/services/uuid-resolver.service';
|
||||
|
||||
@Injectable()
|
||||
export class ShopDrawingService {
|
||||
@@ -37,25 +37,10 @@ export class ShopDrawingService {
|
||||
@InjectRepository(Attachment)
|
||||
private attachmentRepo: Repository<Attachment>,
|
||||
private fileStorageService: FileStorageService,
|
||||
private dataSource: DataSource
|
||||
private dataSource: DataSource,
|
||||
private uuidResolver: UuidResolverService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* ADR-019: Resolve projectId (INT or UUID string) to internal INT ID
|
||||
*/
|
||||
private async resolveProjectId(projectId: number | string): Promise<number> {
|
||||
if (typeof projectId === 'number') return projectId;
|
||||
const num = Number(projectId);
|
||||
if (!isNaN(num)) return num;
|
||||
const project = await this.dataSource.manager.findOne(Project, {
|
||||
where: { uuid: projectId },
|
||||
select: ['id'],
|
||||
});
|
||||
if (!project)
|
||||
throw new NotFoundException(`Project with UUID ${projectId} not found`);
|
||||
return project.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* สร้าง Shop Drawing ใหม่ พร้อม Revision แรก (Rev 0)
|
||||
*/
|
||||
@@ -91,7 +76,7 @@ export class ShopDrawingService {
|
||||
}
|
||||
|
||||
// ADR-019: Resolve UUID→INT
|
||||
const internalProjectId = await this.resolveProjectId(
|
||||
const internalProjectId = await this.uuidResolver.resolveProjectId(
|
||||
createDto.projectId
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user