How to use the entities.UserRole.STATION_OWNER function in entities

To help you get started, we’ve selected a few entities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mgm-interns / team-radio / server / src / config / GraphQLManager.ts View on Github external
this.logger.info('User not exist in application context. Access denied!');
        throw new UnauthorizedException('You are not logged in yet!');
      }
      if (roles.length === 0) {
        // if roles doesn't provided, only check user existence in context
        if (context.user.isUser()) {
          return true;
        }
      }
      if (context.user.isUser()) {
        const authenticatedContext = context as IAuthenticatedContext;
        if (roles.includes(UserRole.ADMIN) && authenticatedContext.user.isAdmin()) {
          return true;
        }
        if (
          roles.includes(UserRole.STATION_OWNER) &&
          (authenticatedContext.user.isStationOwner(args['id']) ||
            authenticatedContext.user.isStationOwner(args['stationId']))
        ) {
          return true;
        }
      }
      // no roles matched, restrict access
      throw new UnauthorizedException("You don't have permission for this action");
    };
  }
github mgm-interns / team-radio / server / src / resolvers / song / PlaylistSongsCRUDResolver.ts View on Github external
return this.playlistSongCRUDService.update(
      id,
      songId,
      title,
      url,
      creatorId,
      stationId,
      duration,
      thumbnail,
      isPlayed,
      upVotes,
      downVotes
    );
  }

  @Authorized([UserRole.STATION_OWNER])
  @Mutation(returns => PlaylistSong, {
    name: 'deletePlaylistSong',
    description: "Delete a song that's currently in playlist."
  })
  public async delete(@Arg('id') id: string): Promise {
    return this.playlistSongCRUDService.delete(id);
  }
}
github mgm-interns / team-radio / server / src / resolvers / song / HistorySongsCRUDResolver.ts View on Github external
return this.historySongCRUDService.update(
      id,
      songId,
      title,
      url,
      creatorId,
      stationId,
      duration,
      thumbnail,
      isPlayed,
      upVotes,
      downVotes
    );
  }

  @Authorized([UserRole.STATION_OWNER])
  @Mutation(returns => HistorySong, {
    name: 'deleteHistorySong',
    description: "Delete a song that's currently in history."
  })
  public async delete(@Arg('id') id: string): Promise {
    return this.historySongCRUDService.delete(id);
  }

  protected getDefaultFilter() {
    return {
      isPlayed: true
    };
  }
}
github mgm-interns / team-radio / server / src / resolvers / station / StationCRUDResolvers.ts View on Github external
filter
    );
    return new ListMetaData(total);
  }

  @Authorized()
  @Mutation(returns => Station, { name: 'createStation', description: 'Create a station in system.' })
  public async create(
    @Arg('stationName') stationName: string,
    @Arg('ownerId') ownerId: string,
    @Arg('stationId', { nullable: true }) stationId?: string
  ): Promise {
    return this.stationCRUDService.create(stationName, ownerId, stationId);
  }

  @Authorized([UserRole.STATION_OWNER])
  @Mutation(returns => Station, { name: 'updateStation', description: 'Update a station in system.' })
  public async update(
    @Arg('id') id: string,
    @Arg('stationName', { nullable: true }) stationName: string,
    @Arg('ownerId', { nullable: true }) ownerId: string,
    @Arg('stationId', { nullable: true }) stationId?: string
  ): Promise {
    return this.stationCRUDService.update(id, stationName, ownerId, stationId);
  }

  @Authorized([UserRole.STATION_OWNER])
  @Mutation(returns => Station, { name: 'deleteStation', description: 'Delete a station in system.' })
  public async delete(@Arg('id') id: string): Promise {
    return this.stationCRUDService.delete(id);
  }
}
github mgm-interns / team-radio / server / src / resolvers / song / SongCRUDResolver.ts View on Github external
@Arg('perPage', type => Int, { nullable: true }) perPage?: number,
    @Arg('sortField', { nullable: true }) sortField?: string,
    @Arg('sortOrder', { nullable: true }) sortOrder?: string,
    @Arg('filter', type => SongFilter, { nullable: true }) filter?: SongFilter
  ): Promise {
    const [entities, total] = await this.songCRUDService.findAllAndCount(page, perPage, sortField, sortOrder, filter);
    return new ListMetaData(total);
  }

  @Authorized()
  @Mutation(returns => Song, { name: 'createSong', description: 'Create a song in system.' })
  public async create(): Promise {
    throw new MethodNotAllowedException();
  }

  @Authorized([UserRole.STATION_OWNER])
  @Mutation(returns => Song, { name: 'updateSong', description: 'Update a song in system.' })
  public async update(
    @Arg('id') id: string,
    @Arg('songId', { nullable: true }) songId?: string,
    @Arg('title', { nullable: true }) title?: string,
    @Arg('url', { nullable: true }) url?: string,
    @Arg('creatorId', { nullable: true }) creatorId?: string,
    @Arg('stationId', { nullable: true }) stationId?: string,
    @Arg('duration', { nullable: true }) duration?: number,
    @Arg('thumbnail', { nullable: true }) thumbnail?: string,
    @Arg('isPlayed', { nullable: true }) isPlayed?: boolean,
    @Arg('upVotes', type => [String], { nullable: true }) upVotes?: string[],
    @Arg('downVotes', type => [String], { nullable: true }) downVotes?: string[]
  ): Promise {
    return this.songCRUDService.update(
      id,