Skip to content

Commit

Permalink
feat(xml_query_fix): Refactor xmlfinder aggregation query to return t…
Browse files Browse the repository at this point in the history
…otalItem count
  • Loading branch information
tholulomo committed Aug 30, 2023
1 parent 3d5baa8 commit f9f0030
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions resfulservice/spec/graphql/resolver/xml.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('XmlData Resolver Unit Tests:', function () {
it("should return paginated lists of xmlData when no input", async () => {
sinon.stub(XmlData, 'countDocuments').returns(2);
sinon.stub(CuratedSamples, 'countDocuments').returns(1)
sinon.stub(XmlData, 'aggregate').returns(mockXmlDataList);
sinon.stub(XmlData, 'aggregate').returns([{count: mockXmlDataList.length, xmlData: mockXmlDataList }]);

const result = await xmlFinder({}, { input }, { req });

Expand All @@ -60,7 +60,7 @@ describe('XmlData Resolver Unit Tests:', function () {
sinon.stub(XmlData, 'countDocuments').returns(2)
sinon.stub(CuratedSamples, 'countDocuments').returns(1)

sinon.stub(XmlData, 'aggregate').returns(mockXmlDataList);
sinon.stub(XmlData, 'aggregate').returns([{count: mockXmlDataList.length, xmlData: mockXmlDataList }]);

const result = await xmlFinder({}, { input }, { req });

Expand Down
2 changes: 1 addition & 1 deletion resfulservice/src/graphql/resolver/xml/input.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ input xmlViewerInput {
"""
A Boolean value to specify it is new curation
"""
isNewCuration: Boolean!
isNewCuration: Boolean
}
10 changes: 5 additions & 5 deletions resfulservice/src/pipelines/curation-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ exports.curationSearchQuery = async (input) => {
if (status) filter.status = status.replace('_', ' ');
if (typeof isNewCuration === 'boolean') filter.isNewCuration = isNewCuration;

const xmlData = await XmlData.aggregate([
const data = await XmlData.aggregate([
{ $match: xmlDataFilter },
{
$project: {
Expand Down Expand Up @@ -54,9 +54,9 @@ exports.curationSearchQuery = async (input) => {
}
},
{ $match: filter },
{ $skip: skip },
{ $limit: pageSize }
{ $group: { _id: null, count: { $sum: 1 }, xmlData: { $push: '$$ROOT' } } },
{ $project: { _id: 0, count: 1, xmlData: { $slice: ['$xmlData', skip, pageSize] } } }
]);

return { xmlData, count: xmlData.length };
const { xmlData, count } = data[0];
return { xmlData, count };
};

0 comments on commit f9f0030

Please sign in to comment.