260316:1347 Refactor to NestJS 11 #2
Build and Deploy / deploy (push) Failing after 2m19s

This commit is contained in:
admin
2026-03-16 13:47:35 +07:00
parent a75ba3105f
commit f13861f02e
17 changed files with 544 additions and 563 deletions
@@ -38,28 +38,16 @@ export class DrawingMasterDataController {
@Get('contract/volumes')
@ApiOperation({ summary: 'List Contract Drawing Volumes' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@RequirePermission('document.view')
getVolumes(@Query('projectId', ParseIntPipe) projectId: number) {
this.logger.log(`Fetching Contract Volumes for Project ID: ${projectId}`);
getVolumes(@Query('projectId') projectId: string | number) {
return this.masterDataService.findAllVolumes(projectId);
}
// ... (Create/Update/Delete methods remain unchanged) ...
@Post('contract/volumes')
@ApiOperation({ summary: 'Create Volume' })
@RequirePermission('master_data.drawing_category.manage')
createVolume(
@Body()
body: {
projectId: number;
volumeCode: string;
volumeName: string;
description?: string;
sortOrder: number;
}
) {
createVolume(@Body() body: any) {
return this.masterDataService.createVolume(body);
}
@@ -68,13 +56,7 @@ export class DrawingMasterDataController {
@RequirePermission('master_data.drawing_category.manage')
updateVolume(
@Param('id', ParseIntPipe) id: number,
@Body()
body: {
volumeCode?: string;
volumeName?: string;
description?: string;
sortOrder?: number;
}
@Body() body: any
) {
return this.masterDataService.updateVolume(id, body);
}
@@ -92,30 +74,16 @@ export class DrawingMasterDataController {
@Get('contract/categories')
@ApiOperation({ summary: 'List Contract Drawing Categories' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@RequirePermission('document.view')
getCategories(@Query('projectId', ParseIntPipe) projectId: number) {
this.logger.log(
`Fetching Contract Categories for Project ID: ${projectId}`
);
getCategories(@Query('projectId') projectId: string | number) {
return this.masterDataService.findAllCategories(projectId);
}
// ... (Create/Update/Delete methods remain unchanged) ...
@Post('contract/categories')
@ApiOperation({ summary: 'Create Category' })
@RequirePermission('master_data.drawing_category.manage')
createCategory(
@Body()
body: {
projectId: number;
catCode: string;
catName: string;
description?: string;
sortOrder: number;
}
) {
createCategory(@Body() body: any) {
return this.masterDataService.createCategory(body);
}
@@ -124,13 +92,7 @@ export class DrawingMasterDataController {
@RequirePermission('master_data.drawing_category.manage')
updateCategory(
@Param('id', ParseIntPipe) id: number,
@Body()
body: {
catCode?: string;
catName?: string;
description?: string;
sortOrder?: number;
}
@Body() body: any
) {
return this.masterDataService.updateCategory(id, body);
}
@@ -148,30 +110,16 @@ export class DrawingMasterDataController {
@Get('contract/sub-categories')
@ApiOperation({ summary: 'List Contract Drawing Sub-Categories' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@RequirePermission('document.view')
getContractSubCats(@Query('projectId', ParseIntPipe) projectId: number) {
this.logger.log(
`Fetching Contract Sub-Categories for Project ID: ${projectId}`
);
getContractSubCats(@Query('projectId') projectId: string | number) {
return this.masterDataService.findAllContractSubCats(projectId);
}
// ... (Create/Update/Delete methods remain unchanged) ...
@Post('contract/sub-categories')
@ApiOperation({ summary: 'Create Contract Sub-Category' })
@RequirePermission('master_data.drawing_category.manage')
createContractSubCat(
@Body()
body: {
projectId: number;
subCatCode: string;
subCatName: string;
description?: string;
sortOrder: number;
}
) {
createContractSubCat(@Body() body: any) {
return this.masterDataService.createContractSubCat(body);
}
@@ -180,18 +128,15 @@ export class DrawingMasterDataController {
@RequirePermission('master_data.drawing_category.manage')
updateContractSubCat(
@Param('id', ParseIntPipe) id: number,
@Body()
body: {
subCatCode?: string;
subCatName?: string;
description?: string;
sortOrder?: number;
}
@Body() body: any
) {
return this.masterDataService.updateContractSubCat(id, body);
}
async deleteContractSubCat(@Param('id', ParseIntPipe) id: number) {
@Delete('contract/sub-categories/:id')
@ApiOperation({ summary: 'Delete Contract Sub-Category' })
@RequirePermission('master_data.drawing_category.manage')
deleteContractSubCat(@Param('id', ParseIntPipe) id: number) {
return this.masterDataService.deleteContractSubCat(id);
}
@@ -201,11 +146,11 @@ export class DrawingMasterDataController {
@Get('contract/mappings')
@ApiOperation({ summary: 'List Contract Drawing Mappings' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@ApiQuery({ name: 'categoryId', required: false, type: Number })
@RequirePermission('document.view')
getContractMappings(
@Query('projectId', ParseIntPipe) projectId: number,
@Query('projectId') projectId: string | number,
@Query('categoryId') categoryId?: number
) {
return this.masterDataService.findContractMappings(
@@ -217,14 +162,7 @@ export class DrawingMasterDataController {
@Post('contract/mappings')
@ApiOperation({ summary: 'Create Contract Drawing Mapping' })
@RequirePermission('master_data.drawing_category.manage')
createContractMapping(
@Body()
body: {
projectId: number;
categoryId: number;
subCategoryId: number;
}
) {
createContractMapping(@Body() body: any) {
return this.masterDataService.createContractMapping(body);
}
@@ -241,31 +179,16 @@ export class DrawingMasterDataController {
@Get('shop/main-categories')
@ApiOperation({ summary: 'List Shop Drawing Main Categories' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@RequirePermission('document.view')
getShopMainCats(@Query('projectId', ParseIntPipe) projectId: number) {
this.logger.log(
`Fetching Shop Main Categories for Project ID: ${projectId}`
);
getShopMainCats(@Query('projectId') projectId: string | number) {
return this.masterDataService.findAllShopMainCats(projectId);
}
// ... (Create/Update/Delete methods remain unchanged) ...
@Post('shop/main-categories')
@ApiOperation({ summary: 'Create Shop Main Category' })
@RequirePermission('master_data.drawing_category.manage')
createShopMainCat(
@Body()
body: {
projectId: number;
mainCategoryCode: string;
mainCategoryName: string;
description?: string;
isActive?: boolean;
sortOrder: number;
}
) {
createShopMainCat(@Body() body: any) {
return this.masterDataService.createShopMainCat(body);
}
@@ -274,14 +197,7 @@ export class DrawingMasterDataController {
@RequirePermission('master_data.drawing_category.manage')
updateShopMainCat(
@Param('id', ParseIntPipe) id: number,
@Body()
body: {
mainCategoryCode?: string;
mainCategoryName?: string;
description?: string;
isActive?: boolean;
sortOrder?: number;
}
@Body() body: any
) {
return this.masterDataService.updateShopMainCat(id, body);
}
@@ -299,16 +215,13 @@ export class DrawingMasterDataController {
@Get('shop/sub-categories')
@ApiOperation({ summary: 'List Shop Drawing Sub-Categories' })
@ApiQuery({ name: 'projectId', required: true, type: Number })
@ApiQuery({ name: 'projectId', required: true, type: String })
@ApiQuery({ name: 'mainCategoryId', required: false, type: Number })
@RequirePermission('document.view')
getShopSubCats(
@Query('projectId', ParseIntPipe) projectId: number,
@Query('projectId') projectId: string | number,
@Query('mainCategoryId') mainCategoryId?: number
) {
this.logger.log(
`Fetching Shop Sub-Categories for Project ID: ${projectId}, MainCategory: ${mainCategoryId}`
);
return this.masterDataService.findAllShopSubCats(
projectId,
mainCategoryId ? Number(mainCategoryId) : undefined
@@ -318,17 +231,7 @@ export class DrawingMasterDataController {
@Post('shop/sub-categories')
@ApiOperation({ summary: 'Create Shop Sub-Category' })
@RequirePermission('master_data.drawing_category.manage')
createShopSubCat(
@Body()
body: {
projectId: number;
subCategoryCode: string;
subCategoryName: string;
description?: string;
isActive?: boolean;
sortOrder: number;
}
) {
createShopSubCat(@Body() body: any) {
return this.masterDataService.createShopSubCat(body);
}
@@ -337,14 +240,7 @@ export class DrawingMasterDataController {
@RequirePermission('master_data.drawing_category.manage')
updateShopSubCat(
@Param('id', ParseIntPipe) id: number,
@Body()
body: {
subCategoryCode?: string;
subCategoryName?: string;
description?: string;
isActive?: boolean;
sortOrder?: number;
}
@Body() body: any
) {
return this.masterDataService.updateShopSubCat(id, body);
}
@@ -1,6 +1,6 @@
import { Injectable, NotFoundException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, FindOptionsWhere } from 'typeorm';
import { InjectRepository, InjectEntityManager } from '@nestjs/typeorm';
import { Repository, FindOptionsWhere, EntityManager } from 'typeorm';
// Entities
import { ContractDrawingVolume } from './entities/contract-drawing-volume.entity';
@@ -9,6 +9,7 @@ import { ContractDrawingSubCategory } from './entities/contract-drawing-sub-cate
import { ShopDrawingMainCategory } from './entities/shop-drawing-main-category.entity';
import { ShopDrawingSubCategory } from './entities/shop-drawing-sub-category.entity';
import { ContractDrawingSubcatCatMap } from './entities/contract-drawing-subcat-cat-map.entity';
import { Project } from '../project/entities/project.entity';
@Injectable()
export class DrawingMasterDataService {
@@ -24,22 +25,47 @@ export class DrawingMasterDataService {
@InjectRepository(ShopDrawingSubCategory)
private sdSubCatRepo: Repository<ShopDrawingSubCategory>,
@InjectRepository(ContractDrawingSubcatCatMap)
private cdMapRepo: Repository<ContractDrawingSubcatCatMap>
private cdMapRepo: Repository<ContractDrawingSubcatCatMap>,
@InjectEntityManager()
private entityManager: EntityManager
) {}
/**
* Helper to resolve projectId (ID or UUID) to internal INT ID
*/
async resolveProjectId(projectId: number | string): Promise<number> {
if (typeof projectId === 'number') return projectId;
const num = Number(projectId);
if (!isNaN(num)) return num;
// If it's a string and not a number, it's a UUID (ADR-019)
const project = await this.entityManager.findOne(Project, {
where: { uuid: projectId as string },
select: ['id'],
});
if (!project) {
throw new NotFoundException(`Project with UUID ${projectId} not found`);
}
return project.id;
}
// =====================================================
// Contract Drawing Volumes
// =====================================================
async findAllVolumes(projectId: number) {
async findAllVolumes(projectId: number | string) {
const internalId = await this.resolveProjectId(projectId);
return this.cdVolumeRepo.find({
where: { projectId },
where: { projectId: internalId },
order: { sortOrder: 'ASC' },
});
}
async createVolume(data: Partial<ContractDrawingVolume>) {
const volume = this.cdVolumeRepo.create(data);
async createVolume(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
const volume = this.cdVolumeRepo.create({ ...data, projectId: internalId });
return this.cdVolumeRepo.save(volume);
}
@@ -61,15 +87,17 @@ export class DrawingMasterDataService {
// Contract Drawing Categories
// =====================================================
async findAllCategories(projectId: number) {
async findAllCategories(projectId: number | string) {
const internalId = await this.resolveProjectId(projectId);
return this.cdCatRepo.find({
where: { projectId },
where: { projectId: internalId },
order: { sortOrder: 'ASC' },
});
}
async createCategory(data: Partial<ContractDrawingCategory>) {
const cat = this.cdCatRepo.create(data);
async createCategory(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
const cat = this.cdCatRepo.create({ ...data, projectId: internalId });
return this.cdCatRepo.save(cat);
}
@@ -91,15 +119,17 @@ export class DrawingMasterDataService {
// Contract Drawing Sub-Categories
// =====================================================
async findAllContractSubCats(projectId: number) {
async findAllContractSubCats(projectId: number | string) {
const internalId = await this.resolveProjectId(projectId);
return this.cdSubCatRepo.find({
where: { projectId },
where: { projectId: internalId },
order: { sortOrder: 'ASC' },
});
}
async createContractSubCat(data: Partial<ContractDrawingSubCategory>) {
const subCat = this.cdSubCatRepo.create(data);
async createContractSubCat(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
const subCat = this.cdSubCatRepo.create({ ...data, projectId: internalId });
return this.cdSubCatRepo.save(subCat);
}
@@ -124,8 +154,9 @@ export class DrawingMasterDataService {
// Contract Drawing Mappings (Category <-> Sub-Category)
// =====================================================
async findContractMappings(projectId: number, categoryId?: number) {
const where: FindOptionsWhere<ContractDrawingSubcatCatMap> = { projectId };
async findContractMappings(projectId: number | string, categoryId?: number) {
const internalId = await this.resolveProjectId(projectId);
const where: FindOptionsWhere<ContractDrawingSubcatCatMap> = { projectId: internalId };
if (categoryId) {
where.categoryId = categoryId;
}
@@ -136,15 +167,12 @@ export class DrawingMasterDataService {
});
}
async createContractMapping(data: {
projectId: number;
categoryId: number;
subCategoryId: number;
}) {
async createContractMapping(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
// Check if mapping already exists to prevent duplicates (though DB has UNIQUE constraint)
const existing = await this.cdMapRepo.findOne({
where: {
projectId: data.projectId,
projectId: internalId,
categoryId: data.categoryId,
subCategoryId: data.subCategoryId,
},
@@ -152,7 +180,7 @@ export class DrawingMasterDataService {
if (existing) return existing;
const map = this.cdMapRepo.create(data);
const map = this.cdMapRepo.create({ ...data, projectId: internalId });
return this.cdMapRepo.save(map);
}
@@ -167,15 +195,17 @@ export class DrawingMasterDataService {
// Shop Drawing Main Categories
// =====================================================
async findAllShopMainCats(projectId: number) {
async findAllShopMainCats(projectId: number | string) {
const internalId = await this.resolveProjectId(projectId);
return this.sdMainCatRepo.find({
where: { projectId },
where: { projectId: internalId },
order: { sortOrder: 'ASC' },
});
}
async createShopMainCat(data: Partial<ShopDrawingMainCategory>) {
const cat = this.sdMainCatRepo.create(data);
async createShopMainCat(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
const cat = this.sdMainCatRepo.create({ ...data, projectId: internalId });
return this.sdMainCatRepo.save(cat);
}
@@ -197,9 +227,10 @@ export class DrawingMasterDataService {
// Shop Drawing Sub-Categories
// =====================================================
async findAllShopSubCats(projectId: number, mainCategoryId?: number) {
async findAllShopSubCats(projectId: number | string, mainCategoryId?: number) {
const internalId = await this.resolveProjectId(projectId);
const where: FindOptionsWhere<ShopDrawingSubCategory> = {
projectId,
projectId: internalId,
...(mainCategoryId ? { mainCategoryId } : {}),
};
@@ -209,8 +240,9 @@ export class DrawingMasterDataService {
});
}
async createShopSubCat(data: Partial<ShopDrawingSubCategory>) {
const subCat = this.sdSubCatRepo.create(data);
async createShopSubCat(data: any) {
const internalId = await this.resolveProjectId(data.projectId);
const subCat = this.sdSubCatRepo.create({ ...data, projectId: internalId });
return this.sdSubCatRepo.save(subCat);
}