first commit
هذا الالتزام موجود في:
59
src/modules/posts/schemas/post.schema.ts
Normal file
59
src/modules/posts/schemas/post.schema.ts
Normal file
@@ -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 });
|
||||
المرجع في مشكلة جديدة
حظر مستخدم