返回 AiToEarn
channel-work-data-snapshot.schema.ts
根目录 / project / aitoearn-backend / libs / channel-db / src / schemas / channel-work-data-snapshot.schema.ts
1 import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'
2 import { AccountType } from '@yikart/common'
3 import { Schema as MongooseSchema } from 'mongoose'
4 import { DEFAULT_SCHEMA_OPTIONS } from '../channel-db.constants'
5 import { BaseTemp } from './time.tamp'
6
7 export interface ChannelWorkSnapshotData {
8 id: string
9 url?: string
10 title?: string
11 description?: string
12 mediaType?: string
13 coverUrl?: string
14 publishedAt?: Date
15 status?: string
16 author?: string
17 }
18
19 export interface ChannelWorkSnapshotMetrics {
20 viewCount?: number
21 playCount?: number
22 impressionCount?: number
23 reachCount?: number
24 likeCount?: number
25 collectCount?: number
26 commentCount?: number
27 shareCount?: number
28 saveCount?: number
29 clickCount?: number
30 engagementCount?: number
31 watchTimeSeconds?: number
32 }
33
34 @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'channelWorkDataSnapshot' })
35 export class ChannelWorkDataSnapshot extends BaseTemp {
36 @Prop({ type: MongooseSchema.Types.String })
37 _id: string
38
39 id: string
40
41 @Prop({ required: true, type: String, index: true })
42 userId: string
43
44 @Prop({ required: true, enum: AccountType, index: true })
45 platform: AccountType
46
47 @Prop({ required: false, type: String, index: true })
48 accountId?: string
49
50 @Prop({ required: true, type: String, index: true })
51 platformWorkId: string
52
53 @Prop({ required: true, type: Date, index: true })
54 snapshotAt: Date
55
56 @Prop({ required: true, type: Date, index: true })
57 fetchedAt: Date
58
59 @Prop({ required: false, type: Date })
60 periodStartAt?: Date
61
62 @Prop({ required: false, type: Date })
63 periodEndAt?: Date
64
65 @Prop({ required: true, type: Object })
66 work: ChannelWorkSnapshotData
67
68 @Prop({ required: false, type: Object })
69 metrics?: ChannelWorkSnapshotMetrics
70
71 @Prop({ required: false, type: Object })
72 extra?: Record<string, unknown>
73
74 @Prop({ required: false, type: MongooseSchema.Types.Mixed })
75 rawResponse?: unknown
76 }
77
78 export const ChannelWorkDataSnapshotSchema = SchemaFactory.createForClass(ChannelWorkDataSnapshot)
79 ChannelWorkDataSnapshotSchema.index({ userId: 1, platformWorkId: 1, fetchedAt: -1 })
80 ChannelWorkDataSnapshotSchema.index({ userId: 1, platformWorkId: 1, snapshotAt: 1, fetchedAt: -1 })
81
81 lines TYPESCRIPT