60 lines
1.4 KiB
TypeScript
60 lines
1.4 KiB
TypeScript
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<AppData>
|
|
{
|
|
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<string>();
|
|
|
|
constructor( id:string, ums:UserManagementServer )
|
|
{
|
|
this._ums = ums;
|
|
this._id = id;
|
|
|
|
this._path = Files.joinPaths( [ this._ums._settings.appsPath, this._id ] );
|
|
}
|
|
|
|
async initialize():Promise<void>
|
|
{
|
|
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<void>):Promise<void>
|
|
{
|
|
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<AppData>( file.absolutePath );
|
|
|
|
return action( userData, appData );
|
|
}
|
|
);
|
|
}
|
|
} |