This commit is contained in:
mahyargdz
2025-09-14 15:15:03 +03:30
commit be82059172
534 changed files with 51310 additions and 0 deletions
+127
View File
@@ -0,0 +1,127 @@
import { Types } from "mongoose";
import { BaseRepository } from "../../../common/base/repository";
import { ILearning } from "../model/Abstractions/ILearning";
import { LearningModel } from "../model/learning.model";
export class LearningRepo extends BaseRepository<ILearning> {
constructor() {
super(LearningModel);
}
async getVideosWithWatchStatus(sellerId: string, catId: string) {
const result = await LearningModel.aggregate([
{
$match: {
category: catId,
deleted: false,
},
},
{
$lookup: {
from: "learningprogresses",
let: { seller: new Types.ObjectId(sellerId), videoId: "$_id" },
pipeline: [
{
$match: {
$expr: {
$and: [{ $eq: ["$sellerId", "$$seller"] }, { $eq: ["$videoId", "$$videoId"] }],
},
},
},
],
as: "watchStatus",
},
},
{
$addFields: {
isWatched: { $gt: [{ $size: { $ifNull: ["$watchStatus", []] } }, 0] },
},
},
{
$project: {
_id: 1,
title: 1,
description: 1,
videoUrl: 1,
cover: 1,
isWatched: 1,
},
},
]);
return result;
}
async getVideosGroupByCategories(sellerId: string) {
const result = await LearningModel.aggregate([
{
$match: {
deleted: false,
},
},
{
$lookup: {
from: "learningprogresses",
let: { seller: new Types.ObjectId(sellerId), videoId: "$_id" },
pipeline: [
{
$match: {
$expr: {
$and: [{ $eq: ["$sellerId", "$$seller"] }, { $eq: ["$videoId", "$$videoId"] }],
},
},
},
],
as: "watchStatus",
},
},
{
$addFields: {
isWatched: { $gt: [{ $size: { $ifNull: ["$watchStatus", []] } }, 0] },
},
},
{
$lookup: {
from: "learningcategories",
localField: "category",
foreignField: "_id",
as: "categoryDetails",
},
},
{
$unwind: "$categoryDetails",
},
{
$group: {
_id: "$category",
categoryTitle: { $first: "$categoryDetails.title" },
videos: {
$push: {
_id: "$_id",
title: "$title",
cover: "$cover",
description: "$description",
videoUrl: "$videoUrl",
isWatched: "$isWatched",
},
},
},
},
{
$project: {
_id: 0,
category: "$_id",
categoryTitle: 1,
videos: 1,
},
},
]);
return result;
}
}
export function CreateLearningRepo(): LearningRepo {
return new LearningRepo();
}
@@ -0,0 +1,13 @@
import { BaseRepository } from "../../../common/base/repository";
import { ILearningCategory } from "../model/Abstractions/ILearningCategory";
import { LearningCategoryModel } from "../model/learningCategory.model";
export class LearningCategoryRepo extends BaseRepository<ILearningCategory> {
constructor() {
super(LearningCategoryModel);
}
}
export function CreateLearningCategoryRepo(): LearningCategoryRepo {
return new LearningCategoryRepo();
}
@@ -0,0 +1,105 @@
import { BaseRepository } from "../../../common/base/repository";
import { ILearningProgress } from "../model/Abstractions/ILearningProgress";
import { LearningProgressModel } from "../model/learningProgress.model";
export class LearningProgressRepo extends BaseRepository<ILearningProgress> {
constructor() {
super(LearningProgressModel);
}
async getLearningProgressBySellers() {
const result = await LearningProgressModel.aggregate([
{
$lookup: {
from: "learnings",
localField: "videoId",
foreignField: "_id",
as: "videoDetails",
},
},
{
$lookup: {
from: "sellers",
localField: "sellerId",
foreignField: "_id",
as: "sellerDetails",
},
},
{
$lookup: {
from: "shops",
localField: "sellerDetails._id",
foreignField: "owner",
as: "shopDetails",
},
},
{
$unwind: "$shopDetails",
},
{
$addFields: {
"sellerDetails.shopName": "$shopDetails.shopName",
"sellerDetails.shopId": "$shopDetails._id",
},
},
{
$project: {
_id: 0,
sellerId: 1,
videoId: 1,
watchedAt: 1,
videoDetails: { $arrayElemAt: ["$videoDetails", 0] },
sellerDetails: { $arrayElemAt: ["$sellerDetails", 0] },
},
},
{
$group: {
_id: "$sellerId",
sellerDetails: { $first: "$sellerDetails" },
watchedVideos: {
$push: {
videoId: "$videoId",
videoDetails: "$videoDetails",
watchedAt: "$watchedAt",
},
},
},
},
{
$lookup: {
from: "learnings",
pipeline: [],
as: "allVideos",
},
},
{
$project: {
sellerDetails: {
_id: 1,
fullName: 1,
shopName: 1,
shopId: 1,
},
watchedVideos: 1,
unwatchedVideos: {
$filter: {
input: "$allVideos",
as: "video",
cond: {
$not: {
$in: ["$$video._id", "$watchedVideos.videoId"],
},
},
},
},
},
},
]);
console.log(result);
return result;
}
}
export function CreateLearningProgressRepo(): LearningProgressRepo {
return new LearningProgressRepo();
}