Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit a33aa09

Browse files
lunayachpaavininanda
authored andcommitted
Multiple Levels in Activities , Part 1 (#155)
1 parent 54779fb commit a33aa09

File tree

61 files changed

+782
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+782
-212
lines changed

config/passport.js

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = function(passport, models) {
1212

1313
const localUser = models.user_account;
1414
const progress = models.progress;
15+
const levelProgress = models.levelProgress;
1516
const activityProgress = models.activityProgress;
1617
let fname, lname;
1718

@@ -69,35 +70,37 @@ module.exports = function(passport, models) {
6970
user_id: user.id,
7071
stage: 0,
7172
activity: 0
72-
}})
73-
.spread((status, created) => {
74-
const response = {email: user.email, name: user.name};
75-
return done(null, response);
76-
})
77-
.catch(function(err) {
78-
return done(err);
79-
});
73+
}}).spread(() => {
74+
const response = {email: user.email, name: user.name};
75+
return done(null, response);
76+
}).catch(function(err) {
77+
return done(err);
78+
});
79+
levelProgress.findOrCreate({where: {
80+
user_id: user.id
81+
}, defaults: {
82+
user_id: user.id,
83+
}}).spread(() => {
84+
const response = {email: user.email, name: user.name};
85+
return done(null, response);
86+
}).catch(function(err) {
87+
return done(err);
88+
});
8089
activityProgress.findOrCreate({where: {
8190
user_id: user.id
8291
}, defaults: {
8392
user_id: user.id,
84-
}})
85-
.spread(() => {
86-
const response = {email: user.email, name: user.name};
87-
return done(null, response);
88-
})
89-
.catch(function(err) {
90-
return done(err);
91-
});
92-
}
93-
94-
)
95-
.catch(function(err) {
93+
}}).spread(() => {
94+
const response = {email: user.email, name: user.name};
95+
return done(null, response);
96+
}).catch(function(err) {
97+
return done(err);
98+
});
99+
}).catch(function(err) {
96100
return done(err);
97101
});
98102
});
99103
}));
100-
101104
passport.use('local-login', new LocalStrategy({
102105
usernameField: 'email',
103106
passwordField: 'password',

data/codes.json

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,28 @@
176176
"code": "PCE035",
177177
"message": "PCE035 Something went wrong while fetching activity-progress data",
178178
"reason": "Internal Server Error"
179-
}
179+
},
180+
"PCE036": {
181+
"code": "PCE036",
182+
"message": "No activity-level data was found",
183+
"reason": "User is not logged in or his data in not logged in levelProgress Table"
184+
},
185+
"PCE037": {
186+
"code": "PCE037",
187+
"message": "Something went wrong while fetching level-progress data",
188+
"reason": "Internal Server Error"
189+
},
190+
"PCE038": {
191+
"code": "PCE038",
192+
"message": "Something went wrong while updating level-progress data",
193+
"reason": "Internal Server Error"
194+
},
195+
"PCE039": {
196+
"code": "PCE039",
197+
"message": "Could not update user's activity level",
198+
"reason": "Request body was empty"
199+
}
180200
},
181-
182201
"success": {
183202
"PCS001": {
184203
"code": "PCS001",
@@ -202,21 +221,25 @@
202221
"message": "PCS005 : Verification mail sent, please check your mail"
203222
},
204223
"PCS006": {
205-
"code": "PCS006",
206-
"message": "PCS006 : User's profile was successfully updated"
224+
"code": "PCS006",
225+
"message": "PCS006 : User's profile was successfully updated"
207226
},
208227
"PCS007": {
209-
"code": "PCS007",
210-
"message": "PCS007 User's current badge was successfully updated"
228+
"code": "PCS007",
229+
"message": "PCS007 User's current badge was successfully updated"
211230
},
212231
"PCS008": {
213-
"code": "PCS008",
214-
"message": "PCS008 User's current total score was successfully updated"
232+
"code": "PCS008",
233+
"message": "PCS008 User's current total score was successfully updated"
215234
},
216235
"PCS009": {
217-
"code": "PCS009",
218-
"message": "PCS009 User's current score in the specific activity was updated"
219-
}
236+
"code": "PCS009",
237+
"message": "PCS009 User's current score in the specific activity was updated"
238+
},
239+
"PCS010": {
240+
"code": "PCS010",
241+
"message": "User's current level in the specific activity was updated"
242+
}
220243
}
221244
}
222245

data/quiz.json

Lines changed: 150 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,153 @@
11
{
2-
"quizlist":
3-
[
4-
{
5-
"question":"Malaria is transmitted ______",
6-
"option1":"Through mosquito bites",
7-
"option2":"By eating tainted food",
8-
"option3":"by physical contact",
9-
"option4":"By playing in dirt",
10-
"answer":"1"
11-
},
12-
{
13-
"question":"Malaria is prevented by ______",
14-
"option1":"Playing in dirt",
15-
"option2":"By not maintaining hygiene",
16-
"option3":"Sleeping under an insecticide-treated bednet",
17-
"option4":"By eating unprotected food",
18-
"answer":"3"
19-
},
20-
{
21-
"question":"Which of the following can repel mosquitoes?",
22-
"option1":"Banana",
23-
"option2":"Chilli",
24-
"option3":"Citronella",
25-
"option4":"Garlic",
26-
"answer":"3"
27-
},
28-
{
29-
"question":"Which of these drink contains quinine, an anti-malarial property?",
30-
"option1":"Lemonade",
31-
"option2":"Tonic",
32-
"option3":"Warm milk",
33-
"option4":"Cola",
34-
"answer":"2"
35-
},
36-
{
37-
"question":"Malaria is transmitted by a mosquito bite, but what causes the disease?",
38-
"option1":"Insecticide",
39-
"option2":"A virus",
40-
"option3":"Blood poisoning",
41-
"option4":"A parasite",
42-
"answer":"4"
43-
},
44-
{
45-
"question":"Find the odd symptom of malaria",
46-
"option1":"Fever",
47-
"option2":"Dizziness",
48-
"option3":"Fatigue",
49-
"option4":"Back pain",
50-
"answer":"2"
51-
},
52-
{
53-
"question":"Find the odd statement",
54-
"option1":"Malaria is a neglected tropical disease",
55-
"option2":"If you get malaria once, you won't ever get it again",
56-
"option3":"Malaria is quite often endemic in poorer regions of the world",
57-
"option4":"Malaria is not curable",
58-
"answer":"3"
59-
},
60-
{
61-
"question":"Disease associated with malaria",
62-
"option1":"Jaundice",
63-
"option2":"Tuberculosis",
64-
"option3":"Cholera",
65-
"option4":"Typhoid",
66-
"answer":"1"
67-
}
68-
]
2+
"level1": [
3+
{
4+
"question": "Malaria is transmitted ______",
5+
"option1": "Through mosquito bites",
6+
"option2": "By eating tainted food",
7+
"option3": "by physical contact",
8+
"option4": "By playing in dirt",
9+
"answer": "1"
10+
},
11+
{
12+
"question": "Malaria is prevented by ______",
13+
"option1": "Playing in dirt",
14+
"option2": "By not maintaining hygiene",
15+
"option3": "Sleeping under an insecticide-treated bednet",
16+
"option4": "By eating unprotected food",
17+
"answer": "3"
18+
},
19+
{
20+
"question": "Which of the following can repel mosquitoes?",
21+
"option1": "Banana",
22+
"option2": "Chilli",
23+
"option3": "Citronella",
24+
"option4": "Garlic",
25+
"answer": "3"
26+
},
27+
{
28+
"question": "Which of these drink contains quinine, an anti-malarial property?",
29+
"option1": "Lemonade",
30+
"option2": "Tonic",
31+
"option3": "Warm milk",
32+
"option4": "Cola",
33+
"answer": "2"
34+
}
35+
],
36+
"level2": [
37+
{
38+
"question": "Malaria is transmitted by a mosquito bite, but what causes the disease?",
39+
"option1": "Insecticide",
40+
"option2": "A virus",
41+
"option3": "Blood poisoning",
42+
"option4": "A parasite",
43+
"answer": "4"
44+
},
45+
{
46+
"question": "Find the odd symptom of malaria",
47+
"option1": "Fever",
48+
"option2": "Dizziness",
49+
"option3": "Fatigue",
50+
"option4": "Back pain",
51+
"answer": "2"
52+
},
53+
{
54+
"question": "Find the odd statement",
55+
"option1": "Malaria is a neglected tropical disease",
56+
"option2": "If you get malaria once, you won't ever get it again",
57+
"option3": "Malaria is quite often endemic in poorer regions of the world",
58+
"option4": "Malaria is not curable",
59+
"answer": "3"
60+
},
61+
{
62+
"question": "Disease associated with malaria",
63+
"option1": "Jaundice",
64+
"option2": "Tuberculosis",
65+
"option3": "Cholera",
66+
"option4": "Typhoid",
67+
"answer": "1"
68+
},
69+
{
70+
"question": "There are four kinds of malaria that can infect humans. They are all spread by what?",
71+
"option1": " a worm in the intestine",
72+
"option2": " a tick bite",
73+
"option3": " a mosquito bite",
74+
"option4": " a tsetse fly bite",
75+
"answer": "3"
76+
},
77+
{
78+
"question": "What part of the body do these malaria parasites feed on?",
79+
"option1": " intestinal lining",
80+
"option2": "muscles",
81+
"option3": "red blood cells",
82+
"option4": "brain tissue",
83+
"answer": "3"
84+
}
85+
],
86+
"level3": [
87+
{
88+
"question": "How long must a malaria parasite grow in its host before infection can be spread to a human being?",
89+
"option1": " twenty four hours",
90+
"option2": "a week or more",
91+
"option3": "two weeks",
92+
"option4": "one month",
93+
"answer": "2"
94+
},
95+
{
96+
"question": "Once malaria parasites enter a person's blood they then travel to which organ?",
97+
"option1": "kidneys",
98+
"option2": "liver",
99+
"option3": "heart",
100+
"option4": "stomach",
101+
"answer": "2"
102+
},
103+
{
104+
"question": "Of the four types of malaria, 'falciparum malaria' is the most deadly. This type of malaria is most prevalent in what place?",
105+
"option1": "southeast Asia",
106+
"option2": "subSaharan Africa",
107+
"option3": "India",
108+
"option4": "South Africa",
109+
"answer": "2"
110+
},
111+
{
112+
"question": "How many countries and territories worldwide are considered at risk for malarial infections?",
113+
"option1": "around 50",
114+
"option2": "more than 100",
115+
"option3": "fewer than 80",
116+
"option4": "exactly 65",
117+
"answer": "2"
118+
},
119+
{
120+
"question": "According to the World Health Organization's estimate in 2000, malaria kills one child how often?",
121+
"option1": " every 15 minutes",
122+
"option2": " every minute",
123+
"option3": "every 30 seconds",
124+
"option4": "every five minutes",
125+
"answer": "3"
126+
},
127+
{
128+
"question": "African children under the age of five suffer approximately how many bouts of malaria per year?",
129+
"option1": "10",
130+
"option2": "6",
131+
"option3": "12",
132+
"option4": "3",
133+
"answer": "2"
134+
},
135+
{
136+
"question": "Which type of malaria is usually fatal?",
137+
"option1": " severe malaria",
138+
"option2": "cerebral malaria",
139+
"option3": "placental malaria",
140+
"option4": " all of the above",
141+
"answer": "4"
142+
},
143+
{
144+
"question": "How soon, after infection, will a person feel usually begin to feel ill?",
145+
"option1": " 6 days",
146+
"option2": "2 days",
147+
"option3": "4 days",
148+
"option4": "none of the above",
149+
"answer": "4"
150+
}
151+
]
69152
}
70153

database/associations.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = function(models) {
33
const Progress = models.progress;
44
const Infokit = models.info_kit;
55
const Verification = models.verification;
6+
const levelProgress = models.levelProgress;
67
const activityProgress = models.activityProgress;
78

89
// 1:1 relationship between User and Progress table
@@ -12,6 +13,9 @@ module.exports = function(models) {
1213
User.hasOne(Infokit, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
1314
Verification.belongsTo(User, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
1415
User.hasOne(Verification, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
16+
levelProgress.belongsTo(User, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
17+
User.hasOne(levelProgress, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
1518
activityProgress.belongsTo(User, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
1619
User.hasOne(activityProgress, {foreignKey: 'user_id', targetKey: 'id', onDelete: 'cascade'});
1720
};
21+

0 commit comments

Comments
 (0)