| 1 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' |
| 2 | import { DraftGenerationMemoryContentType } from '@yikart/aitoearn-ai-shared' |
| 3 | import { DEFAULT_SCHEMA_OPTIONS } from '../mongodb.constants' |
| 4 | import { WithTimestampSchema } from './timestamp.schema' |
| 5 | |
| 6 | @Schema({ _id: false }) |
| 7 | export class DraftGenerationMemoryItem { |
| 8 | @Prop({ required: true }) |
| 9 | id: string |
| 10 | |
| 11 | @Prop({ required: true }) |
| 12 | text: string |
| 13 | |
| 14 | @Prop({ required: true, type: Date }) |
| 15 | createdAt: Date |
| 16 | |
| 17 | @Prop({ required: true, type: Date }) |
| 18 | updatedAt: Date |
| 19 | } |
| 20 | |
| 21 | export const DraftGenerationMemoryItemSchema = SchemaFactory.createForClass(DraftGenerationMemoryItem) |
| 22 | |
| 23 | @Schema({ ...DEFAULT_SCHEMA_OPTIONS, collection: 'draftGenerationMemories' }) |
| 24 | export class DraftGenerationMemory extends WithTimestampSchema { |
| 25 | id: string |
| 26 | |
| 27 | @Prop({ required: true, index: true }) |
| 28 | userId: string |
| 29 | |
| 30 | @Prop({ required: true, index: true, enum: DraftGenerationMemoryContentType }) |
| 31 | contentType: DraftGenerationMemoryContentType |
| 32 | |
| 33 | @Prop({ required: true, type: [DraftGenerationMemoryItemSchema], default: [] }) |
| 34 | items: DraftGenerationMemoryItem[] |
| 35 | |
| 36 | @Prop({ required: false, type: Date }) |
| 37 | lastGeneratedAt?: Date |
| 38 | |
| 39 | @Prop({ required: true, type: Number, default: 0 }) |
| 40 | sampleCount: number |
| 41 | } |
| 42 | |
| 43 | export const DraftGenerationMemorySchema = SchemaFactory.createForClass(DraftGenerationMemory) |
| 44 | DraftGenerationMemorySchema.index({ userId: 1, contentType: 1 }, { unique: true }) |
| 45 |