feat: add user job listing and summary helpers for dashboard flows
This commit is contained in:
@@ -120,6 +120,29 @@ class XArtAudioEngine {
|
||||
return this.jobs.get(jobId) || null;
|
||||
}
|
||||
|
||||
listJobsForUser(userId) {
|
||||
if (!userId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Array.from(this.jobs.values())
|
||||
.filter((job) => job.callerUserId === userId)
|
||||
.sort((a, b) => Number(b.id) - Number(a.id));
|
||||
}
|
||||
|
||||
getUserSummary(userId) {
|
||||
const jobs = this.listJobsForUser(userId);
|
||||
const completed = jobs.filter((job) => job.status === "completed").length;
|
||||
const totalCreditsSpent = jobs.reduce((sum, job) => sum + job.creditsCharged, 0);
|
||||
|
||||
return {
|
||||
balance: this.getWalletBalance(userId),
|
||||
totalJobs: jobs.length,
|
||||
completedJobs: completed,
|
||||
totalCreditsSpent,
|
||||
};
|
||||
}
|
||||
|
||||
getAsset(assetId) {
|
||||
return this.assets.get(String(assetId)) || null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user