11import { prisma } from "~/db.server" ;
22import { generateFriendlyId } from "~/v3/friendlyIdentifiers" ;
3+ import { PrismaClientOrTransaction } from "@trigger.dev/database" ;
34
45export const MAX_TAGS_PER_RUN = 10 ;
56
6- export async function createTag ( { tag, projectId } : { tag : string ; projectId : string } ) {
7+ export async function createTag (
8+ { tag, projectId } : { tag : string ; projectId : string } ,
9+ prismaClient : PrismaClientOrTransaction = prisma
10+ ) {
711 if ( tag . trim ( ) . length === 0 ) return ;
8- return prisma . taskRunTag . upsert ( {
12+ return prismaClient . taskRunTag . upsert ( {
913 where : {
1014 projectId_name : {
1115 projectId : projectId ,
@@ -21,6 +25,48 @@ export async function createTag({ tag, projectId }: { tag: string; projectId: st
2125 } ) ;
2226}
2327
28+ export type TagRecord = {
29+ id : string ;
30+ name : string ;
31+ } ;
32+
33+ export async function createTags (
34+ {
35+ tags,
36+ projectId,
37+ } : {
38+ tags : string | string [ ] | undefined ;
39+ projectId : string ;
40+ } ,
41+ prismaClient : PrismaClientOrTransaction = prisma
42+ ) : Promise < TagRecord [ ] > {
43+ if ( ! tags ) {
44+ return [ ] ;
45+ }
46+
47+ const tagsArray = typeof tags === "string" ? [ tags ] : tags ;
48+
49+ if ( tagsArray . length === 0 ) {
50+ return [ ] ;
51+ }
52+
53+ const tagRecords : TagRecord [ ] = [ ] ;
54+ for ( const tag of tagsArray ) {
55+ const tagRecord = await createTag (
56+ {
57+ tag,
58+ projectId,
59+ } ,
60+ prismaClient
61+ ) ;
62+ if ( tagRecord ) {
63+ tagRecords . push ( { id : tagRecord . id , name : tagRecord . name } ) ;
64+ }
65+ }
66+
67+ return tagRecords ;
68+ }
69+
2470export async function getTagsForRunId ( {
2571 friendlyId,
2672 environmentId,
0 commit comments