Skip to content

Commit

Permalink
fixing the message users get when code:push to an app with latest liv…
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaharshaki2 committed Sep 16, 2024
1 parent e4223da commit 4b33f37
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/services/app-versions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,23 @@ export const listAppVersionsByAppId = async (appId: AppId): Promise<Array<AppVer

export const defaultVersionByAppId = async (
appId: AppId,
customLogMessage?: string,
useLiveVersion = false,
options: { customLogMessage?: string; useLiveVersion?: boolean } = {},
): Promise<AppVersion | undefined> => {
const defaults = { useLiveVersion: false };
options = { ...defaults, ...options };
logger.info(`Getting the latest valid version for app id - ${appId}`);

const appVersions = await listAppVersionsByAppId(appId);
const latestVersion = appVersions.sort((a, b) => b.id - a.id)[0];
const allowedStatuses = useLiveVersion
const allowedStatuses = options.useLiveVersion
? [APP_VERSION_STATUS.LIVE, APP_VERSION_STATUS.DRAFT]
: [APP_VERSION_STATUS.DRAFT];

const validVersion = allowedStatuses.includes(latestVersion.status) ? latestVersion : undefined;
if (validVersion) {
logger.info(`Using version - ${validVersion?.id} for app id - ${appId}`);
} else {
logger.info(customLogMessage || `No valid version found for app id - ${appId}`);
logger.info(options?.customLogMessage || `No valid version found for app id - ${appId}`);
}

return validVersion;
Expand Down
2 changes: 1 addition & 1 deletion src/services/apps-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const cloneAppTemplateAndLoadManifest = async (
};

export const createFeatures = async (ctx: AppCreateCommandTasksContext) => {
const defaultVersion = await defaultVersionByAppId(ctx.appId!, undefined, false);
const defaultVersion = await defaultVersionByAppId(ctx.appId!);
const baseUrl = await getTunnelingDomain();
if (!defaultVersion) throw new Error(`No default version found for app id - ${ctx.appId}`);
ctx.appVersionId = defaultVersion.id;
Expand Down
5 changes: 4 additions & 1 deletion src/services/dynamic-choices-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export const DynamicChoicesService = {
if (useLiveVersion) filterByStatus.push(APP_VERSION_STATUS.LIVE);

if (appId && autoSelectVersion) {
const defaultVersion = await defaultVersionByAppId(appId, LIVE_VERSION_ERROR_LOG, useLiveVersion);
const defaultVersion = await defaultVersionByAppId(appId, {
customLogMessage: LIVE_VERSION_ERROR_LOG,
useLiveVersion: useLiveVersion,
});
if (!defaultVersion) throw new Error(`No default version found for app id - ${appId}`);

return { appId, appVersionId: defaultVersion.id };
Expand Down

0 comments on commit 4b33f37

Please sign in to comment.