Skip to content

Commit 60755b9

Browse files
authored
Merge pull request #3871 from Northeastern-Electric-Racing/#3870-checklists-auto-check-when-no-required-items
#3870 retrieve checked items in query, include top level for items with no checkable tasks
2 parents 384dbd9 + b9896da commit 60755b9

2 files changed

Lines changed: 56 additions & 35 deletions

File tree

src/backend/src/services/onboarding.services.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,37 @@ 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: {
55+
OR: [
56+
{ isOptional: true },
57+
{ usersChecked: { some: { userId: user.userId } } },
58+
{ itemType: ChecklistItemType.INFO }
59+
]
60+
}
61+
}
62+
}
63+
]
64+
}
65+
]
66+
},
67+
include: { subtasks: { where: { dateDeleted: null }, orderBy: { displayIndex: 'asc' } } },
4368
orderBy: { displayIndex: 'asc' }
4469
});
4570

46-
const checkedChecklists = allChecklists.filter((checklist) =>
47-
checklist.usersChecked.some((userChecked) => userChecked.userId === user.userId)
48-
);
49-
5071
return checkedChecklists;
5172
}
5273

src/frontend/src/pages/HomePage/components/ChecklistSection.tsx

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,36 @@ const ChecklistSection: React.FC<ChecklistSectionProps> = ({ usersChecklists, ch
4242
<Grid item xs={12} padding={2}>
4343
<Checklist parentChecklists={checklists} checkedChecklists={checkedChecklists} checklistName={checklistName} />
4444
</Grid>
45-
{checklistName === 'General' && newMemberImageUrl && (
46-
<Grid item xs={12} padding={2}>
47-
<Box
48-
sx={{
49-
backgroundColor: theme.palette.background.paper,
50-
borderRadius: '10px',
51-
padding: 3,
52-
width: '100%'
53-
}}
54-
>
55-
<Typography variant="h5" sx={{ mb: 2 }}>
56-
New Member Events
57-
</Typography>
58-
<Box
59-
component="img"
60-
sx={{
61-
display: 'block',
62-
width: '100%',
63-
maxHeight: '500px',
64-
objectFit: 'contain',
65-
borderRadius: '8px'
66-
}}
67-
alt="New Member Events"
68-
src={newMemberImageUrl}
69-
/>
70-
</Box>
71-
</Grid>
72-
)}
7345
</React.Fragment>
7446
))}
47+
{newMemberImageUrl && (
48+
<Grid item xs={12} padding={2}>
49+
<Box
50+
sx={{
51+
backgroundColor: theme.palette.background.paper,
52+
borderRadius: '10px',
53+
padding: 3,
54+
width: '100%'
55+
}}
56+
>
57+
<Typography variant="h5" sx={{ mb: 2 }}>
58+
New Member Events
59+
</Typography>
60+
<Box
61+
component="img"
62+
sx={{
63+
display: 'block',
64+
width: '100%',
65+
maxHeight: '500px',
66+
objectFit: 'contain',
67+
borderRadius: '8px'
68+
}}
69+
alt="New Member Events"
70+
src={newMemberImageUrl}
71+
/>
72+
</Box>
73+
</Grid>
74+
)}
7575
</Grid>
7676
{!usersChecklists.length && (
7777
<Box

0 commit comments

Comments
 (0)