Skip to content

Commit

Permalink
fix(apps): fix source-url being cleared when new version is uploaded (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo authored Nov 16, 2022
1 parent f8da690 commit 4ff7525
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/src/routes/v1/apps/formatting/convertAppsToApiV1Format.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const debug = require('debug')(
const { MediaType } = require('../../../../enums')
const getServerUrl = require('../../../../utils/getServerUrl')

const convertDbAppViewRowToAppApiV1Object = app => ({
const convertDbAppViewRowToAppApiV1Object = (app) => ({
appType: app.type,

status: app.status,
Expand Down Expand Up @@ -78,7 +78,7 @@ const convertAll = (apps, request) => {
debug(`Using serverUrl: ${serverUrl}`)

const formattedApps = {}
apps.forEach(app => {
apps.forEach((app) => {
let currentApp = formattedApps[app.app_id]

if (!currentApp) {
Expand All @@ -90,7 +90,7 @@ const convertAll = (apps, request) => {
if (app.media_id !== null) {
const media = convertAppToV1Media(app, serverUrl)

if (!currentApp.images.find(img => img.id === media.id)) {
if (!currentApp.images.find((img) => img.id === media.id)) {
currentApp.images.push(media)
}

Expand All @@ -100,9 +100,17 @@ const convertAll = (apps, request) => {
})
}

// some app-version may not have a version set
// sourceUrl really should be in 'app'-table, not 'app_version'
if (app.source_url && !currentApp.sourceUrl) {
currentApp.sourceUrl = app.source_url
}

//Prevent duplicate versions
if (
!currentApp.versions.find(version => version.id === app.version_id)
!currentApp.versions.find(
(version) => version.id === app.version_id
)
) {
currentApp.versions.push(convertAppToV1AppVersion(app, serverUrl))
}
Expand Down

0 comments on commit 4ff7525

Please sign in to comment.