courses get and post
This commit is contained in:
@@ -11,6 +11,5 @@ module.exports.default = async () => {
|
||||
} catch (err) {
|
||||
const statusCode = (err && err.statusCode) || 500;
|
||||
return createResponse(statusCode, err.message || err);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
15
handlers/courses/post.js
Normal file
15
handlers/courses/post.js
Normal file
@@ -0,0 +1,15 @@
|
||||
const {createResponse} = require('../../helpers');
|
||||
const {parseAndValidateBody} = require('../../validators');
|
||||
const {courseSchema} = require('../../validators/schemas');
|
||||
const db = require('../../services/db');
|
||||
|
||||
module.exports.default = async (event, context, callback) => {
|
||||
try {
|
||||
const course = await parseAndValidateBody(courseSchema, event.body);
|
||||
const createCourseResult = await db.create('gt_courses', course);
|
||||
return createResponse(200, {course: createCourseResult});
|
||||
} catch (err) {
|
||||
const statusCode = (err && err.statusCode) || 500;
|
||||
return createResponse(statusCode, err.message || err);
|
||||
}
|
||||
};
|
||||
@@ -66,13 +66,20 @@ provider:
|
||||
# - exclude-me-dir/**
|
||||
|
||||
functions:
|
||||
courses:
|
||||
courses-get:
|
||||
handler: handlers/courses/get.default
|
||||
events:
|
||||
- http:
|
||||
path: courses
|
||||
method: get
|
||||
cors: true
|
||||
courses-post:
|
||||
handler: handlers/courses/post.default
|
||||
events:
|
||||
- http:
|
||||
path: courses
|
||||
method: post
|
||||
cors: true
|
||||
|
||||
# The following are a few example events you can configure
|
||||
# NOTE: Please make sure to change your handler code to work with those events
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
// const answerSchema = {
|
||||
// "type": "object",
|
||||
// "properties": {
|
||||
// "user_id": {"type": "string"},
|
||||
// "question_id": {"type": "string"},
|
||||
// "is_correct": {"type": "boolean"}
|
||||
// },
|
||||
// "required": ["user_id", "question_id", "is_correct"]
|
||||
// };
|
||||
|
||||
module.exports = {
|
||||
answerSchema,
|
||||
userSchema,
|
||||
loginFollowUpSchema
|
||||
const courseSchema = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"course_name": {"type": "string"},
|
||||
"num_tests": {"type": "number"},
|
||||
"num_questions_per_test": {"type": "number"},
|
||||
"answers": {"type": "array"}
|
||||
},
|
||||
"required": ["course_name", "num_tests", "num_questions_per_test", "answers"]
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
courseSchema
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user