This commit is contained in:
@@ -6,7 +6,6 @@ import {
|
||||
Body,
|
||||
Param,
|
||||
Query,
|
||||
ParseIntPipe,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
UseGuards,
|
||||
@@ -34,6 +33,7 @@ import { SearchAsBuiltDrawingDto } from './dto/search-asbuilt-drawing.dto';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { Audit } from '../../common/decorators/audit.decorator';
|
||||
import { ParseUuidPipe } from '../../common/pipes/parse-uuid.pipe';
|
||||
import { User } from '../user/entities/user.entity';
|
||||
|
||||
@ApiTags('Drawings - AS Built')
|
||||
@@ -56,16 +56,17 @@ export class AsBuiltDrawingController {
|
||||
return this.asBuiltDrawingService.create(createDto, user);
|
||||
}
|
||||
|
||||
@Post(':id/revisions')
|
||||
@Post(':uuid/revisions')
|
||||
@ApiOperation({ summary: 'Create new revision for AS Built Drawing' })
|
||||
@ApiResponse({ status: 201, description: 'Revision created' })
|
||||
@ApiResponse({ status: 404, description: 'AS Built Drawing not found' })
|
||||
@ApiResponse({ status: 409, description: 'Revision label already exists' })
|
||||
async createRevision(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@Body() createDto: CreateAsBuiltDrawingRevisionDto
|
||||
) {
|
||||
return this.asBuiltDrawingService.createRevision(id, createDto);
|
||||
const drawing = await this.asBuiltDrawingService.findOneByUuid(uuid);
|
||||
return this.asBuiltDrawingService.createRevision(drawing.id, createDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@@ -76,16 +77,16 @@ export class AsBuiltDrawingController {
|
||||
return this.asBuiltDrawingService.findAll(searchDto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get AS Built Drawing by ID' })
|
||||
@Get(':uuid')
|
||||
@ApiOperation({ summary: 'Get AS Built Drawing by UUID' })
|
||||
@ApiResponse({ status: 200, description: 'AS Built Drawing details' })
|
||||
@ApiResponse({ status: 404, description: 'AS Built Drawing not found' })
|
||||
@RequirePermission('drawing.view')
|
||||
async findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.asBuiltDrawingService.findOne(id);
|
||||
async findOne(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.asBuiltDrawingService.findOneByUuid(uuid);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(':uuid')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@ApiOperation({ summary: 'Soft delete AS Built Drawing' })
|
||||
@ApiResponse({ status: 204, description: 'AS Built Drawing deleted' })
|
||||
@@ -93,9 +94,10 @@ export class AsBuiltDrawingController {
|
||||
@RequirePermission('drawing.delete')
|
||||
@Audit('drawing.delete', 'asbuilt_drawing')
|
||||
async remove(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@CurrentUser() user: User
|
||||
) {
|
||||
return this.asBuiltDrawingService.remove(id, user);
|
||||
const drawing = await this.asBuiltDrawingService.findOneByUuid(uuid);
|
||||
return this.asBuiltDrawingService.remove(drawing.id, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,6 +295,28 @@ export class AsBuiltDrawingService {
|
||||
return asBuiltDrawing;
|
||||
}
|
||||
|
||||
async findOneByUuid(uuid: string) {
|
||||
const asBuiltDrawing = await this.asBuiltDrawingRepo.findOne({
|
||||
where: { uuid },
|
||||
relations: [
|
||||
'mainCategory',
|
||||
'subCategory',
|
||||
'revisions',
|
||||
'revisions.attachments',
|
||||
'revisions.shopDrawingRevisions',
|
||||
],
|
||||
order: {
|
||||
revisions: { revisionNumber: 'DESC' },
|
||||
},
|
||||
});
|
||||
|
||||
if (!asBuiltDrawing) {
|
||||
throw new NotFoundException(`AS Built Drawing UUID ${uuid} not found`);
|
||||
}
|
||||
|
||||
return asBuiltDrawing;
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบ AS Built Drawing
|
||||
*/
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
Put,
|
||||
Query,
|
||||
UseGuards,
|
||||
ParseIntPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
|
||||
@@ -20,6 +19,7 @@ import { SearchContractDrawingDto } from './dto/search-contract-drawing.dto';
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { RbacGuard } from '../../common/guards/rbac.guard';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { ParseUuidPipe } from '../../common/pipes/parse-uuid.pipe';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { User } from '../user/entities/user.entity';
|
||||
|
||||
@@ -51,28 +51,33 @@ export class ContractDrawingController {
|
||||
return this.contractDrawingService.findAll(searchDto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Get(':uuid')
|
||||
@ApiOperation({ summary: 'Get Contract Drawing details' })
|
||||
@RequirePermission('document.view')
|
||||
findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.contractDrawingService.findOne(id);
|
||||
findOne(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.contractDrawingService.findOneByUuid(uuid);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@Put(':uuid')
|
||||
@ApiOperation({ summary: 'Update Contract Drawing' })
|
||||
@RequirePermission('drawing.create') // สิทธิ์ ID 39 ครอบคลุมการแก้ไขด้วย
|
||||
update(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
async update(
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@Body() updateDto: UpdateContractDrawingDto,
|
||||
@CurrentUser() user: User
|
||||
) {
|
||||
return this.contractDrawingService.update(id, updateDto, user);
|
||||
const drawing = await this.contractDrawingService.findOneByUuid(uuid);
|
||||
return this.contractDrawingService.update(drawing.id, updateDto, user);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(':uuid')
|
||||
@ApiOperation({ summary: 'Delete Contract Drawing (Soft Delete)' })
|
||||
@RequirePermission('document.delete') // สิทธิ์ ID 34: ลบเอกสาร
|
||||
remove(@Param('id', ParseIntPipe) id: number, @CurrentUser() user: User) {
|
||||
return this.contractDrawingService.remove(id, user);
|
||||
async remove(
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@CurrentUser() user: User
|
||||
) {
|
||||
const drawing = await this.contractDrawingService.findOneByUuid(uuid);
|
||||
return this.contractDrawingService.remove(drawing.id, user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,19 @@ export class ContractDrawingService {
|
||||
return drawing;
|
||||
}
|
||||
|
||||
async findOneByUuid(uuid: string) {
|
||||
const drawing = await this.drawingRepo.findOne({
|
||||
where: { uuid },
|
||||
relations: ['attachments'],
|
||||
});
|
||||
|
||||
if (!drawing) {
|
||||
throw new NotFoundException(`Contract Drawing UUID ${uuid} not found`);
|
||||
}
|
||||
|
||||
return drawing;
|
||||
}
|
||||
|
||||
/**
|
||||
* แก้ไขข้อมูลแบบ (Update)
|
||||
*/
|
||||
|
||||
@@ -13,11 +13,14 @@ import { AsBuiltDrawing } from './asbuilt-drawing.entity';
|
||||
import { ShopDrawingRevision } from './shop-drawing-revision.entity';
|
||||
import { Attachment } from '../../../common/file-storage/entities/attachment.entity';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('asbuilt_drawing_revisions')
|
||||
@Unique(['asBuiltDrawingId', 'isCurrent'])
|
||||
export class AsBuiltDrawingRevision {
|
||||
export class AsBuiltDrawingRevision extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number;
|
||||
|
||||
@Column({ name: 'asbuilt_drawing_id' })
|
||||
|
||||
@@ -14,10 +14,13 @@ import { AsBuiltDrawingRevision } from './asbuilt-drawing-revision.entity';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { ShopDrawingMainCategory } from './shop-drawing-main-category.entity';
|
||||
import { ShopDrawingSubCategory } from './shop-drawing-sub-category.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('asbuilt_drawings')
|
||||
export class AsBuiltDrawing {
|
||||
export class AsBuiltDrawing extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number;
|
||||
|
||||
@Column({ name: 'project_id' })
|
||||
|
||||
@@ -15,10 +15,13 @@ import { User } from '../../user/entities/user.entity';
|
||||
import { Attachment } from '../../../common/file-storage/entities/attachment.entity';
|
||||
import { ContractDrawingSubcatCatMap } from './contract-drawing-subcat-cat-map.entity';
|
||||
import { ContractDrawingVolume } from './contract-drawing-volume.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('contract_drawings')
|
||||
export class ContractDrawing {
|
||||
export class ContractDrawing extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number; // ! ห้ามว่าง
|
||||
|
||||
@Column({ name: 'project_id' })
|
||||
|
||||
@@ -13,11 +13,14 @@ import { ShopDrawing } from './shop-drawing.entity';
|
||||
import { ContractDrawing } from './contract-drawing.entity';
|
||||
import { Attachment } from '../../../common/file-storage/entities/attachment.entity';
|
||||
import { User } from '../../user/entities/user.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('shop_drawing_revisions')
|
||||
@Unique(['shopDrawingId', 'isCurrent'])
|
||||
export class ShopDrawingRevision {
|
||||
export class ShopDrawingRevision extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number; // เติม !
|
||||
|
||||
@Column({ name: 'shop_drawing_id' })
|
||||
|
||||
@@ -13,10 +13,13 @@ import { ShopDrawingRevision } from './shop-drawing-revision.entity';
|
||||
import { Project } from '../../project/entities/project.entity';
|
||||
import { ShopDrawingMainCategory } from './shop-drawing-main-category.entity';
|
||||
import { ShopDrawingSubCategory } from './shop-drawing-sub-category.entity';
|
||||
import { UuidBaseEntity } from '../../../common/entities/uuid-base.entity';
|
||||
import { Exclude } from 'class-transformer';
|
||||
|
||||
@Entity('shop_drawings')
|
||||
export class ShopDrawing {
|
||||
export class ShopDrawing extends UuidBaseEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
@Exclude()
|
||||
id!: number; // เติม !
|
||||
|
||||
@Column({ name: 'project_id' })
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
Param,
|
||||
Query,
|
||||
UseGuards,
|
||||
ParseIntPipe,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
|
||||
|
||||
@@ -18,6 +17,7 @@ import { CreateShopDrawingRevisionDto } from './dto/create-shop-drawing-revision
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { RbacGuard } from '../../common/guards/rbac.guard';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { ParseUuidPipe } from '../../common/pipes/parse-uuid.pipe';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
import { User } from '../user/entities/user.entity';
|
||||
import { Audit } from '../../common/decorators/audit.decorator'; // Import
|
||||
@@ -44,21 +44,22 @@ export class ShopDrawingController {
|
||||
return this.shopDrawingService.findAll(searchDto);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@Get(':uuid')
|
||||
@ApiOperation({ summary: 'Get Shop Drawing details with revisions' })
|
||||
@RequirePermission('drawing.view')
|
||||
findOne(@Param('id', ParseIntPipe) id: number) {
|
||||
return this.shopDrawingService.findOne(id);
|
||||
findOne(@Param('uuid', ParseUuidPipe) uuid: string) {
|
||||
return this.shopDrawingService.findOneByUuid(uuid);
|
||||
}
|
||||
|
||||
@Post(':id/revisions')
|
||||
@Post(':uuid/revisions')
|
||||
@ApiOperation({ summary: 'Add new revision to existing Shop Drawing' })
|
||||
@RequirePermission('drawing.create') // หรือ drawing.edit ตาม Logic องค์กร
|
||||
@Audit('drawing.create', 'shop_drawing') // ✅ แปะตรงนี้
|
||||
createRevision(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() createRevisionDto: CreateShopDrawingRevisionDto,
|
||||
async createRevision(
|
||||
@Param('uuid', ParseUuidPipe) uuid: string,
|
||||
@Body() createRevisionDto: CreateShopDrawingRevisionDto
|
||||
) {
|
||||
return this.shopDrawingService.createRevision(id, createRevisionDto);
|
||||
const sd = await this.shopDrawingService.findOneByUuid(uuid);
|
||||
return this.shopDrawingService.createRevision(sd.id, createRevisionDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,6 +289,28 @@ export class ShopDrawingService {
|
||||
return shopDrawing;
|
||||
}
|
||||
|
||||
async findOneByUuid(uuid: string) {
|
||||
const shopDrawing = await this.shopDrawingRepo.findOne({
|
||||
where: { uuid },
|
||||
relations: [
|
||||
'mainCategory',
|
||||
'subCategory',
|
||||
'revisions',
|
||||
'revisions.attachments',
|
||||
'revisions.contractDrawings',
|
||||
],
|
||||
order: {
|
||||
revisions: { revisionNumber: 'DESC' },
|
||||
},
|
||||
});
|
||||
|
||||
if (!shopDrawing) {
|
||||
throw new NotFoundException(`Shop Drawing UUID ${uuid} not found`);
|
||||
}
|
||||
|
||||
return shopDrawing;
|
||||
}
|
||||
|
||||
/**
|
||||
* ลบ Shop Drawing
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user