@@ -37,16 +37,31 @@ export default class OnboardingServices {
3737 * @returns all the checklists that this user has checked
3838 */
3939 static async getCheckedChecklists ( user : User , organization : Organization ) {
40- const allChecklists = await prisma . checklist . findMany ( {
41- where : { organizationId : organization . organizationId , dateDeleted : null } ,
42- include : { subtasks : { where : { dateDeleted : null } , orderBy : { displayIndex : 'asc' } } , usersChecked : true } ,
40+ const checkedChecklists = await prisma . checklist . findMany ( {
41+ where : {
42+ organizationId : organization . organizationId ,
43+ dateDeleted : null ,
44+ // A checklist is checked if the user has checked it, it is an info block, or all its subtasks are checked
45+ OR : [
46+ { usersChecked : { some : { userId : user . userId } } } ,
47+ { itemType : ChecklistItemType . INFO } ,
48+ {
49+ // Checks if the checklist has subtasks and if all subtasks are checked by the user
50+ AND : [
51+ { subtasks : { some : { } } } ,
52+ {
53+ subtasks : {
54+ every : { OR : [ { usersChecked : { some : { userId : user . userId } } } , { itemType : ChecklistItemType . INFO } ] }
55+ }
56+ }
57+ ]
58+ }
59+ ]
60+ } ,
61+ include : { subtasks : { where : { dateDeleted : null } , orderBy : { displayIndex : 'asc' } } } ,
4362 orderBy : { displayIndex : 'asc' }
4463 } ) ;
4564
46- const checkedChecklists = allChecklists . filter ( ( checklist ) =>
47- checklist . usersChecked . some ( ( userChecked ) => userChecked . userId === user . userId )
48- ) ;
49-
5065 return checkedChecklists ;
5166 }
5267
0 commit comments