| 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 ChannelAccountSnapshotProfile { |
| 8 | displayName?: string |
| 9 | username?: string |
| 10 | avatarUrl?: string |
| 11 | accountType?: string |
| 12 | } |
| 13 | |
| 14 | export interface ChannelAccountSnapshotMetrics { |
| 15 | fansCount?: number |
| 16 | followingCount?: number |
| 17 | workCount?: number |
| 18 | readCount?: number |
| 19 | viewCount?: number |
| 20 | impressionCount?: number |
| 21 | reachCount?: number |
| 22 | likeCount?: number |
| 23 | collectCount?: number |
| 24 | forwardCount?: number |
| 25 | commentCount?: number |
| 26 | clickCount?: number |
| 27 | engagementCount?: number |
| 28 | } |
| 29 | |
| 30 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'channelAccountDataSnapshot' }) |
| 31 | export class ChannelAccountDataSnapshot extends BaseTemp { |
| 32 | @Prop({ type: MongooseSchema.Types.String }) |
| 33 | _id: string |
| 34 | |
| 35 | id: string |
| 36 | |
| 37 | @Prop({ required: true, type: String, index: true }) |
| 38 | userId: string |
| 39 | |
| 40 | @Prop({ required: true, enum: AccountType, index: true }) |
| 41 | platform: AccountType |
| 42 | |
| 43 | @Prop({ required: true, type: String, index: true }) |
| 44 | accountId: string |
| 45 | |
| 46 | @Prop({ required: false, type: String, index: true }) |
| 47 | platformUid?: string |
| 48 | |
| 49 | @Prop({ required: true, type: Date, index: true }) |
| 50 | snapshotAt: Date |
| 51 | |
| 52 | @Prop({ required: true, type: Date, index: true }) |
| 53 | fetchedAt: Date |
| 54 | |
| 55 | @Prop({ required: false, type: Date }) |
| 56 | periodStartAt?: Date |
| 57 | |
| 58 | @Prop({ required: false, type: Date }) |
| 59 | periodEndAt?: Date |
| 60 | |
| 61 | @Prop({ required: false, type: Object }) |
| 62 | profile?: ChannelAccountSnapshotProfile |
| 63 | |
| 64 | @Prop({ required: false, type: Object }) |
| 65 | metrics?: ChannelAccountSnapshotMetrics |
| 66 | |
| 67 | @Prop({ required: false, type: Object }) |
| 68 | extra?: Record<string, unknown> |
| 69 | |
| 70 | @Prop({ required: false, type: MongooseSchema.Types.Mixed }) |
| 71 | rawResponse?: unknown |
| 72 | } |
| 73 | |
| 74 | export const ChannelAccountDataSnapshotSchema = SchemaFactory.createForClass(ChannelAccountDataSnapshot) |
| 75 | ChannelAccountDataSnapshotSchema.index({ userId: 1, accountId: 1, fetchedAt: -1 }) |
| 76 | ChannelAccountDataSnapshotSchema.index({ userId: 1, accountId: 1, snapshotAt: 1, fetchedAt: -1 }) |
| 77 |