Skip to content

Commit aa9ad63

Browse files
committed
resolve the conflicts
2 parents 44214a6 + b8a101a commit aa9ad63

18 files changed

Lines changed: 1101 additions & 110 deletions

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ jobs:
3030
3131
- name: Install dependencies
3232
run: bun install
33+
34+
- name: Generate Prisma client
35+
run: bun run generate
3336

3437
- name: Run tests
3538
run: bun jest
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { Request, Response } from "express";
2+
import { ApiError } from "../utils/apiError";
3+
import * as progressServices from "../services/progress.service"
4+
5+
export const getCompletedQuestion = async(req:Request,res:Response)=>{
6+
const memberId = req.params.memberId;
7+
if(!memberId){
8+
throw new ApiError("required field is missing",400);
9+
}
10+
11+
const completedQuestion = await progressServices.getCompletedQuestion(memberId);
12+
res.status(200).json({
13+
status:"SUCCESS",
14+
completedQuestion
15+
})
16+
17+
}
18+
19+
export const toggleQuestions = async(req:Request,res:Response) =>{
20+
const memberId = req.params.memberId;
21+
const questionId = parseInt(req.params.questionId);
22+
if(!memberId || !questionId){
23+
throw new ApiError("required field is missing",400);
24+
}
25+
26+
await progressServices.markQuestion(questionId,memberId);
27+
res.status(200).json({
28+
status:"SUCCESS",
29+
})
30+
31+
}

src/controllers/project.controller.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,29 @@ import { supabase } from "../app";
77

88
export const getProjects = async ( req : Request , res : Response ) => {
99

10-
try {
10+
1111
const projects = await projectService.getProjects();
1212
res.status(200).json(projects);
13-
} catch (error) {
14-
res.status(500).json({ error: "Failed to fetch projects" });
15-
}
13+
1614
};
1715

1816

1917
export const getProjectById = async ( req : Request , res : Response ) => {
2018

21-
try{
19+
2220
const projectId = parseInt( req.params.projectId );
2321

2422
if( isNaN(projectId) ) throw new ApiError( "Invalid project ID" , 400);
2523

2624
const project = await projectService.getProjectById( projectId );
2725
res.status(200).json(project);
2826

29-
}catch(error){
30-
throw new ApiError("No project with this ID" , 500);
31-
}
27+
3228
};
3329

3430
export const createProject = async ( req : Request , res : Response ) => {
3531

36-
try {
32+
3733
const file = req.file;
3834
if(!file) throw new ApiError('Image file not found' , 400);
3935

@@ -54,14 +50,11 @@ export const createProject = async ( req : Request , res : Response ) => {
5450
const project = await projectService.createProject( projectContent );
5551
res.status(200).json(project);
5652

57-
} catch (error) {
58-
throw new ApiError( error as string , 500);
59-
}
6053
};
6154

6255
export const updateProjects = async ( req : Request , res : Response ) => {
6356

64-
try {
57+
6558
const projectInfo = req.body.projectData;
6659
const projectId = parseInt(req.params.projectId);
6760
const updatedById = projectInfo.updatedById;
@@ -83,47 +76,40 @@ export const updateProjects = async ( req : Request , res : Response ) => {
8376
const project = await projectService.updateProjects( projectInfo , projectId );
8477
res.status(200).json(project)
8578

86-
} catch (error) {
87-
throw new ApiError(error as string , 500);
88-
}
79+
8980
}
9081

9182

9283
export const deleteProjects = async ( req : Request , res : Response ) => {
9384

94-
try {
85+
9586
const projectId = parseInt(req.params.projectId);
9687
if( !projectId ) throw new ApiError( " Send The project id " , 400);
9788

9889
const deleted = await projectService.deleteProjects( projectId );
9990
res.status(200).json(deleted)
10091

101-
} catch (error) {
102-
throw new ApiError( error as string , 500);
103-
}
92+
10493

10594
}
10695

10796
export const getMembersByProjectId = async ( req : Request , res : Response ) => {
10897

109-
try {
98+
11099
const projectId = parseInt( req.params.projectId );
111100
if( !projectId ) throw new ApiError( " Project Id required !!! " , 400);
112101

113102
const members = await projectService.getMembersByProjectId(projectId);
114103
res.status(200).json(members)
115104

116-
}
117-
catch (error) {
118-
throw new ApiError( error as string , 500);
119-
}
105+
120106

121107

122108
}
123109

124110
export const addMembers = async ( req : Request , res : Response ) => {
125111

126-
try {
112+
127113
const projectId = parseInt( req.params.projectId );
128114
const memberData = req.body.memberId;
129115
if( !projectId || !memberData || memberData.length === 0) throw new ApiError(" field is missing " , 400);
@@ -136,15 +122,13 @@ export const addMembers = async ( req : Request , res : Response ) => {
136122
const member = await projectService.addMembers( data );
137123
res.status(200).json(member);
138124

139-
} catch (error) {
140-
throw new ApiError( error as string , 500);
141-
}
125+
142126
}
143127

144128

145129
export const removeMembers = async ( req : Request , res : Response ) => {
146130

147-
try {
131+
148132
const data = {
149133
projectId : parseInt ( req.params.projectId ),
150134
memberId : req.params.memberId
@@ -155,8 +139,6 @@ export const removeMembers = async ( req : Request , res : Response ) => {
155139
const removedMember = await projectService.removeMembers(data);
156140
res.status(200).json( removedMember );
157141

158-
} catch (error) {
159-
throw new ApiError( error as string , 500);
160-
}
142+
161143
}
162144

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { Request, Response } from 'express'
2+
import * as questionServices from '../services/question.service'
3+
import { ApiError } from '../utils/apiError';
4+
5+
6+
export const getQuestionByTopicId = async (req: Request, res: Response) => {
7+
const topicId = parseInt(req.params.topicId);
8+
if (!topicId) {
9+
throw new ApiError("required field missing", 400);
10+
}
11+
12+
const questions = await questionServices.getQuestionByTopicId(topicId);
13+
14+
res.status(200).json({
15+
status: "SUCCESS",
16+
questions
17+
})
18+
19+
20+
}
21+
22+
export const addQuestion = async (req: Request, res: Response) => {
23+
24+
const topicId = parseInt(req.params.topicId);
25+
const { questionName, difficulty, link } = req.body
26+
const adminId = req.body.adminId;
27+
28+
if (!questionName || !difficulty || !link || !adminId || !topicId) {
29+
throw new ApiError("required field missing", 400);
30+
}
31+
32+
const question = await questionServices.addQuestionByTopicId(adminId, topicId, link, difficulty, questionName);
33+
res.status(201).json({
34+
status: "SUCCESS",
35+
question
36+
})
37+
38+
39+
}
40+
41+
export const getQuestionByQuestionId = async (req: Request, res: Response) => {
42+
const questionId = parseInt(req.params.questionId);
43+
if (!questionId) {
44+
throw new ApiError("required field missing", 400);
45+
}
46+
47+
const question = await questionServices.getQuestionByQuestionId(questionId);
48+
49+
if (!question) {
50+
throw new ApiError("No question found with this ID", 404);
51+
}
52+
res.status(200).json({
53+
status: "SUCCESS",
54+
question
55+
})
56+
57+
58+
59+
}
60+
61+
62+
export const updateQuestion = async (req: Request, res: Response) => {
63+
const questionId = parseInt(req.params.questionId);
64+
65+
const adminId = req.body.adminId;
66+
const questionData: questionData = req.body.questionData;
67+
68+
if (!questionData || JSON.stringify(questionData) === "{}" || !adminId) {
69+
throw new ApiError("required field missing", 400);
70+
}
71+
questionData.updatedById = adminId;
72+
73+
const question = await questionServices.updateQuestion(questionData, questionId);
74+
75+
if (!question) {
76+
throw new ApiError("No question found with this ID", 404);
77+
}
78+
79+
res.status(200).json({
80+
status: "SUCCESS",
81+
question
82+
})
83+
84+
}
85+
86+
export const deleteQuestion = async (req: Request, res: Response) => {
87+
const questionId = parseInt(req.params.questionId);
88+
if (!questionId) {
89+
throw new ApiError("required field missing ", 400);
90+
}
91+
92+
93+
await questionServices.deleteQuestion(questionId);
94+
95+
res.status(200).json({
96+
status: "SUCCESS"
97+
})
98+
99+
}
100+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { Request, Response } from 'express'
2+
import * as topicServices from '../services/topic.service'
3+
import { ApiError } from '../utils/apiError';
4+
5+
6+
export const getTopics = async (req: Request, res: Response) => {
7+
8+
const topics = await topicServices.getTopics();
9+
10+
res.status(201).json(topics)
11+
12+
}
13+
14+
15+
16+
export const createTopic = async (req: Request, res: Response) => {
17+
const { title, description } = req.body
18+
19+
const adminId = req.body.adminId
20+
if (!title || !description || !adminId) {
21+
throw new ApiError("missing required fields", 400);
22+
}
23+
const topic = await topicServices.createTopics(title, description, adminId);
24+
res.status(201).json(topic);
25+
26+
}
27+
28+
29+
30+
export const updateTopic = async (req: Request, res: Response) => {
31+
const topicId = parseInt(req.params.topicId);
32+
33+
const adminId = req.body.adminId
34+
35+
const updateData: topicData = req.body.updateData
36+
37+
if (!updateData || JSON.stringify(updateData) === '{}' || !adminId) {
38+
throw new ApiError("missing required fields", 400);
39+
}
40+
41+
42+
const updatedTopic = await topicServices.updateTopic(topicId, updateData, adminId);
43+
res.status(200).json(updatedTopic)
44+
45+
46+
}
47+
48+
export const deleteTopic = async (req: Request, res: Response) => {
49+
const topicId = parseInt(req.params.topicId);
50+
if (!topicId) {
51+
throw new ApiError("missing required fields", 400);
52+
}
53+
54+
await topicServices.deleteTopic(topicId);
55+
res.status(200).json({
56+
status: "SUCCESS"
57+
})
58+
59+
}
60+

src/routes/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@ import { Multer } from 'multer'
33
import { SupabaseClient } from '@supabase/supabase-js'
44
// import membersRouter from './members'
55
import projectsRouter from './projects'
6-
// bakiche tumhi import kara mala kantala ala
6+
import topicRouter from './topics'
7+
import quetionsRouter from './questions'
8+
import progressRouter from './progress'
79

810
export default function routes(upload: Multer, supabase: SupabaseClient) {
911
const router = Router()
1012

1113
// router.use('/members', membersRouter(upload, supabase))
1214
router.use('/projects', projectsRouter(upload, supabase))
13-
// … mount other routers, just write xyzRouter() if the routes in that router don't need multer or supabase
15+
16+
router.use('/topics',topicRouter());
17+
18+
router.use('/questions',quetionsRouter());
19+
20+
router.use('/progress',progressRouter());
21+
1422

1523
return router
1624
}

0 commit comments

Comments
 (0)