feat: per-project workflow settings, statistics and "my work" home

Per-project settings (owners/admins, «Configuración» tab):
- Statuses with category (TODO, IN_PROGRESS, QA, DONE, CANCELLED), colour and
  "requires reason"; configurable transitions; ticket types (icon, colour) and
  areas. Defaults are the previous fixed values; projects created before keep
  them without migration.
- Values are archived, never deleted: tickets, history and statistics keep
  referring to them. Validated in the domain (ProjectSettingsChangedEvent).
- Releases, board, tracking and "my work" use categories, so custom statuses
  keep working. Status changes carry name/category metadata for history.
- GraphQL: status/type/area are strings (breaking for clients sending enum
  literals); Project.settings, updateProjectSettings, statusCategory,
  myIssues(categories). REST: PUT /projects/{project}/settings, category filters.
- Read model: statusCategory on issues (backfilled at startup).

Statistics («Estadísticas» tab):
- New issue_timeline projection; pure functions compute created vs resolved,
  cumulative flow, cycle/lead time (avg + p85), throughput per person, QA
  pass/fail and release burnup. GraphQL Project.analytics(days),
  Release.burnup; REST /projects/{project}/analytics, /releases/{id}/burnup.
- Web: SVG charts with validated light/dark palette, crosshair tooltip,
  keyboard navigation, legend and data table.

Home "Mi trabajo": my open tickets across projects grouped by category (QA
failures first), tickets waiting for QA, upcoming releases and "Ir a…".

Tests: domain/application specs, e2e scenario for settings and analytics,
facade tests. Docs, READMEs, schema.gql/openapi.json and Word/PDF updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 20:53:45 +02:00
parent 240ea9a539
commit 0e301ad545
143 changed files with 10291 additions and 1052 deletions

View File

@@ -1,11 +1,13 @@
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import {
CrossProjectIssueFilter,
FindActivityRepository,
FindCommentsRepository,
FindIssuesRepository,
FindProjectsRepository,
FindReleasesRepository,
FindTimelineRepository,
IssueFilter,
Page,
} from '@task-stream/api/tracker/application';
@@ -13,14 +15,16 @@ import {
ActivityReadModel,
CommentReadModel,
CountBy,
FINISHED_STATUSES,
defaultProjectSettings,
IssueReadModel,
IssueStatus,
IssueTimelineEntry,
ProjectReadModel,
ProjectRole,
ProjectStatsReadModel,
ReleaseProgressReadModel,
ReleaseReadModel,
ReleaseStatus,
StatusCategory,
UserRefReadModel,
} from '@task-stream/api/tracker/domain';
import { FilterQuery, Model } from 'mongoose';
@@ -31,6 +35,7 @@ import {
ProjectDoc,
ReadModels,
ReleaseDoc,
TimelineDoc,
fromDoc,
issueFromDoc,
} from './read-model.schemas';
@@ -40,9 +45,15 @@ import {
const escapeRegex = (text: string) =>
text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const FINISHED = [StatusCategory.DONE, StatusCategory.CANCELLED];
function toProject(doc: ProjectDoc): ProjectReadModel {
const { memberIds: _ignored, ...rest } = doc;
return fromDoc(rest);
// Projects projected before settings existed use the defaults.
return {
...fromDoc(rest),
settings: rest.settings ?? defaultProjectSettings(),
};
}
@Injectable()
@@ -123,6 +134,29 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
return { items: docs.map(issueFromDoc), total };
}
async searchAcross(
filter: CrossProjectIssueFilter,
): Promise<Page<IssueReadModel>> {
if (filter.projectIds.length === 0) return { items: [], total: 0 };
const query: Record<string, unknown> = {
projectId: { $in: filter.projectIds },
};
if (filter.assigneeId) query['assignee.id'] = filter.assigneeId;
if (filter.statuses?.length) query['status'] = { $in: filter.statuses };
if (filter.categories?.length)
query['statusCategory'] = { $in: filter.categories };
const [docs, total] = await Promise.all([
this.issues
.find(query)
.sort({ updatedAt: -1 })
.skip(filter.offset)
.limit(filter.limit)
.lean<IssueDoc[]>(),
this.issues.countDocuments(query),
]);
return { items: docs.map(issueFromDoc), total };
}
async stats(projectId: string): Promise<ProjectStatsReadModel> {
const countBy = (field: string) => [
{ $group: { _id: `$${field}`, count: { $sum: 1 } } },
@@ -131,7 +165,7 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
const [facets] = await this.issues.aggregate<{
total: { count: number }[];
open: { count: number }[];
byStatus: { _id: IssueStatus; count: number }[];
byStatus: { _id: string; count: number }[];
byType: { _id: string; count: number }[];
byPriority: { _id: string; count: number }[];
byArea: { _id: string | null; count: number }[];
@@ -142,7 +176,7 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
$facet: {
total: [{ $count: 'count' }],
open: [
{ $match: { status: { $nin: FINISHED_STATUSES } } },
{ $match: { statusCategory: { $nin: FINISHED } } },
{ $count: 'count' },
],
byStatus: countBy('status'),
@@ -150,7 +184,7 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
byPriority: countBy('priority'),
byArea: countBy('area'),
byAssignee: [
{ $match: { status: { $nin: FINISHED_STATUSES } } },
{ $match: { statusCategory: { $nin: FINISHED } } },
...countBy('assignee'),
],
},
@@ -173,23 +207,36 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
};
}
async findByProject(projectId: string): Promise<IssueReadModel[]> {
const docs = await this.issues.find({ projectId }).lean<IssueDoc[]>();
return docs.map(issueFromDoc);
}
async releaseProgress(releaseId: string): Promise<ReleaseProgressReadModel> {
const rows = await this.issues.aggregate<{
_id: IssueStatus;
_id: { status: string; category: StatusCategory };
count: number;
}>([
{ $match: { 'release.id': releaseId } },
{ $group: { _id: '$status', count: { $sum: 1 } } },
{
$group: {
_id: { status: '$status', category: '$statusCategory' },
count: { $sum: 1 },
},
},
]);
const total = rows.reduce((sum, r) => sum + r.count, 0);
const finished = rows
.filter((r) => FINISHED_STATUSES.includes(r._id))
.filter((r) => FINISHED.includes(r._id.category))
.reduce((sum, r) => sum + r.count, 0);
const byStatus = new Map<string, number>();
for (const r of rows)
byStatus.set(r._id.status, (byStatus.get(r._id.status) ?? 0) + r.count);
return {
total,
finished,
percent: total === 0 ? 0 : Math.round((finished / total) * 100),
byStatus: rows.map((r) => ({ key: r._id, count: r.count })),
byStatus: [...byStatus].map(([key, count]) => ({ key, count })),
};
}
}
@@ -197,6 +244,8 @@ export class MongoFindIssuesRepository extends FindIssuesRepository {
function toMongoFilter(filter: IssueFilter): FilterQuery<IssueDoc> {
const query: FilterQuery<IssueDoc> = { projectId: filter.projectId };
if (filter.statuses?.length) query.status = { $in: filter.statuses };
if (filter.categories?.length)
query['statusCategory'] = { $in: filter.categories };
if (filter.types?.length) query['type'] = { $in: filter.types };
if (filter.areas?.length) query['area'] = { $in: filter.areas };
if (filter.priorities?.length) query['priority'] = { $in: filter.priorities };
@@ -273,6 +322,25 @@ export class MongoFindReleasesRepository extends FindReleasesRepository {
.lean<ReleaseDoc[]>();
return docs.map(fromDoc);
}
async findUpcoming(
projectIds: string[],
limit: number,
): Promise<ReleaseReadModel[]> {
if (projectIds.length === 0) return [];
const docs = await this.releases
.find({ projectId: { $in: projectIds }, status: ReleaseStatus.PLANNED })
.lean<ReleaseDoc[]>();
// Ascending targetDate puts nulls first in Mongo: sort here instead.
return docs
.map(fromDoc)
.sort(
(a, b) =>
(a.targetDate ?? '9999').localeCompare(b.targetDate ?? '9999') ||
a.name.localeCompare(b.name),
)
.slice(0, limit);
}
}
@Injectable()
@@ -301,3 +369,21 @@ export class MongoFindActivityRepository extends FindActivityRepository {
return docs.map(fromDoc);
}
}
@Injectable()
export class MongoFindTimelineRepository extends FindTimelineRepository {
constructor(
@InjectModel(ReadModels.Timeline)
private readonly timeline: Model<TimelineDoc>,
) {
super();
}
async findByProject(projectId: string): Promise<IssueTimelineEntry[]> {
const docs = await this.timeline
.find({ projectId })
.sort({ at: 1 })
.lean<TimelineDoc[]>();
return docs.map(fromDoc);
}
}