This commit is contained in:
ditiqi 2025-02-26 22:03:07 +08:00
parent 0c06116742
commit 5872f4b728
2 changed files with 18 additions and 14 deletions

View File

@ -166,19 +166,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
); );
return transDto; return transDto;
} }
// async findMany(args: Prisma.PostFindManyArgs, staff?: UserProfile) {
// if (!args.where) args.where = {};
// args.where.OR = await this.preFilter(args.where.OR, staff);
// return this.wrapResult(super.findMany(args), async (result) => {
// await Promise.all(
// result.map(async (item) => {
// await setPostRelation({ data: item, staff });
// await this.setPerms(item, staff);
// }),
// );
// return { ...result };
// });
// }
async findManyWithCursor(args: Prisma.PostFindManyArgs, staff?: UserProfile) { async findManyWithCursor(args: Prisma.PostFindManyArgs, staff?: UserProfile) {
if (!args.where) args.where = {}; if (!args.where) args.where = {};
args.where.OR = await this.preFilter(args.where.OR, staff); args.where.OR = await this.preFilter(args.where.OR, staff);
@ -255,6 +243,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
// 批量执行更新 // 批量执行更新
return updates.length > 0 ? await db.$transaction(updates) : []; return updates.length > 0 ? await db.$transaction(updates) : [];
} }
protected async setPerms(data: Post, staff?: UserProfile) { protected async setPerms(data: Post, staff?: UserProfile) {
if (!staff) return; if (!staff) return;
const perms: ResPerm = { const perms: ResPerm = {

View File

@ -168,6 +168,21 @@ export async function setCourseInfo({ data }: { data: Post }) {
(lecture) => lecture.parentId === section.id, (lecture) => lecture.parentId === section.id,
) as any as Lecture[]; ) as any as Lecture[];
}); });
Object.assign(data, { sections, lectureCount });
const students = await db.staff.findMany({
where: {
learningPosts: {
some: {
id: data.id,
},
},
},
select: {
id: true,
},
});
const studentIds = (students || []).map((student) => student?.id);
Object.assign(data, { sections, lectureCount, studentIds });
} }
} }