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

This commit is contained in:
cchalopin 2023-11-26 15:03:21 +01:00
parent 769f671749
commit f61e6b2dae
3 changed files with 21 additions and 1960 deletions

File diff suppressed because it is too large Load diff

View file

@ -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', () => {

View file

@ -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;
};