Browse Source

feat(update app): back to prev status before update

cchalopin 1 year ago
parent
commit
f61e6b2dae

File diff suppressed because it is too large
+ 0 - 733
pnpm-lock.yaml


+ 10 - 0
src/server/services/apps/apps.service.test.ts

@@ -505,6 +505,16 @@ describe('Update app', () => {
     const app = await getAppById(appConfig.id, db);
     const app = await getAppById(appConfig.id, db);
     expect(app?.status).toBe('stopped');
     expect(app?.status).toBe('stopped');
   });
   });
+  it('Should comme back to the previous status before the update of the app', async () => {
+    // arrange
+    const appConfig = createAppConfig({});
+    await insertApp({ status: 'stopped' }, appConfig, db);
+
+    // act & assert
+    await updateApp(appConfig.id, { version: 0 }, db);
+    const app = await getAppById(appConfig.id, db);
+    expect(app?.status).toBe('stopped');
+  });
 });
 });
 
 
 describe('installedApps', () => {
 describe('installedApps', () => {

+ 8 - 2
src/server/services/apps/apps.service.ts

@@ -341,6 +341,7 @@ export class AppServiceClass {
    */
    */
   public updateApp = async (id: string) => {
   public updateApp = async (id: string) => {
     const app = await this.queries.getApp(id);
     const app = await this.queries.getApp(id);
+    const appStatusBeforeUpdate = app?.status;
 
 
     if (!app) {
     if (!app) {
       throw new TranslatedError('server-messages.errors.app-not-found', { id });
       throw new TranslatedError('server-messages.errors.app-not-found', { id });
@@ -355,14 +356,19 @@ export class AppServiceClass {
     if (success) {
     if (success) {
       const appInfo = getAppInfo(app.id, app.status);
       const appInfo = getAppInfo(app.id, app.status);
 
 
-      await this.queries.updateApp(id, { status: 'running', version: appInfo?.tipi_version });
+      await this.queries.updateApp(id, { version: appInfo?.tipi_version });
+      if (appStatusBeforeUpdate === 'running') {
+        await this.startApp(id);
+      } else {
+        await this.queries.updateApp(id, { status: appStatusBeforeUpdate });
+      }
     } else {
     } else {
       await this.queries.updateApp(id, { status: 'stopped' });
       await this.queries.updateApp(id, { status: 'stopped' });
       Logger.error(`Failed to update app ${id}: ${stdout}`);
       Logger.error(`Failed to update app ${id}: ${stdout}`);
       throw new TranslatedError('server-messages.errors.app-failed-to-update', { id });
       throw new TranslatedError('server-messages.errors.app-failed-to-update', { id });
     }
     }
 
 
-    const updatedApp = await this.queries.updateApp(id, { status: 'stopped' });
+    const updatedApp = await this.getApp(id);
     return updatedApp;
     return updatedApp;
   };
   };
 
 

Some files were not shown because too many files changed in this diff