This commit is contained in:
@@ -38,10 +38,9 @@ export class TransmittalItemDto {
|
||||
}
|
||||
|
||||
export class CreateTransmittalDto {
|
||||
@ApiProperty({ description: 'ID ของโครงการ', example: 1 })
|
||||
@IsInt()
|
||||
@ApiProperty({ description: 'ID หรือ UUID ของโครงการ (ADR-019)' })
|
||||
@IsNotEmpty()
|
||||
projectId!: number;
|
||||
projectId!: number | string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'เรื่อง',
|
||||
@@ -51,10 +50,16 @@ export class CreateTransmittalDto {
|
||||
@IsNotEmpty()
|
||||
subject!: string;
|
||||
|
||||
@ApiProperty({ description: 'ผู้รับ (Organization ID)', example: 2 })
|
||||
@IsInt()
|
||||
@ApiProperty({ description: 'ผู้รับ Organization ID หรือ UUID (ADR-019)' })
|
||||
@IsNotEmpty()
|
||||
recipientOrganizationId!: number;
|
||||
recipientOrganizationId!: number | string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Correspondence ID หรือ UUID (ADR-019)',
|
||||
required: false,
|
||||
})
|
||||
@IsOptional()
|
||||
correspondenceId?: number | string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'วัตถุประสงค์',
|
||||
@@ -65,6 +70,11 @@ export class CreateTransmittalDto {
|
||||
@IsOptional()
|
||||
purpose?: TransmittalPurpose;
|
||||
|
||||
@ApiProperty({ description: 'หมายเหตุ', required: false })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
remarks?: string;
|
||||
|
||||
@ApiProperty({ description: 'รายการที่แนบ', type: [TransmittalItemDto] })
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
|
||||
@@ -21,6 +21,8 @@ import { CorrespondenceRevision } from '../correspondence/entities/correspondenc
|
||||
import { CorrespondenceType } from '../correspondence/entities/correspondence-type.entity';
|
||||
import { CorrespondenceStatus } from '../correspondence/entities/correspondence-status.entity';
|
||||
import { Project } from '../project/entities/project.entity';
|
||||
import { Organization } from '../organization/entities/organization.entity';
|
||||
import { CorrespondenceRecipient } from '../correspondence/entities/correspondence-recipient.entity';
|
||||
|
||||
@Injectable()
|
||||
export class TransmittalService {
|
||||
@@ -55,6 +57,22 @@ export class TransmittalService {
|
||||
return project.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* ADR-019: Resolve organizationId (INT or UUID string) to internal INT ID
|
||||
*/
|
||||
private async resolveOrganizationId(orgId: number | string): Promise<number> {
|
||||
if (typeof orgId === 'number') return orgId;
|
||||
const num = Number(orgId);
|
||||
if (!isNaN(num)) return num;
|
||||
const org = await this.dataSource.manager.findOne(Organization, {
|
||||
where: { uuid: orgId },
|
||||
select: ['id'],
|
||||
});
|
||||
if (!org)
|
||||
throw new NotFoundException(`Organization with UUID ${orgId} not found`);
|
||||
return org.id;
|
||||
}
|
||||
|
||||
async create(createDto: CreateTransmittalDto, user: User) {
|
||||
// 1. Get Transmittal Type (Assuming Code '901' or 'TRN')
|
||||
const type = await this.typeRepo.findOne({
|
||||
@@ -119,11 +137,22 @@ export class TransmittalService {
|
||||
});
|
||||
await queryRunner.manager.save(revision);
|
||||
|
||||
// ADR-019: Resolve recipientOrganizationId UUID→INT and create recipient record
|
||||
const internalRecipientOrgId = await this.resolveOrganizationId(
|
||||
createDto.recipientOrganizationId
|
||||
);
|
||||
const recipient = queryRunner.manager.create(CorrespondenceRecipient, {
|
||||
correspondenceId: savedCorr.id,
|
||||
recipientOrganizationId: internalRecipientOrgId,
|
||||
recipientType: 'TO',
|
||||
});
|
||||
await queryRunner.manager.save(recipient);
|
||||
|
||||
// 5. Create Transmittal
|
||||
const transmittal = queryRunner.manager.create(Transmittal, {
|
||||
correspondenceId: savedCorr.id,
|
||||
purpose: 'FOR_REVIEW', // Default or from DTO
|
||||
// remarks: createDto.remarks, // Add if in DTO
|
||||
purpose: createDto.purpose || 'FOR_REVIEW',
|
||||
remarks: createDto.remarks,
|
||||
});
|
||||
const savedTransmittal = await queryRunner.manager.save(transmittal);
|
||||
|
||||
@@ -169,7 +198,6 @@ export class TransmittalService {
|
||||
if (!correspondence) {
|
||||
throw new NotFoundException(`Transmittal with UUID ${uuid} not found`);
|
||||
}
|
||||
return this.findOne(correspondence.id);
|
||||
}
|
||||
|
||||
async findOne(id: number) {
|
||||
|
||||
Reference in New Issue
Block a user