import { EventSlot } from "../../../browser/events/EventSlot"; import { Files } from "../../files/Files"; import { PathFilter } from "../../files/PathFilter"; import { UserData } from "../UserData"; import { UserManagementServer } from "../UserManagementServer"; export class UserApp { protected _id:string; get id(){ return this._id;} protected _ums:UserManagementServer; get ums(){ return this._ums } protected _path:string; get path(){ return this._path; } readonly onFileChange = new EventSlot(); constructor( id:string, ums:UserManagementServer ) { this._ums = ums; this._id = id; this._path = Files.joinPaths( [ this._ums._settings.appsPath, this._id ] ); } async initialize():Promise { return Promise.resolve(); } get schedulesTasks():boolean { return false; } getUserPath( userID:string ){ return Files.joinPaths( [ this.path, userID + ".json" ] ); } async iterateUserData( action:(ud:UserData,ad:AppData)=>Promise):Promise { await Files.forDirectChildrenIn( this.path, PathFilter.JSON, async ( file ) => { let id = file.fileNameWithoutExtension; if ( ! this.ums.userDB.hasUserWithID( id ) ) { return; } let userData = await this.ums.userDB.byID( id ); let appData = await Files.loadJSON( file.absolutePath ); return action( userData, appData ); } ); } }