Skip to content

Commit

Permalink
allow to clear all times
Browse files Browse the repository at this point in the history
  • Loading branch information
cz8s committed Oct 3, 2018
1 parent 6ebeac9 commit a7e1f7f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
10 changes: 10 additions & 0 deletions routes/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ router.post('/reopen-registration', isAuthenticated, (req, res) => {
}
});

router.post('/clear-times', isAuthenticated, (req, res) => {
if (canViewAdminPage(req.user.role)) {
participants.clearTimes().then(() =>
res.redirect('/admin')
);
}
});



module.exports = router;
12 changes: 12 additions & 0 deletions service/participants.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,18 @@ participants.getTime = (startnumber) => {
return deferred.promise;
};

participants.clearTimes = () => {
const deferred = Q.defer();
db.select('update participants set time = NULL, seconds = NULL')
.then((result) => {
deferred.resolve();
})
.catch(deferred.reject);
return deferred.promise;
};



participants.rank = (startnumber) => {
const deferred = Q.defer();
db.select("select pos from (select seconds,start_number,rank() over (order by seconds) as pos from participants where visibility='yes') as ss where start_number=$1;", [startnumber])
Expand Down
24 changes: 21 additions & 3 deletions spec/service/participantsITSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,24 @@ describe('participants service', () => {
done.fail();
});
});

it('should clear all times', (done) => {
let time = '10:32:32';
let nr = startNr++;
startBlocks.add('35000', 'startblock 1')
.then(() => startBlocks.add('36000', 'startblock 2'))
.then(() => participants.save(aParticipant.withStartNr(nr)))
.then(() => participants.insertTime(nr, time))
.then(() => participants.clearTimes())
.then(() => participants.get.byStartnumber(nr))
.then((participant) => {
expect(participant.time).toBeNull();
expect(participant.seconds).toBeNull();
done();
}).catch((err) => {
console.log("Err:", err);
done.fail();
});
});
it('should not save if time is slower than saved time', (done) => {
configMock.mockValue("teamEvent", false);
let time = '10:32:32';
Expand All @@ -525,8 +542,7 @@ describe('participants service', () => {
done.fail();
});
});

});
});

describe('team event', () => {
it('should save if time is slower than saved time', (done) => {
Expand Down Expand Up @@ -604,4 +620,6 @@ describe('participants service', () => {
});
});



});
7 changes: 7 additions & 0 deletions views/admin/admin.pug
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ block content
button#generate-start-numbers.primary.button-primary.pace(type='submit') Generieren
.two.columns
a(href='/pdf/startnumbers') download
form(method='POST', action='admin/clear-times')
.row
.eight.columns
input(type='hidden', name='_csrf', value=_csrf)
h4 Alle Zeiten löschen
.two.columns
button#clear-times.primary.button-primary.pace(type='submit') Löschen


script(src='/javascript/usageChart.js')
Expand Down

0 comments on commit a7e1f7f

Please sign in to comment.