Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
github-actions bot opened this issue Sep 12, 2023 · 0 comments
Open

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

github-actions bot opened this issue Sep 12, 2023 · 0 comments
Assignees
Labels

Comments

@github-actions
Copy link

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;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant