Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Sync master with develop #46

Merged
merged 2 commits into from
Nov 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/models/Group.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ const GroupSchema = new Schema({
groupId: {
type: String,
hashKey: true
},
createdAt: {
type: String,
required: true
},
updatedAt: {
type: String,
required: true
}
}, {
throughput: {
Expand Down
10 changes: 9 additions & 1 deletion src/models/Leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,15 @@ const LeaderboardSchema = new Schema({
schema: [String]
},
status: { type: String },
finalDetails: { type: Object }
finalDetails: { type: Object },
createdAt: {
type: String,
required: true
},
updatedAt: {
type: String,
required: true
}
}, {
throughput: {
read: Number(config.AMAZON.DYNAMODB_READ_CAPACITY_UNITS),
Expand Down
12 changes: 9 additions & 3 deletions src/services/GroupService.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ async function searchGroups () {
* @returns {Object} the created group
*/
async function createGroup (groupId) {
const entity = await Group.get(groupId)
let entity = await Group.get(groupId)
if (entity) {
throw new errors.ConflictError(`groupId # ${groupId} already exists.`)
}

const dbEntity = await Group.create({ groupId })
entity = {
groupId,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
}

const dbEntity = await Group.create(entity)
try {
await helper.publishMessage('create', 'group', { groupId })
await helper.publishMessage('create', 'group', entity)
} catch (err) {
logger.logFullError(err)
}
Expand Down
10 changes: 9 additions & 1 deletion src/services/LeaderboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ async function createLeaderboard (challengeId, memberId, review) {
testsPassed,
totalTestCases,
scoreLevel,
groupIds: _.map(groupIds, e => String(e))
groupIds: _.map(groupIds, e => String(e)),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
}

const dbEntity = await Leaderboard.create(record)
Expand Down Expand Up @@ -251,6 +253,12 @@ async function updateLeaderboard (challengeId, memberId, review) {
})
}

if (!existRecords[0].createdAt) {
existRecords[0].createdAt = new Date().toISOString()
}

existRecords[0].updatedAt = new Date().toISOString()

const dbEntity = await existRecords[0].save()
try {
await helper.publishMessage('update', 'leaderboard', existRecords[0])
Expand Down