浏览代码

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

cchalopin 1 年之前
父节点
当前提交
f61e6b2dae
共有 3 个文件被更改,包括 18 次插入735 次删除
  1. 0 733
      pnpm-lock.yaml
  2. 10 0
      src/server/services/apps/apps.service.test.ts
  3. 8 2
      src/server/services/apps/apps.service.ts

文件差异内容过多而无法显示
+ 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);
     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', () => {

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

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

部分文件因为文件数量过多而无法显示