diff --git a/server/src/data/getAppById.js b/server/src/data/getAppById.js index 96c5ebd74..f03cde58c 100644 --- a/server/src/data/getAppById.js +++ b/server/src/data/getAppById.js @@ -26,6 +26,7 @@ const getAppById = async (appId, languageCode, knex) => { app_id: appId, language_code: languageCode, }) + .orderBy('version_created_at', 'desc') } catch (err) { throw new Error(`Could not get app with id: ${appId}. ${err.message}`) } diff --git a/server/src/data/getApps.js b/server/src/data/getApps.js index 52abd6bf5..3a3cdafdc 100644 --- a/server/src/data/getApps.js +++ b/server/src/data/getApps.js @@ -53,7 +53,13 @@ const getApps = ( }) } }) - .orderBy('name') + .orderBy([ + 'name', + { + column: 'version_created_at', + order: 'desc', + }, + ]) } module.exports = getApps diff --git a/server/src/data/getAppsByIdAndStatus.js b/server/src/data/getAppsByIdAndStatus.js index 0ed9b13f0..27e0906e8 100644 --- a/server/src/data/getAppsByIdAndStatus.js +++ b/server/src/data/getAppsByIdAndStatus.js @@ -18,6 +18,7 @@ const getAppsByIdAndStatus = (id, status, languageCode, knex) => { status, language_code: languageCode, }) + .orderBy('version_created_at', 'desc') } module.exports = getAppsByIdAndStatus diff --git a/server/src/routes/v1/apps/formatting/convertAppsToApiV1Format.js b/server/src/routes/v1/apps/formatting/convertAppsToApiV1Format.js index c3ec3adf3..0b5762298 100644 --- a/server/src/routes/v1/apps/formatting/convertAppsToApiV1Format.js +++ b/server/src/routes/v1/apps/formatting/convertAppsToApiV1Format.js @@ -78,7 +78,8 @@ const convertAll = (apps, request) => { debug(`Using serverUrl: ${serverUrl}`) const formattedApps = {} - + // use api/v2 for paginated response, only return 5 latest versions + const maxVersions = 5 apps.forEach(app => { let currentApp = formattedApps[app.app_id] @@ -103,6 +104,7 @@ const convertAll = (apps, request) => { //Prevent duplicate versions if ( + currentApp.versions.length < maxVersions && !currentApp.versions.find(version => version.id === app.version_id) ) { currentApp.versions.push(convertAppToV1AppVersion(app, serverUrl)) diff --git a/server/src/routes/v2/apps.js b/server/src/routes/v2/apps.js index 57ed66f4f..4c97eac74 100644 --- a/server/src/routes/v2/apps.js +++ b/server/src/routes/v2/apps.js @@ -70,6 +70,7 @@ module.exports = [ apps, request.query.dhis_version ) + const pager = request.plugins.pagination const result = convertAppsToApiV1Format(filteredApps, request) return h.paginate(pager, {