690406:2310 Done Task BE-ERR-01
CI / CD Pipeline / build (push) Failing after 4m53s
CI / CD Pipeline / deploy (push) Has been skipped

This commit is contained in:
2026-04-06 23:10:56 +07:00
parent c95e0f537e
commit 961ee72343
24 changed files with 1329 additions and 268 deletions
@@ -1,13 +1,12 @@
// File: src/modules/json-schema/json-schema.service.ts
// บันทึกการแก้ไข: Fix TS2345 (undefined check)
import { Injectable, Logger, OnModuleInit } from '@nestjs/common';
import {
BadRequestException,
Injectable,
Logger,
BusinessException,
NotFoundException,
OnModuleInit,
} from '@nestjs/common';
ValidationException,
} from '../../common/exceptions';
import { InjectRepository } from '@nestjs/typeorm';
import Ajv, { ValidateFunction } from 'ajv';
import addFormats from 'ajv-formats';
@@ -101,7 +100,7 @@ export class JsonSchemaService implements OnModuleInit {
try {
this.ajv.compile(createDto.schemaDefinition);
} catch (error: unknown) {
throw new BadRequestException(
throw new ValidationException(
`Invalid JSON Schema format: ${error instanceof Error ? error.message : String(error)}`
);
}
@@ -207,7 +206,7 @@ export class JsonSchemaService implements OnModuleInit {
async findOne(id: number): Promise<JsonSchema> {
const schema = await this.jsonSchemaRepository.findOne({ where: { id } });
if (!schema) {
throw new NotFoundException(`JsonSchema with ID ${id} not found`);
throw new NotFoundException('JsonSchema', String(id));
}
return schema;
}
@@ -224,9 +223,7 @@ export class JsonSchemaService implements OnModuleInit {
});
if (!schema) {
throw new NotFoundException(
`JsonSchema '${code}' version ${version} not found`
);
throw new NotFoundException('JsonSchema', `${code}@v${version}`);
}
return schema;
}
@@ -241,9 +238,7 @@ export class JsonSchemaService implements OnModuleInit {
});
if (!schema) {
throw new NotFoundException(
`Active JsonSchema with code '${code}' not found`
);
throw new NotFoundException('Active JsonSchema', code);
}
return schema;
}
@@ -333,8 +328,10 @@ export class JsonSchemaService implements OnModuleInit {
validate = this.ajv.compile(schema.schemaDefinition);
this.validators.set(schemaCode, validate);
} catch (error: unknown) {
throw new BadRequestException(
`Invalid Schema Definition for '${schemaCode}': ${error instanceof Error ? error.message : String(error)}`
throw new BusinessException(
'INVALID_SCHEMA_DEFINITION',
`Invalid Schema Definition for '${schemaCode}': ${error instanceof Error ? error.message : String(error)}`,
'Schema Definition ไม่ถูกต้อง'
);
}
}
@@ -353,7 +350,7 @@ export class JsonSchemaService implements OnModuleInit {
const errorMsg = result.errors
.map((e) => `${e.field}: ${e.message}`)
.join(', ');
throw new BadRequestException(`JSON Validation Failed: ${errorMsg}`);
throw new ValidationException(`JSON Validation Failed: ${errorMsg}`);
}
return true;
}
@@ -372,7 +369,7 @@ export class JsonSchemaService implements OnModuleInit {
try {
this.ajv.compile(updateDto.schemaDefinition);
} catch (error: unknown) {
throw new BadRequestException(
throw new ValidationException(
`Invalid JSON Schema format: ${error instanceof Error ? error.message : String(error)}`
);
}
@@ -1,5 +1,9 @@
// File: src/modules/json-schema/services/schema-migration.service.ts
import { Injectable, Logger, BadRequestException } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import {
BusinessException,
NotFoundException,
} from '../../../common/exceptions';
import { DataSource } from 'typeorm';
import { JsonSchemaService } from '../json-schema.service';
@@ -66,9 +70,7 @@ export class SchemaMigrationService {
]);
if (!entities || entities.length === 0) {
throw new BadRequestException(
`Entity ${entityType} with ID ${entityId} not found.`
);
throw new NotFoundException(entityType, String(entityId));
}
const entity = entities[0];
@@ -125,8 +127,10 @@ export class SchemaMigrationService {
);
if (!validation.isValid) {
throw new BadRequestException(
`Migration failed: Resulting data does not match target schema v${targetSchema.version}. Errors: ${JSON.stringify(validation.errors)}`
throw new BusinessException(
'SCHEMA_MIGRATION_VALIDATION_FAILED',
`Migration failed: Data does not match target schema v${targetSchema.version}`,
'การ Migration ล้มเหลว: ข้อมูลไม่ตรงกับ Schema เป้าหมาย'
);
}
@@ -1,5 +1,6 @@
// File: src/modules/json-schema/services/ui-schema.service.ts
import { Injectable, BadRequestException, Logger } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { ValidationException } from '../../../common/exceptions';
import {
UiSchema,
UiSchemaField,
@@ -21,8 +22,8 @@ export class UiSchemaService {
// 1. Validate Structure เบื้องต้น
if (!uiSchema.layout || !uiSchema.fields) {
throw new BadRequestException(
'UI Schema must contain "layout" and "fields" properties.'
throw new ValidationException(
'UI Schema must contain "layout" and "fields" properties'
);
}
@@ -34,7 +35,7 @@ export class UiSchemaService {
group.fields.forEach((fieldKey) => {
layoutFields.add(fieldKey);
if (!definedFields.has(fieldKey)) {
throw new BadRequestException(
throw new ValidationException(
`Field "${fieldKey}" used in layout "${group.title}" is not defined in "fields".`
);
}