first commit
هذا الالتزام موجود في:
31
src/modules/likes/likes.repository.ts
Normal file
31
src/modules/likes/likes.repository.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Model, Types } from 'mongoose';
|
||||
import { Like, LikeDocument } from './schemas/like.schema';
|
||||
|
||||
@Injectable()
|
||||
export class LikesRepository {
|
||||
constructor(@InjectModel(Like.name) private readonly likeModel: Model<LikeDocument>) {}
|
||||
|
||||
async findOne(userId: string, targetId: string, targetType: 'post' | 'comment'): Promise<LikeDocument | null> {
|
||||
return this.likeModel
|
||||
.findOne({
|
||||
userId: new Types.ObjectId(userId),
|
||||
targetId: new Types.ObjectId(targetId),
|
||||
targetType,
|
||||
})
|
||||
.exec();
|
||||
}
|
||||
|
||||
async create(userId: string, targetId: string, targetType: 'post' | 'comment'): Promise<LikeDocument> {
|
||||
return this.likeModel.create({
|
||||
userId: new Types.ObjectId(userId),
|
||||
targetId: new Types.ObjectId(targetId),
|
||||
targetType,
|
||||
});
|
||||
}
|
||||
|
||||
async deleteById(id: string): Promise<void> {
|
||||
await this.likeModel.findByIdAndDelete(id).exec();
|
||||
}
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم