import { AppNotFoundError } from "../common/errors" ; import Usecase from "../common/Usecase" ; import { IApp } from "../entities/App" ; import { IConfiguration , validateConfiguration , } from "../entities/Configuration" ; import { Operation } from "../entities/OperationLog" ; export default class UpdateApp extends Usecase { async exec ( id , patch ) { const existingApp = await this . storages . apps . findOne ( id ) ; if ( ! existingApp ) { throw new AppNotFoundError ( id , "id" ) ; } await this . authorizer . ensureCanUpdateApp ( existingApp . name ) ; if ( patch . defaultConfiguration ) { validateConfiguration ( patch . defaultConfiguration , "defaultConfiguration" ) ; } const updatedApp = await this . storages . apps . updateOne ( id , { defaultConfiguration : patch . defaultConfiguration , updatedAt : new Date ( ) , } ) ; await this . operationLogger . logOperation ( Operation . UpdateApp , { oldApp : existingApp , newApp : updatedApp , } ) ; return updatedApp ; } }