Skip to content

Instantly share code, notes, and snippets.

@imflamboyant
Created May 4, 2022 08:49
Show Gist options
  • Select an option

  • Save imflamboyant/2e0376bcc977439a83de8ba9245024f5 to your computer and use it in GitHub Desktop.

Select an option

Save imflamboyant/2e0376bcc977439a83de8ba9245024f5 to your computer and use it in GitHub Desktop.
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Song } from './entities/song.entity';
@Injectable()
export class SongService {
constructor(
@InjectRepository(Song) private songRepository: Repository<Song>,
) {
}
async create(song: Song): Promise<Song> {
return await this.songRepository.save(song);
}
async findAll(): Promise<Song[]> {
return await this.songRepository.find();
}
async findOne(id: number): Promise<Song> {
return await this.songRepository.findOne({ id });
}
async remove(id: number): Promise<void> {
await this.songRepository.delete(id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment