Update patchGroup.js #21
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({
region: 'ap-northeast-2',
endpoint: "http://dynamodb.ap-northeast-2.amazonaws.com"
})
// Create the DynamoDB service object
const dynamo = new AWS.DynamoDB.DocumentClient();
var response = {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
"GET": "success",
},
"isBase64Encoded": false
};
var failResponse = {
"statusCode": 400,
"headers": {
"GET": "fail"
},
"isBase64Encoded": false
};
exports.handler = function(event, context, callback) {
var func = event.func;
var id = event.id;
var probs = event.probs;
var baj_id = event.baj_id;
var sum = event.sum;
var rank_Group = event.rank_Group;
var attendance = event.attendance;
var cycle = event.cycle;
var number_member = event.number_member;
var new_member = event.new_member;
var number = event.number;
var name = event.name;
var rank_inGroup = event.rank_inGroup;
var score = event.score;
var prob_num = event.prob_num;
var goal = event.goal;
var prob_level = event.prob_level;
var group_noti = event.group_noti;
var rank_member = event.rank_member;
}
function updateProblems(id, probs, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET group_attendance.probs = :probs",
ExpressionAttributeValues: {":probs": probs}
};
dynamo.update(params, function(err, data) {
if (err) {
console.log("Error", err);
failResponse.body = JSON.stringify({"message":
has error: ${err}});callback(null, failResponse);
} else {
console.log("Success", data);
response.body = JSON.stringify(data);
callback(null, response);
}
});
}
function updateCycle(id, cycle, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET group_attendance.attendance_cycle = :cycle",
ExpressionAttributeValues: {":cycle": cycle}
}
function updateProblemNumber(id, prob_num, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET group_goal.prob_num = :prob_num",
ExpressionAttributeValues: {":prob_num": prob_num}
}
function updateGroupGoal(id, goal, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET group_goal.goal = :goal",
ExpressionAttributeValues: {":goal": goal}
}
function updateProblemLevel(id, prob_level, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET group_goal.prob_level = :prob_level",
ExpressionAttributeValues: {":prob_level": prob_level}
}
function updateGroupRank(id, rank_Group, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
AttributeUpdates: {
"rank_group": {
"Action": "PUT",
"Value": rank_Group
}
}
function updateGroupNotice(id, group_noti, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
AttributeUpdates: {
"group_noti": {
"Action": "PUT",
"Value": group_noti
}
}
function updateNumberMember(id,number_member,callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
AttributeUpdates: {
"number_member": {
"Action": "PUT",
"Value": number_member
}
}
function updateAttendance(id, name, attendance, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET rank_member.#name.attendance = :attendance",
ExpressionAttributeNames: {"#name": name},
ExpressionAttributeValues: {":attendance": attendance}
}
function updatePersonalRank(id, name, rank_inGroup, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET rank_member.#name.rank_inGroup = :rank_inGroup",
ExpressionAttributeNames: {"#name": name},
ExpressionAttributeValues: {":rank_inGroup": rank_inGroup}
}
function updatePersonalScore(id, name, score, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET rank_member.#name.score = :score",
ExpressionAttributeNames: {"#name": name},
ExpressionAttributeValues: {":score": score}
}
function addMember(id, new_member, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
AttributeUpdates: {
"member": {
"Action": "ADD",
"Value": new_member
}
}
}
function addRankMember(id, rank_member, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "SET rank_member = :rank_member",
ExpressionAttributeValues: {":rank_member": rank_member}
};
}
function deleteMember(id, callback){
}
function deleteRankMember(id, name, callback){
var params = {
TableName: 'groupDataBase',
Key: {
"id": id
},
UpdateExpression: "REMOVE rank_member.#name",
ExpressionAttributeNames: {"#name": name}
};
}