fujaba / fulib.org

The fulib web app: fulibScenarios, fulibWorkflows, Docs, Projects and Assignments in one app.
https://fulib.org
MIT License
5 stars 1 forks source link

only emit to users that have access to the assignment #352

Open github-actions[bot] opened 1 year ago

github-actions[bot] commented 1 year ago

https://api.github.com/fujaba/fulib.org/blob/1c9ac6c/services/apps/assignments/src/selection/selection.service.ts#L15


import {EventService} from '@mean-stream/nestx';
import {Injectable} from '@nestjs/common';
import {filter} from 'rxjs';
import {CreateSelectionDto, SelectionDto} from './selection.dto';

@Injectable()
export class SelectionService {
  constructor(
    private eventService: EventService,
  ) {
  }

  create(assignment: string, solution: string, dto: CreateSelectionDto): SelectionDto {
    const selection: SelectionDto = {...dto, assignment, solution};
    // TODO only emit to users that have access to the assignment
    this.eventService.emit(`assignments.${assignment}.solutions.${solution}.selections.created`, selection);
    return selection;
  }

  subscribe(assignment: string, solution: string, event: string, user?: string, author?: string) {
    const stream = this.eventService.subscribe<SelectionDto>(`assignments.${assignment}.solutions.${solution}.selections.${event}`, user);
    if (author) {
      return stream.pipe(filter(({data}) => data.author === author));
    }
    return stream;
  }
}