Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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");
};
}
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);
}
}
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
};
}
}
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);
}
}
@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,