feat(update app): back to prev status before update
This commit is contained in:
parent
197f6e3998
commit
31c3de78b8
3 changed files with 21 additions and 1184 deletions
1185
pnpm-lock.yaml
1185
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
|
@ -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', () => {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue