هذا الالتزام موجود في:
2026-04-20 15:12:16 +03:00
التزام 28f7241bcd
172 ملفات معدلة مع 21907 إضافات و0 حذوفات

عرض الملف

@@ -0,0 +1,59 @@
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument, Types } from 'mongoose';
import { PostType } from '../../../common/enums/post-type.enum';
import { PostVisibility } from '../../../common/enums/post-visibility.enum';
import { User } from '../../users/schemas/user.schema';
export type PostDocument = HydratedDocument<Post>;
@Schema({ timestamps: true, versionKey: false })
export class Post {
@Prop({ type: Types.ObjectId, ref: User.name, required: true, index: true })
authorId!: Types.ObjectId;
@Prop({ default: '', trim: true, maxlength: 2200, required: true })
content!: string;
@Prop({ default: '' })
videoUrl!: string;
@Prop({ default: '' })
audioUrl!: string;
@Prop({ enum: PostType, default: PostType.TEXT, index: true })
postType!: PostType;
@Prop({ enum: PostVisibility, default: PostVisibility.PUBLIC, index: true })
visibility!: PostVisibility;
@Prop({ default: 0, min: 0 })
likesCount!: number;
@Prop({ default: 0, min: 0 })
commentsCount!: number;
@Prop({ default: 0, min: 0 })
savesCount!: number;
@Prop({ type: [String], default: [], index: true })
hashtags!: string[];
@Prop({ default: false, index: true })
isDeleted!: boolean;
@Prop({ type: Date, default: null })
deletedAt?: Date | null;
@Prop({ type: Types.ObjectId, ref: User.name, default: null })
deletedBy?: Types.ObjectId | null;
}
export const PostSchema = SchemaFactory.createForClass(Post);
PostSchema.index({ authorId: 1, createdAt: -1 });
PostSchema.index({ visibility: 1, createdAt: -1 });
PostSchema.index({ postType: 1, createdAt: -1 });
PostSchema.index({ hashtags: 1, createdAt: -1 });
PostSchema.index({ authorId: 1, isDeleted: 1, createdAt: -1 });
PostSchema.index({ visibility: 1, isDeleted: 1, createdAt: -1 });
PostSchema.index({ visibility: 1, isDeleted: 1, likesCount: -1, commentsCount: -1, savesCount: -1, createdAt: -1 });