diff --git a/apps/server/src/models/post/post.service.ts b/apps/server/src/models/post/post.service.ts index 5e9a116..cbcf7bc 100755 --- a/apps/server/src/models/post/post.service.ts +++ b/apps/server/src/models/post/post.service.ts @@ -184,7 +184,34 @@ export class PostService extends BaseTreeService { where?: Prisma.PostWhereInput; orderBy?: OrderByArgs<(typeof db.post)['findMany']>; select?: Prisma.PostSelect; - }) { + }): Promise<{ + items: { + id: string; + type: string | null; + level: string | null; + state: string | null; + title: string | null; + subTitle: string | null; + content: string | null; + important: boolean | null; + domainId: string | null; + order: number | null; + duration: number | null; + rating: number | null; + createdAt: Date; + views: number; + hates: number; + likes: number; + publishedAt: Date | null; + updatedAt: Date; + deletedAt: Date | null; + authorId: string | null; + parentId: string | null; + hasChildren: boolean | null; + meta: Prisma.JsonValue | null; + }[]; + totalPages: number; + }> { // super.updateOrder; return super.findManyWithPagination(args); } diff --git a/apps/server/src/models/visit/visit.router.ts b/apps/server/src/models/visit/visit.router.ts index ad6d632..e600ff2 100755 --- a/apps/server/src/models/visit/visit.router.ts +++ b/apps/server/src/models/visit/visit.router.ts @@ -15,13 +15,13 @@ export class VisitRouter { private readonly visitService: VisitService, ) {} router = this.trpc.router({ - create: this.trpc.protectProcedure + create: this.trpc.procedure .input(VisitCreateArgsSchema) .mutation(async ({ ctx, input }) => { const { staff } = ctx; return await this.visitService.create(input, staff); }), - createMany: this.trpc.protectProcedure + createMany: this.trpc.procedure .input(z.array(VisitCreateManyInputSchema)) .mutation(async ({ ctx, input }) => { const { staff } = ctx; diff --git a/apps/server/src/queue/models/post/utils.ts b/apps/server/src/queue/models/post/utils.ts index 51bffca..57129a3 100755 --- a/apps/server/src/queue/models/post/utils.ts +++ b/apps/server/src/queue/models/post/utils.ts @@ -8,7 +8,7 @@ import { export async function updateTotalCourseViewCount(type: VisitType) { const posts = await db.post.findMany({ where: { - type: { in: [PostType.COURSE, PostType.LECTURE] }, + // type: { in: [PostType.COURSE, PostType.LECTURE,] }, deletedAt: null, }, select: { id: true, type: true }, @@ -66,27 +66,34 @@ export async function updatePostViewCount(id: string, type: VisitType) { where: { id }, select: { id: true, meta: true, type: true }, }); + console.log(post?.type); + console.log('updatePostViewCount'); const metaFieldMap = { [VisitType.READED]: 'views', [VisitType.LIKE]: 'likes', [VisitType.HATE]: 'hates', }; if (post?.type === PostType.LECTURE) { - const course = await db.postAncestry.findFirst({ + const courseAncestry = await db.postAncestry.findFirst({ where: { descendantId: post?.id, ancestor: { type: PostType.COURSE, }, }, - select: { id: true }, + select: { id: true, ancestorId: true }, }); - const lectures = await db.postAncestry.findMany({ + const course = { id: courseAncestry.ancestorId }; + const lecturesAncestry = await db.postAncestry.findMany({ where: { ancestorId: course.id, descendant: { type: PostType.LECTURE } }, select: { id: true, + descendantId: true, }, }); + const lectures = lecturesAncestry.map((ancestry) => ({ + id: ancestry.descendantId, + })); const courseViews = await db.visit.aggregate({ _sum: { views: true, @@ -98,9 +105,11 @@ export async function updatePostViewCount(id: string, type: VisitType) { type: type, }, }); + console.log(courseViews); await db.post.update({ where: { id: course.id }, data: { + [metaFieldMap[type]]: courseViews._sum.views || 0, meta: { ...((post?.meta as any) || {}), [metaFieldMap[type]]: courseViews._sum.views || 0, @@ -117,9 +126,11 @@ export async function updatePostViewCount(id: string, type: VisitType) { type: type, }, }); + console.log('totalViews', totalViews); await db.post.update({ where: { id }, data: { + [metaFieldMap[type]]: totalViews._sum.views || 0, meta: { ...((post?.meta as any) || {}), [metaFieldMap[type]]: totalViews._sum.views || 0, diff --git a/apps/web/src/app/main/home/components/CoursesSection.tsx b/apps/web/src/app/main/home/components/CoursesSection.tsx index 40814f4..cc68bd0 100755 --- a/apps/web/src/app/main/home/components/CoursesSection.tsx +++ b/apps/web/src/app/main/home/components/CoursesSection.tsx @@ -34,14 +34,16 @@ interface CoursesSectionProps { description: string; initialVisibleCoursesCount?: number; postType:string; - render?:(post)=>ReactNode + render?:(post)=>ReactNode; + to:string } const CoursesSection: React.FC = ({ title, description, initialVisibleCoursesCount = 8, postType, - render + render, + to }) => { const [selectedCategory, setSelectedCategory] = useState("全部"); const gateGory: GetTaxonomyProps = useGetTaxonomy({ @@ -102,7 +104,7 @@ const CoursesSection: React.FC = ({ }} showPagination={false} cols={4}> - + ); diff --git a/apps/web/src/app/main/home/components/LookForMore.tsx b/apps/web/src/app/main/home/components/LookForMore.tsx index 88e1b41..2bd74cc 100755 --- a/apps/web/src/app/main/home/components/LookForMore.tsx +++ b/apps/web/src/app/main/home/components/LookForMore.tsx @@ -11,7 +11,10 @@ export default function LookForMore({to}:{to:string}) {