1+ import * as utils from "../../common/utils.js" ;
2+ import { z } from "zod" ;
3+
4+ // 定义标签和标签分类的Zod模式
5+ export const TagGroupSchema = z . object ( {
6+ id : z . number ( ) . int ( ) . nullable ( ) . optional ( ) . describe ( "标签分类 id" ) ,
7+ name : z . string ( ) . nullable ( ) . optional ( ) . describe ( "标签分类名称" ) ,
8+ creatorAccountId : z . string ( ) . nullable ( ) . optional ( ) . describe ( "创建人" ) ,
9+ modifierAccountId : z . string ( ) . nullable ( ) . optional ( ) . describe ( "更新人" ) ,
10+ } ) ;
11+
12+ export const TagSchema = z . object ( {
13+ id : z . number ( ) . int ( ) . nullable ( ) . optional ( ) . describe ( "标签 id" ) ,
14+ name : z . string ( ) . nullable ( ) . optional ( ) . describe ( "标签名称" ) ,
15+ color : z . string ( ) . nullable ( ) . optional ( ) . describe ( "标签颜色" ) ,
16+ creatorAccountId : z . string ( ) . nullable ( ) . optional ( ) . describe ( "创建人" ) ,
17+ modifierAccountId : z . string ( ) . nullable ( ) . optional ( ) . describe ( "更新人" ) ,
18+ } ) ;
19+
20+ export const TagGroupWithTagsSchema = TagGroupSchema . extend ( {
21+ flowTagList : z . array ( TagSchema ) . nullable ( ) . optional ( ) . describe ( "标签列表" ) ,
22+ } ) ;
23+
24+ // 定义API请求参数的Zod模式
25+ export const BaseTagSchema = z . object ( {
26+ organizationId : z . string ( ) . describe ( "企业Id" ) ,
27+ } ) ;
28+
29+ export const CreateTagSchema = BaseTagSchema . extend ( {
30+ name : z . string ( ) . describe ( "标签名称" ) ,
31+ color : z . string ( ) . describe ( "#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色" ) ,
32+ flowTagGroupId : z . number ( ) . int ( ) . describe ( "标签分类 id" ) ,
33+ } ) ;
34+
35+ export const CreateTagGroupSchema = BaseTagSchema . extend ( {
36+ name : z . string ( ) . describe ( "标签分类名称" ) ,
37+ } ) ;
38+
39+ export const DeleteTagGroupSchema = BaseTagSchema . extend ( {
40+ id : z . number ( ) . int ( ) . describe ( "标签分类 id" ) ,
41+ } ) ;
42+
43+ export const UpdateTagGroupSchema = DeleteTagGroupSchema . extend ( {
44+ name : z . string ( ) . describe ( "标签分类名称" ) ,
45+ } ) ;
46+
47+ export const DeleteTagSchema = BaseTagSchema . extend ( {
48+ id : z . number ( ) . int ( ) . describe ( "标签 id" ) ,
49+ } ) ;
50+
51+ export const UpdateTagSchema = DeleteTagSchema . extend ( {
52+ name : z . string ( ) . describe ( "标签名称" ) ,
53+ color : z . string ( ) . describe ( "#1F9AEF 蓝色; #E63A3A 红色; #FA8C15 黄色; #15AD31 绿色; #7978E5 紫色; #8C8C8C 灰色" ) ,
54+ flowTagGroupId : z . number ( ) . int ( ) . describe ( "标签分类 id" ) ,
55+ } ) ;
56+
57+ export const GetTagGroupSchema = DeleteTagGroupSchema ;
58+
59+ // 定义类型
60+ export type TagGroup = z . infer < typeof TagGroupSchema > ;
61+ export type Tag = z . infer < typeof TagSchema > ;
62+ export type TagGroupWithTags = z . infer < typeof TagGroupWithTagsSchema > ;
63+ export type CreateTagParams = z . infer < typeof CreateTagSchema > ;
64+ export type CreateTagGroupParams = z . infer < typeof CreateTagGroupSchema > ;
65+ export type DeleteTagGroupParams = z . infer < typeof DeleteTagGroupSchema > ;
66+ export type UpdateTagGroupParams = z . infer < typeof UpdateTagGroupSchema > ;
67+ export type DeleteTagParams = z . infer < typeof DeleteTagSchema > ;
68+ export type UpdateTagParams = z . infer < typeof UpdateTagSchema > ;
69+ export type GetTagGroupParams = z . infer < typeof GetTagGroupSchema > ;
70+
71+ /**
72+ * 创建标签
73+ * @param organizationId 企业Id
74+ * @param name 标签名称
75+ * @param color 标签颜色
76+ * @param flowTagGroupId 标签分类 id
77+ * @returns 标签 id
78+ */
79+ export async function createTagFunc (
80+ organizationId : string ,
81+ name : string ,
82+ color : string ,
83+ flowTagGroupId : number
84+ ) : Promise < number > {
85+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tags` ;
86+
87+ const queryParams = { name, color, flowTagGroupId } ;
88+ const fullUrl = utils . buildUrl ( url , queryParams ) ;
89+
90+ const response = await utils . yunxiaoRequest ( fullUrl , {
91+ method : "POST" ,
92+ } ) ;
93+
94+ return Number ( response ) ;
95+ }
96+
97+ /**
98+ * 创建标签分类
99+ * @param organizationId 企业Id
100+ * @param name 标签分类名称
101+ * @returns 标签分类 id
102+ */
103+ export async function createTagGroupFunc (
104+ organizationId : string ,
105+ name : string
106+ ) : Promise < number > {
107+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tagGroups` ;
108+
109+ const queryParams = { name } ;
110+ const fullUrl = utils . buildUrl ( url , queryParams ) ;
111+
112+ const response = await utils . yunxiaoRequest ( fullUrl , {
113+ method : "POST" ,
114+ } ) ;
115+
116+ return Number ( response ) ;
117+ }
118+
119+ /**
120+ * 获取流水线分类列表
121+ * @param organizationId 企业Id
122+ * @returns 流水线分类列表
123+ */
124+ export async function listTagGroupsFunc (
125+ organizationId : string
126+ ) : Promise < TagGroup [ ] > {
127+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tagGroups` ;
128+
129+ const response = await utils . yunxiaoRequest ( url , {
130+ method : "GET" ,
131+ } ) ;
132+
133+ if ( Array . isArray ( response ) ) {
134+ return response . map ( item => TagGroupSchema . parse ( item ) ) ;
135+ }
136+
137+ return [ ] ;
138+ }
139+
140+ /**
141+ * 删除标签分类
142+ * @param organizationId 企业Id
143+ * @param id 标签分类 id
144+ * @returns 是否成功
145+ */
146+ export async function deleteTagGroupFunc (
147+ organizationId : string ,
148+ id : number
149+ ) : Promise < boolean > {
150+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tagGroups/${ id } ` ;
151+
152+ const response = await utils . yunxiaoRequest ( url , {
153+ method : "DELETE" ,
154+ } ) ;
155+
156+ return Boolean ( response ) ;
157+ }
158+
159+ /**
160+ * 更新标签分类
161+ * @param organizationId 企业Id
162+ * @param id 标签分类 id
163+ * @param name 标签分类名称
164+ * @returns 是否成功
165+ */
166+ export async function updateTagGroupFunc (
167+ organizationId : string ,
168+ id : number ,
169+ name : string
170+ ) : Promise < boolean > {
171+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tagGroups/${ id } ` ;
172+
173+ const queryParams = { name } ;
174+ const fullUrl = utils . buildUrl ( url , queryParams ) ;
175+
176+ const response = await utils . yunxiaoRequest ( fullUrl , {
177+ method : "PUT" ,
178+ } ) ;
179+
180+ return Boolean ( response ) ;
181+ }
182+
183+ /**
184+ * 获取标签分类
185+ * @param organizationId 企业Id
186+ * @param id 标签分类 id
187+ * @returns 标签分类
188+ */
189+ export async function getTagGroupFunc (
190+ organizationId : string ,
191+ id : number
192+ ) : Promise < TagGroupWithTags > {
193+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tagGroups/${ id } ` ;
194+
195+ const response = await utils . yunxiaoRequest ( url , {
196+ method : "GET" ,
197+ } ) ;
198+
199+ return TagGroupWithTagsSchema . parse ( response ) ;
200+ }
201+
202+ /**
203+ * 删除标签
204+ * @param organizationId 企业Id
205+ * @param id 标签 id
206+ * @returns 是否成功
207+ */
208+ export async function deleteTagFunc (
209+ organizationId : string ,
210+ id : number
211+ ) : Promise < boolean > {
212+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tags/${ id } ` ;
213+
214+ const response = await utils . yunxiaoRequest ( url , {
215+ method : "DELETE" ,
216+ } ) ;
217+
218+ return Boolean ( response ) ;
219+ }
220+
221+ /**
222+ * 更新标签
223+ * @param organizationId 企业Id
224+ * @param id 标签 id
225+ * @param name 标签名称
226+ * @param color 标签颜色
227+ * @param flowTagGroupId 标签分类 id
228+ * @returns 是否成功
229+ */
230+ export async function updateTagFunc (
231+ organizationId : string ,
232+ id : number ,
233+ name : string ,
234+ color : string ,
235+ flowTagGroupId : number
236+ ) : Promise < boolean > {
237+ const url = `/oapi/v1/flow/organizations/${ organizationId } /tags/${ id } ` ;
238+
239+ const queryParams = { name, color, flowTagGroupId } ;
240+ const fullUrl = utils . buildUrl ( url , queryParams ) ;
241+
242+ const response = await utils . yunxiaoRequest ( fullUrl , {
243+ method : "PUT" ,
244+ } ) ;
245+
246+ return Boolean ( response ) ;
247+ }
0 commit comments