Add contribution date #30

Merged
raucao merged 3 commits from feature/29-date_time into master 2019-04-13 16:07:47 +00:00
Showing only changes of commit fca991c685 - Show all commits

View File

@ -33,14 +33,15 @@ module.exports = async function(robot, kredits) {
}); });
} }
function createContribution(username, amount, description, url, details={}) { function createContribution(username, date, amount, description, url, details={}) {
return getContributorByWikiUser(username).then(contributor => { return getContributorByWikiUser(username).then(contributor => {
robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${contributor.name} for ${url}...`); robot.logger.debug(`[hubot-kredits] Creating contribution token for ${amount}₭S to ${contributor.name} for ${url}...`);
let contribution = { let contribution = {
contributorId: contributor.id, contributorId: contributor.id,
amount: amount,
contributorIpfsHash: contributor.ipfsHash, contributorIpfsHash: contributor.ipfsHash,
date,
amount: amount,
url, url,
description, description,
details, details,
@ -141,6 +142,10 @@ module.exports = async function(robot, kredits) {
} }
function createContributionForUserChanges (user, changes) { function createContributionForUserChanges (user, changes) {
const dateNow = new Date();
const dateYesterday = dateNow.setDate(dateNow.getDate() - 1);
const date = (new Date(dateYesterday)).toISOString().split('T')[0];
const details = analyzeUserChanges(user, changes); const details = analyzeUserChanges(user, changes);
const amount = calculateAmountForChanges(details); const amount = calculateAmountForChanges(details);
@ -161,7 +166,7 @@ module.exports = async function(robot, kredits) {
url = `${wikiURL}index.php?title=${rc.title}&diff=${rc.revid}&oldid=${rc.old_revid}`; url = `${wikiURL}index.php?title=${rc.title}&diff=${rc.revid}&oldid=${rc.old_revid}`;
} }
return createContribution(user, amount, desc, url, details); return createContribution(user, date, amount, desc, url, details);
} }
function updateTimestampForNextFetch () { function updateTimestampForNextFetch () {