Files
task-stream/libs/api/tracker/infrastructure/src/lib/mongo/release-note-shares.repository.ts
Josep Piguillem 8ed16f133e feat: a public notes page per release, for clients
On the releases page, «Página pública» (owners and admins) opens a
secret link to a page with the release's notes, readable without an
account, also for private projects: the notes written, or the draft
from its finished tickets while there are none (without repeating the
title the page already shows). The link can be copied, renewed (the old
one stops working) or withdrawn. Stored in Mongo (`release_note_shares`).

API: shareReleaseNotes / unshareReleaseNotes / releaseNotesShare,
publicReleaseNotes(token); GET/PUT/DELETE /api/releases/{id}/public-notes,
GET /api/shared/release-notes/{token}. Web: /notes/:token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 20:57:40 +02:00

45 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import {
ReleaseNoteSharesRepository,
ReleaseNotesShare,
} from '@task-stream/api/tracker/application';
import { Model } from 'mongoose';
import { ReadModels } from './read-model.schemas';
type Stored = ReleaseNotesShare & { _id?: unknown };
const strip = ({ _id: _ignored, ...share }: Stored): ReleaseNotesShare => share;
@Injectable()
export class MongoReleaseNoteSharesRepository extends ReleaseNoteSharesRepository {
constructor(
@InjectModel(ReadModels.ReleaseNotesShare)
private readonly shares: Model<Stored>,
) {
super();
}
async findByRelease(releaseId: string): Promise<ReleaseNotesShare | null> {
const doc = await this.shares.findOne({ releaseId }).lean<Stored>();
return doc ? strip(doc) : null;
}
async findByToken(token: string): Promise<ReleaseNotesShare | null> {
const doc = await this.shares.findOne({ token }).lean<Stored>();
return doc ? strip(doc) : null;
}
async save(share: ReleaseNotesShare): Promise<void> {
await this.shares.updateOne(
{ releaseId: share.releaseId },
{ $set: share },
{ upsert: true },
);
}
async remove(releaseId: string): Promise<void> {
await this.shares.deleteOne({ releaseId });
}
}