260306:1535 20260306:1500 refactor tags
Some checks failed
Build and Deploy / deploy (push) Failing after 8m12s
Some checks failed
Build and Deploy / deploy (push) Failing after 8m12s
This commit is contained in:
@@ -5,6 +5,14 @@ import { Type } from 'class-transformer';
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
|
||||
export class SearchTagDto {
|
||||
@ApiPropertyOptional({
|
||||
description: 'ID โครงการ (ใช้กรอง Tag ของแต่ละโปรเจกต์)',
|
||||
})
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
project_id?: number;
|
||||
|
||||
@ApiPropertyOptional({ description: 'คำค้นหา (ชื่อ Tag หรือ คำอธิบาย)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -4,22 +4,37 @@ import {
|
||||
PrimaryGeneratedColumn,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
DeleteDateColumn,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
|
||||
@Entity('tags')
|
||||
@Unique('ux_tag_project', ['project_id', 'tag_name'])
|
||||
export class Tag {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: number; // เพิ่ม !
|
||||
|
||||
@Column({ length: 100, unique: true })
|
||||
@Column({ type: 'int', nullable: true })
|
||||
project_id!: number | null; // เพิ่ม !
|
||||
|
||||
@Column({ length: 100 })
|
||||
tag_name!: string; // เพิ่ม !
|
||||
|
||||
@Column({ length: 30, default: 'default' })
|
||||
color_code!: string; // เพิ่ม !
|
||||
|
||||
@Column({ type: 'text', nullable: true })
|
||||
description!: string; // เพิ่ม !
|
||||
description!: string | null; // เพิ่ม !
|
||||
|
||||
@CreateDateColumn()
|
||||
created_at!: Date; // เพิ่ม !
|
||||
|
||||
@UpdateDateColumn()
|
||||
updated_at!: Date; // เพิ่ม !
|
||||
|
||||
@Column({ type: 'int', nullable: true })
|
||||
created_by!: number | null; // เพิ่ม !
|
||||
|
||||
@DeleteDateColumn()
|
||||
deleted_at!: Date | null; // เพิ่ม !
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { SaveNumberFormatDto } from './dto/save-number-format.dto'; // [New]
|
||||
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
||||
import { RequirePermission } from '../../common/decorators/require-permission.decorator';
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator';
|
||||
|
||||
@ApiTags('Master Data')
|
||||
@Controller('master')
|
||||
@@ -216,8 +217,11 @@ export class MasterController {
|
||||
@Post('tags')
|
||||
@RequirePermission('master_data.tag.manage')
|
||||
@ApiOperation({ summary: 'Create a new tag' })
|
||||
createTag(@Body() dto: CreateTagDto) {
|
||||
return this.masterService.createTag(dto);
|
||||
createTag(
|
||||
@CurrentUser() user: { userId: number },
|
||||
@Body() dto: CreateTagDto
|
||||
) {
|
||||
return this.masterService.createTag(dto, user.userId);
|
||||
}
|
||||
|
||||
@Patch('tags/:id')
|
||||
|
||||
@@ -253,11 +253,21 @@ export class MasterService {
|
||||
// ... (Tag Logic เดิม คงไว้ตามปกติ) ...
|
||||
async findAllTags(query?: SearchTagDto) {
|
||||
const qb = this.tagRepo.createQueryBuilder('tag');
|
||||
if (query?.search) {
|
||||
qb.where('tag.tag_name LIKE :search OR tag.description LIKE :search', {
|
||||
search: `%${query.search}%`,
|
||||
|
||||
if (query?.project_id) {
|
||||
qb.andWhere('tag.project_id = :projectId', {
|
||||
projectId: query.project_id,
|
||||
});
|
||||
}
|
||||
|
||||
if (query?.search) {
|
||||
qb.andWhere(
|
||||
'(tag.tag_name LIKE :search OR tag.description LIKE :search)',
|
||||
{
|
||||
search: `%${query.search}%`,
|
||||
}
|
||||
);
|
||||
}
|
||||
qb.orderBy('tag.tag_name', 'ASC');
|
||||
if (query?.page && query?.limit) {
|
||||
const page = query.page;
|
||||
@@ -278,8 +288,11 @@ export class MasterService {
|
||||
return tag;
|
||||
}
|
||||
|
||||
async createTag(dto: CreateTagDto) {
|
||||
const tag = this.tagRepo.create(dto);
|
||||
async createTag(dto: CreateTagDto, userId: number) {
|
||||
const tag = this.tagRepo.create({
|
||||
...dto,
|
||||
created_by: userId,
|
||||
});
|
||||
return this.tagRepo.save(tag);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user