返回 AiToEarn
content-generation-task.schema.ts
根目录 / project / aitoearn-backend / libs / mongodb / src / schemas / content-generation-task.schema.ts
1 import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2 import { SchemaTypes } from 'mongoose'
3 import { ContentGenerationTaskStatus } from '../enums'
4 import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants'
5 import { WithTimestampSchema } from './timestamp.schema'
6
7 export type TaskAnalysisPriority = 'none' | 'high' | 'medium' | 'low'
8 export type TaskAnalysisOptimizationPriority = 'high' | 'medium' | 'low'
9
10 export interface TaskAnalysisOptimization {
11 issue: string
12 priority: TaskAnalysisOptimizationPriority
13 }
14
15 export interface TaskAnalysis {
16 summary: string
17 priority: TaskAnalysisPriority
18 optimizations?: TaskAnalysisOptimization[]
19 analyzedAt: Date
20 model: string
21 error?: string
22 }
23
24 @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'contentGenerationTask' })
25 export class ContentGenerationTask extends WithTimestampSchema {
26 id: string
27
28 @Prop({
29 required: true,
30 })
31 userId: string
32
33 @Prop({
34 required: false,
35 index: true,
36 })
37 sessionId?: string
38
39 @Prop({
40 required: false,
41 })
42 title?: string
43
44 @Prop({
45 required: false,
46 default: [],
47 type: [SchemaTypes.Mixed],
48 })
49 messages: Array<Record<string, unknown>>
50
51 @Prop({
52 type: Date,
53 required: false,
54 })
55 deletedAt?: Date
56
57 @Prop({
58 required: true,
59 enum: ContentGenerationTaskStatus,
60 default: ContentGenerationTaskStatus.Running,
61 })
62 status: ContentGenerationTaskStatus
63
64 @Prop({
65 required: false,
66 min: 1,
67 max: 5,
68 })
69 rating?: number
70
71 @Prop({
72 required: false,
73 })
74 ratingComment?: string
75
76 @Prop({
77 required: false,
78 index: true,
79 })
80 publicShareToken?: string
81
82 @Prop({
83 required: false,
84 type: Date,
85 })
86 publicShareExpiresAt?: Date
87
88 @Prop({
89 required: false,
90 type: [String],
91 default: [],
92 })
93 subAgentIds?: string[]
94
95 @Prop({
96 required: false,
97 type: [String],
98 default: [],
99 })
100 todos?: string[]
101
102 @Prop({
103 type: Date,
104 required: false,
105 })
106 favoritedAt?: Date
107
108 @Prop({
109 type: {
110 summary: String,
111 priority: { type: String, enum: ['none', 'high', 'medium', 'low'] },
112 optimizations: [{
113 issue: String,
114 priority: { type: String, enum: ['high', 'medium', 'low'] },
115 }],
116 analyzedAt: Date,
117 model: String,
118 error: String,
119 },
120 required: false,
121 })
122 analysis?: TaskAnalysis
123 }
124
125 export const ContentGenerationTaskSchema = SchemaFactory.createForClass(ContentGenerationTask)
126
127 ContentGenerationTaskSchema.index({ userId: 1, deletedAt: 1, createdAt: -1 })
128 ContentGenerationTaskSchema.index({ userId: 1, favoritedAt: -1, deletedAt: 1 })
129 ContentGenerationTaskSchema.index({ status: 1, deletedAt: 1, updatedAt: 1 })
130
130 lines TYPESCRIPT