This repository has been archived by the owner on Jun 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: list all package versions by date (#1557)
- Loading branch information
Showing
7 changed files
with
104 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
const moment = require('moment'); | ||
const packageService = require('../../../services/package'); | ||
|
||
// GET /-/allversions?date={2020-02-20} | ||
// List all packages versions sync at date(gmt_modified) | ||
|
||
module.exports = function* () { | ||
const query = this.query; | ||
const date = moment(query.date, 'YYYY-MM-DD'); | ||
if (!date.isValid()) { | ||
this.status = 400; | ||
const error = '[query_parse_error] Invalid value for `date`, should be `YYYY-MM-DD` format.'; | ||
this.body = { | ||
error, | ||
reason: error, | ||
}; | ||
return; | ||
} | ||
|
||
const today = date.format('YYYY-MM-DD'); | ||
const rows = yield packageService.findAllModuleAbbreviateds({ | ||
gmt_modified: { | ||
$gte: `${today} 00:00:00`, | ||
$lte: `${today} 23:59:59`, | ||
}, | ||
}); | ||
this.body = rows.map(row => { | ||
return { | ||
name: row.name, | ||
version: row.version, | ||
publish_time: new Date(row.publish_time), | ||
gmt_modified: row.gmt_modified, | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
const should = require('should'); | ||
const request = require('supertest'); | ||
const mm = require('mm'); | ||
const moment = require('moment'); | ||
const config = require('../../../../config'); | ||
const app = require('../../../../servers/registry'); | ||
const utils = require('../../../utils'); | ||
|
||
describe('test/controllers/registry/package/list_versions.test.js', function () { | ||
afterEach(mm.restore); | ||
|
||
before(function (done) { | ||
utils.sync('pedding', done); | ||
}); | ||
|
||
describe('GET /-/allversions', function () { | ||
it('should get 200', function (done) { | ||
mm(config, 'syncModel', 'all'); | ||
request(app) | ||
.get('/-/allversions?date=' + moment().format('YYYY-MM-DD')) | ||
.expect(200, function (err, res) { | ||
should.not.exist(err); | ||
console.log(res.body); | ||
const rows = res.body; | ||
rows.length.should.above(0); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should get 404', function (done) { | ||
mm(config, 'syncModel', 'all'); | ||
request(app) | ||
.get('/-/allversions?date=notadsfwe') | ||
.expect(400, function (err, res) { | ||
should.not.exist(err); | ||
res.body.reason.should.equal('[query_parse_error] Invalid value for `date`, should be `YYYY-MM-DD` format.'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters