Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizKindly log in to use this feature. We’ll take you to the login page automatically.
LoginCourse Queries Competitions/Entrance Exams 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
You are not using the Model correctly. Think that each Model.js is a table and each attribute is a column.
So, your Exam.js can be like this:
// api/models/Exam.js module.exports = { attributes: { name: { type: 'string', }, year: { type: 'integer' }, subject: { type: 'string', }, question: { type: 'string', }, answers: { type: 'array', } } };
And on the controller you will define how to display the data from db. You can learn more about Sails Models and Controllers on the docs:
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
I am building a mobile app for exam practice. I need an API endpoint for the exam details and questions. I need help with structuring my data in sails.js. I have this JSON structure from firebase in mind.
The endpoint GET operation should return this:
{ "8h9iuhiuhi89h98h": { "exam": "waec", "year": "1990", "subject": "chemistry", "question": "Which of these is not an acid", "answers": [ { option: "NaCl", isValid: true }, { option: "H2SO4", isValid: false }, { option: "H3", isValid: false }, { option: "HCl", isValid: false } ] }, "8h9iuhiuhi89h98h": { "exam": "waec", "year": "1990", "subject": "chemistry", "question": "Which of these is not an acid", "answers": [ { option: "NaCl", isValid: true }, { option: "H2SO4", isValid: false }, { option: "H3", isValid: false }, { option: "HCl", isValid: false } ] }, "8h9iuhiuhi89h98h": { "exam": "waec", "year": "1990", "subject": "chemistry", "question": "Which of these is not an acid", "answers": [ { option: "NaCl", isValid: true }, { option: "H2SO4", isValid: false }, { option: "H3", isValid: false }, { option: "HCl", isValid: false } ] }, "8h9iuhiuhi89h98h": { "exam": "waec", "year": "1990", "subject": "chemistry", "question": "Which of these is not an acid", "answers": [ { option: "NaCl", isValid: true }, { option: "H2SO4", isValid: false }, { option: "H3", isValid: false }, { option: "HCl", isValid: false } ] } }where waec is the exam, 1990 is the year, and chemistry is the subject.
http://someappurl.com/api/exam/{exam}/{year}/{subject}I have generated API using the sails generate command. but I don't know how to structure and query my data. How do I structure my schema? i have a sails model structure like this
attributes: { exams: { exam_name: 'string', years: { exam_year: 'string', subjects:[ { subject_name: 'string', questions: [ { serial_no: 'string', text: 'string', answers:[ { option: 'string', is_valid: 'boolean' } ] } ] } ] } } }