Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
linxiaoxin committed Jul 27, 2024
2 parents 0b568f2 + 6ffc4a3 commit f0f75d0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
19 changes: 14 additions & 5 deletions app/(main)/questions/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const EditQuestion = () => {

useEffect(()=>{
QuestionsService.getTopics().then((data) => {
console.log("topics initialized: ", data);
setListOfTopics(data);
});
QuestionsService.getSkills().then((data) => {
console.log("skills initialized: ", data);
setListOfSkills(data);
});
}, [])
Expand Down Expand Up @@ -116,6 +118,7 @@ const EditQuestion = () => {
setShowOptionDialog(false);
};
const handleOnClickDone =() => {
console.log("handleOnClickDone")
//validate
const answer = addedOptions.filter((option: Questions.Option)=>{
return option.isAnswer
Expand All @@ -127,13 +130,19 @@ const EditQuestion = () => {
//instantiate MCQ object before adding
let mcq = {
stem: stem,
option: addedOptions,
isAnswer: answer[0].no,
status: "Draft",
options: addedOptions,
topics: selectedTopics,
skills: selectedSkills
skills: selectedSkills,
// isAnswer: answer[0].no,
status: "Draft",

}
console.log(mcq)
console.log("mcq to be created ", mcq);
QuestionsService.addMCQ(mcq).then((data) => {
console.log("saveQuestion response: ", data);
}).catch((e)=>{
console.log("saveQuestion error: ", e);
});
}
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion app/(main)/questions/searchlist/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Tag } from 'primereact/tag';

const QuestioSearchList = () => {
const [MCQ, setMCQ] = useState<Questions.MCQ[]>([]);
const [loading, setLoading] = useState(true);
const [loading, setLoading] = useState(true); // what is this for

useEffect(() => {
const retrieveQuestionRequest: Questions.RetrieveQuestionRequest = {
Expand Down
20 changes: 19 additions & 1 deletion service/QuestionsService.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
import { Questions } from '@/types';

const QuesionsSvcUrl = process.env.NEXT_PUBLIC_QUEMISTRY_QUESTIONS_URL || ''
const retrieveQuestionUrl = `${process.env.NEXT_PUBLIC_QUEMISTRY_GATEWAY_URL}/questions/retrieve` || ''
const retrieveQuestionUrl = `${process.env.NEXT_PUBLIC_QUEMISTRY_GATEWAY_URL}/questions/retrieve`
const saveQuestionUrl = `${process.env.NEXT_PUBLIC_QUEMISTRY_GATEWAY_URL}/questions`

export const QuestionsService = {
addMCQ(data : any) {
console.log("calling saveQuestion ", saveQuestionUrl, data);
return fetch(saveQuestionUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
credentials: "include",
body: JSON.stringify(data)
})
.then((res) => {
return res.json();
})
.then((data) => {
return data as Questions.MCQ}
);
},
getMCQ() {
return fetch(QuesionsSvcUrl, {
headers: {
Expand Down

0 comments on commit f0f75d0

Please sign in to comment.