feat: saved views of my work, across my projects
A person saves named views of «my work»: projects, assigned to me, that I follow, status categories, priorities, bugs only, overdue and text. They are private (Mongo my_views, no history), listed and deleted by their owner (GraphQL myViews / saveMyView / deleteMyView, REST /api/me/views), and run as the cross-project search, which gains project, priority, bugsOnly and overdue filters (also in MCP my_issues). The home page shows them as a bar above «my work», with a drawer to save a new one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { MyViewsRepository } from '@task-stream/api/tracker/application';
|
||||
import { MyViewReadModel } from '@task-stream/api/tracker/domain';
|
||||
import { Model } from 'mongoose';
|
||||
import { MyViewDoc, ReadModels, fromDoc } from './read-model.schemas';
|
||||
|
||||
@Injectable()
|
||||
export class MongoMyViewsRepository extends MyViewsRepository {
|
||||
constructor(
|
||||
@InjectModel(ReadModels.MyView)
|
||||
private readonly views: Model<MyViewDoc>,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
async findByOwner(ownerId: string): Promise<MyViewReadModel[]> {
|
||||
const docs = await this.views
|
||||
.find({ ownerId })
|
||||
.sort({ name: 1 })
|
||||
.lean<MyViewDoc[]>();
|
||||
return docs.map(toView);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<MyViewReadModel | null> {
|
||||
const doc = await this.views.findOne({ id }).lean<MyViewDoc>();
|
||||
return doc ? toView(doc) : null;
|
||||
}
|
||||
|
||||
countByOwner(ownerId: string): Promise<number> {
|
||||
return this.views.countDocuments({ ownerId });
|
||||
}
|
||||
|
||||
async insert(view: MyViewReadModel): Promise<void> {
|
||||
await this.views.create(view);
|
||||
}
|
||||
|
||||
async delete(id: string): Promise<void> {
|
||||
await this.views.deleteOne({ id });
|
||||
}
|
||||
}
|
||||
|
||||
/** Mongo leaves empty objects out: a view with no criteria has none. */
|
||||
function toView(doc: MyViewDoc): MyViewReadModel {
|
||||
const view = fromDoc(doc) as MyViewReadModel;
|
||||
return { ...view, criteria: view.criteria ?? {} };
|
||||
}
|
||||
Reference in New Issue
Block a user