courses get and post
This commit is contained in:
@@ -11,6 +11,5 @@ module.exports.default = async () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
const statusCode = (err && err.statusCode) || 500;
|
const statusCode = (err && err.statusCode) || 500;
|
||||||
return createResponse(statusCode, err.message || err);
|
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/**
|
# - exclude-me-dir/**
|
||||||
|
|
||||||
functions:
|
functions:
|
||||||
courses:
|
courses-get:
|
||||||
handler: handlers/courses/get.default
|
handler: handlers/courses/get.default
|
||||||
events:
|
events:
|
||||||
- http:
|
- http:
|
||||||
path: courses
|
path: courses
|
||||||
method: get
|
method: get
|
||||||
cors: true
|
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
|
# The following are a few example events you can configure
|
||||||
# NOTE: Please make sure to change your handler code to work with those events
|
# NOTE: Please make sure to change your handler code to work with those events
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
// const answerSchema = {
|
const courseSchema = {
|
||||||
// "type": "object",
|
"type": "object",
|
||||||
// "properties": {
|
"properties": {
|
||||||
// "user_id": {"type": "string"},
|
"course_name": {"type": "string"},
|
||||||
// "question_id": {"type": "string"},
|
"num_tests": {"type": "number"},
|
||||||
// "is_correct": {"type": "boolean"}
|
"num_questions_per_test": {"type": "number"},
|
||||||
// },
|
"answers": {"type": "array"}
|
||||||
// "required": ["user_id", "question_id", "is_correct"]
|
},
|
||||||
// };
|
"required": ["course_name", "num_tests", "num_questions_per_test", "answers"]
|
||||||
|
};
|
||||||
module.exports = {
|
|
||||||
answerSchema,
|
module.exports = {
|
||||||
userSchema,
|
courseSchema
|
||||||
loginFollowUpSchema
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user