Skip to content

Commit 2d7f59c

Browse files
committed
[Add] Checklist for cards added into prisma / graphql schema
1 parent a15659a commit 2d7f59c

File tree

11 files changed

+198
-2
lines changed

11 files changed

+198
-2
lines changed

backend/prisma/schema.prisma

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,22 @@ model Card {
114114
card_labels CardLabel[]
115115
card_members CardMember[]
116116
attachments Attachment[]
117+
checklists Checklist[]
117118
118119
list List @relation(fields: [list_id], references: [list_id], onDelete: Cascade)
119120
120121
@@index([list_id])
121122
}
122123

124+
model Checklist {
125+
checklist_id String @id @default(uuid())
126+
content String
127+
is_completed Boolean @default(false)
128+
card_id String
129+
130+
card Card @relation(fields: [card_id], references: [card_id], onDelete: Cascade)
131+
}
132+
123133
model Comment {
124134
comment_id String @id @default(uuid())
125135
content String

backend/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { BoardModule } from './board/board.module';
2727
import { ListModule } from './list/list.module';
2828
import { CardModule } from './card/card.module';
2929
import { LabelModule } from './label/label.module';
30+
import { ChecklistModule } from './checklist/checklist.module';
3031

3132
@Module({
3233
imports: [
@@ -51,6 +52,7 @@ import { LabelModule } from './label/label.module';
5152
ListModule,
5253
CardModule,
5354
LabelModule,
55+
ChecklistModule,
5456
],
5557
controllers: [AppController],
5658
providers: [AppService],

backend/src/card/card.resolver.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,27 @@ export class CardResolver {
9393
});
9494
return members.map((m) => m.user);
9595
}
96+
97+
// @ResolveField('comments')
98+
// async getComments(@Parent() card: Card) {
99+
// return this.prisma.comment.findMany({
100+
// where: { card_id: card.card_id },
101+
// orderBy: { created_at: 'asc' },
102+
// });
103+
// }
104+
105+
// @ResolveField('attachments')
106+
// async getAttachments(@Parent() card: Card) {
107+
// return this.prisma.attachment.findMany({
108+
// where: { card_id: card.card_id },
109+
// orderBy: { created_at: 'asc' },
110+
// });
111+
// }
112+
113+
@ResolveField('checklists')
114+
async getChecklists(@Parent() card: Card) {
115+
return this.prisma.checklist.findMany({
116+
where: { card_id: card.card_id }
117+
});
118+
}
96119
}

backend/src/card/card.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,19 @@ export class CardService {
3737
}
3838

3939
async delete(cardId: string) {
40-
await this.prisma.card.delete({ where: { card_id: cardId } });
41-
return { success: true, message: 'Card deleted' };
40+
try {
41+
await this.prisma.card.delete({ where: { card_id: cardId } });
42+
return {
43+
__typename: 'Success',
44+
successMessage: 'Card deleted successfully',
45+
};
46+
} catch {
47+
return {
48+
__typename: 'Error',
49+
errorMessage: 'Failed to delete card',
50+
code: 'CARD_DELETE_FAILED',
51+
};
52+
}
4253
}
4354

4455
async move(cardId: string, listId: string, position: number) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Module } from '@nestjs/common';
2+
import { ChecklistService } from './checklist.service';
3+
import { ChecklistResolver } from './checklist.resolver';
4+
5+
@Module({
6+
providers: [ChecklistService, ChecklistResolver]
7+
})
8+
export class ChecklistModule {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { ChecklistResolver } from './checklist.resolver';
3+
4+
describe('ChecklistResolver', () => {
5+
let resolver: ChecklistResolver;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
providers: [ChecklistResolver],
10+
}).compile();
11+
12+
resolver = module.get<ChecklistResolver>(ChecklistResolver);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(resolver).toBeDefined();
17+
});
18+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
** EPITECH PROJECT, 2025
3+
** TaskFlow
4+
** File description:
5+
** checklist.resolver
6+
*/
7+
8+
import {
9+
Resolver,
10+
Mutation,
11+
Args,
12+
ResolveField,
13+
Parent,
14+
} from '@nestjs/graphql';
15+
import { ChecklistService } from './checklist.service';
16+
import { PrismaService } from '../prisma/prisma.service';
17+
import { CreateChecklistInput } from '../graphql/graphql';
18+
import { UseGuards } from '@nestjs/common';
19+
import { AuthGuard } from '../common/guards/auth.guard';
20+
21+
@Resolver()
22+
export class ChecklistResolver {
23+
constructor(
24+
private checklistService: ChecklistService,
25+
private prisma: PrismaService,
26+
) {}
27+
28+
@Mutation('createChecklist')
29+
@UseGuards(AuthGuard)
30+
async createChecklist(
31+
@Args('input') input: CreateChecklistInput,
32+
) {
33+
return this.checklistService.create(input);
34+
}
35+
36+
@Mutation('deleteChecklist')
37+
@UseGuards(AuthGuard)
38+
async deleteChecklist(@Args('checklist_id') checklistId: string) {
39+
return this.checklistService.delete(checklistId);
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { ChecklistService } from './checklist.service';
3+
4+
describe('ChecklistService', () => {
5+
let service: ChecklistService;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
providers: [ChecklistService],
10+
}).compile();
11+
12+
service = module.get<ChecklistService>(ChecklistService);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(service).toBeDefined();
17+
});
18+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
** EPITECH PROJECT, 2025
3+
** TaskFlow
4+
** File description:
5+
** checklist.service
6+
*/
7+
8+
import { Injectable } from '@nestjs/common';
9+
import { PrismaService } from '../prisma/prisma.service';
10+
import { CreateChecklistInput } from '../graphql/graphql';
11+
12+
@Injectable()
13+
export class ChecklistService {
14+
constructor(private prisma: PrismaService) {}
15+
16+
async create(input: CreateChecklistInput) {
17+
return this.prisma.checklist.create({
18+
data: {
19+
card_id: input.card_id,
20+
content: input.content,
21+
},
22+
});
23+
}
24+
25+
async delete(checklistId: string) {
26+
await this.prisma.checklist.delete({
27+
where: { checklist_id: checklistId },
28+
});
29+
return { success: true, message: 'Checklist deleted' };
30+
}
31+
}

backend/src/graphql/graphql.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ export class UpdateCardInput {
5858
due_date?: Nullable<DateTime>;
5959
}
6060

61+
export class CreateChecklistInput {
62+
content: string;
63+
card_id: string;
64+
}
65+
6166
export class LoginInput {
6267
email: string;
6368
password: string;
@@ -138,6 +143,14 @@ export class Card {
138143
comments: Comment[];
139144
attachments: Attachment[];
140145
assignees: User[];
146+
checklists: Checklist[];
147+
}
148+
149+
export class Checklist {
150+
checklist_id: string;
151+
content: string;
152+
is_completed: boolean;
153+
card_id: string;
141154
}
142155

143156
export class Comment {
@@ -206,6 +219,10 @@ export abstract class IMutation {
206219

207220
abstract moveCard(card_id: string, list_id: string, new_position: number): Card | Promise<Card>;
208221

222+
abstract createChecklist(input: CreateChecklistInput): Checklist | Promise<Checklist>;
223+
224+
abstract deleteChecklist(checklist_id: string): Status | Promise<Status>;
225+
209226
abstract addLabelToCard(card_id: string, label_id: string): Card | Promise<Card>;
210227

211228
abstract removeLabelFromCard(card_id: string, label_id: string): Card | Promise<Card>;

0 commit comments

Comments
 (0)