Skip to content

Commit d159f87

Browse files
authored
Merge pull request #8692 from ever-co/enhancement/tag-type
[Feat] Tag Type
2 parents 5f3be79 + 2883b91 commit d159f87

File tree

15 files changed

+532
-5
lines changed

15 files changed

+532
-5
lines changed

packages/contracts/src/lib/tag.model.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IRelationalOrganizationTeam } from './organization-team.model';
2-
import { IBasePerTenantAndOrganizationEntityModel } from './base-entity.model';
2+
import { IBasePerTenantAndOrganizationEntityModel, ID } from './base-entity.model';
33

44
export interface ITaggable {
55
tags?: ITag[];
@@ -12,6 +12,8 @@ export interface ITag extends IBasePerTenantAndOrganizationEntityModel, IRelatio
1212
icon?: string;
1313
description?: string;
1414
isSystem?: boolean;
15+
tagTypeId?: ID;
16+
tagType?: ITagType;
1517
}
1618

1719
export interface ITagFindInput extends IBasePerTenantAndOrganizationEntityModel, Pick<ITag, 'organizationTeamId'> {
@@ -20,12 +22,18 @@ export interface ITagFindInput extends IBasePerTenantAndOrganizationEntityModel,
2022
textColor?: string;
2123
description?: string;
2224
isSystem?: boolean;
25+
tagTypeId?: ID;
2326
}
2427

2528
export interface ITagCreateInput extends ITag {}
2629

30+
export interface ITagType {
31+
type: string;
32+
tags?: ITag[];
33+
}
34+
2735
export interface ITagUpdateInput extends Partial<ITagCreateInput> {
28-
id?: string;
36+
id?: ID;
2937
}
3038

3139
/**

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ export {
100100
ExpenseCategoryFirstOrCreateCommand
101101
} from './lib/expense-categories';
102102
export { TagModule, TagService, Taggable, AutomationLabelSyncCommand, RelationalTagDTO } from './lib/tags';
103+
export { TagTypeModule, TagTypeService } from './lib/tag-type';

packages/core/src/lib/core/entities/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ import {
130130
SocialAccount,
131131
Subscription,
132132
Tag,
133+
TagType,
133134
Task,
134135
TaskEstimation,
135136
TaskLinkedIssue,
@@ -286,6 +287,7 @@ export const coreEntities = [
286287
SocialAccount,
287288
Subscription,
288289
Tag,
290+
TagType,
289291
Task,
290292
TaskEstimation,
291293
TaskLinkedIssue,

packages/core/src/lib/core/entities/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export * from '../../role/role.entity';
131131
export * from '../../skills/skill.entity';
132132
export * from '../../subscription/subscription.entity';
133133
export * from '../../tags/tag.entity';
134+
export * from '../../tag-type/tag-type.entity';
134135
export * from '../../tasks/daily-plan/daily-plan.entity';
135136
export * from '../../tasks/estimation/task-estimation.entity';
136137
export * from '../../tasks/issue-type/issue-type.entity';

packages/core/src/lib/database/migrations/1736155704913-CreateTagTypeTable.ts

Lines changed: 235 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { ITagType } from '@gauzy/contracts';
2+
3+
/**
4+
* Represents the default tag types used throughout the application.
5+
* Each tag type corresponds to a specific category or grouping.
6+
*
7+
* @constant DEFAULT_TAG_TYPES
8+
* @type {ITagType[]}
9+
*
10+
* @description
11+
* This constant defines an array of objects that represent default tag types.
12+
* Each object contains a `type` property, which is a string describing the tag type.
13+
* These tags can be used to classify various entities such as equipment, income,
14+
* invoices, and more.
15+
*
16+
* Example Usage:
17+
* ```typescript
18+
* console.log(DEFAULT_TAG_TYPES);
19+
* ```
20+
*
21+
*/
22+
export const DEFAULT_TAG_TYPES: ITagType[] = [
23+
{ type: 'Equipment' },
24+
{ type: 'Income' },
25+
{ type: 'Invoice' },
26+
{ type: 'Payment' },
27+
{ type: 'Task' },
28+
{ type: 'Proposals' },
29+
{ type: 'Organization Contact' },
30+
{ type: 'Employee Level' },
31+
{ type: 'Organization Department' },
32+
{ type: 'Warehouse' },
33+
{ type: 'Employee' },
34+
{ type: 'User' }
35+
];
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './tag-type.module';
2+
export * from './tag-type.service';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { MikroOrmBaseEntityRepository } from '../../core/repository/mikro-orm-base-entity.repository';
2+
import { TagType } from '../tag-type.entity';
3+
4+
export class MikroOrmTagTypeRepository extends MikroOrmBaseEntityRepository<TagType> {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { InjectRepository } from '@nestjs/typeorm';
3+
import { Repository } from 'typeorm';
4+
import { TagType } from '../tag-type.entity';
5+
6+
@Injectable()
7+
export class TypeOrmTagTypeRepository extends Repository<TagType> {
8+
constructor(@InjectRepository(TagType) readonly repository: Repository<TagType>) {
9+
super(repository.target, repository.manager, repository.queryRunner);
10+
}
11+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';
2+
import { Controller, HttpStatus, Get, Query, UseGuards, ValidationPipe } from '@nestjs/common';
3+
import { FindOptionsWhere } from 'typeorm';
4+
import { IPagination } from '@gauzy/contracts';
5+
import { CrudController, PaginationParams } from '../core/crud';
6+
import { PermissionGuard, TenantPermissionGuard } from '../shared/guards';
7+
import { TagType } from './tag-type.entity';
8+
import { TagTypeService } from './tag-type.service';
9+
10+
@ApiTags('TagTypes')
11+
@UseGuards(TenantPermissionGuard, PermissionGuard)
12+
@Controller('/tag-types')
13+
export class TagTypeController extends CrudController<TagType> {
14+
constructor(private readonly tagTypesService: TagTypeService) {
15+
super(tagTypesService);
16+
}
17+
18+
/**
19+
* GET tag types count
20+
*
21+
* @param data
22+
* @returns
23+
*/
24+
@ApiOperation({ summary: 'Find Tag Types Count ' })
25+
@ApiResponse({
26+
status: HttpStatus.OK,
27+
description: 'Count Tag Types',
28+
type: TagType
29+
})
30+
@ApiResponse({
31+
status: HttpStatus.NOT_FOUND,
32+
description: 'Record not found'
33+
})
34+
@Get('count')
35+
async getCount(@Query() options: FindOptionsWhere<TagType>): Promise<number> {
36+
return await this.tagTypesService.countBy(options);
37+
}
38+
39+
/**
40+
* GET all tag types
41+
*
42+
* @param options
43+
* @returns
44+
*/
45+
@ApiOperation({
46+
summary: 'Find all tag types.'
47+
})
48+
@ApiResponse({
49+
status: HttpStatus.OK,
50+
description: 'Found tag types.',
51+
type: TagType
52+
})
53+
@ApiResponse({
54+
status: HttpStatus.NOT_FOUND,
55+
description: 'Record not found'
56+
})
57+
@Get()
58+
async findAll(@Query(new ValidationPipe()) options: PaginationParams<TagType>): Promise<IPagination<TagType>> {
59+
return await this.tagTypesService.findAll(options);
60+
}
61+
}

0 commit comments

Comments
 (0)