Create

2가지 방법으로 생성할 수 있다.

  1. relation

    async createAlbum(createAlbumRequestDto: CreateAlbumRequestDto): Promise<string> {
        const { groupId, albumName } = createAlbumRequestDto;
        const group = await this.groupRepository.findOne(groupId, { relations: ["albums"] });
        if (!group) throw new NotFoundException(`Not found group with the id ${groupId}`);
    
        const album = new Album();
        album.albumName = albumName;
        album.base = false;
    
        group.albums.push(album);
        await group.save();
    
        return album.albumName;
      }
    
  2. 직접 접근

    async createAlbum(createAlbumRequestDto: CreateAlbumRequestDto): Promise<string> {
        const { groupId, albumName } = createAlbumRequestDto;
        const group = await this.groupRepository.findOne({ groupId });
        if (!group) throw new NotFoundException(`Not found group with the id ${groupId}`);
    
        const album = await this.albumRepository.save({
          albumName: albumName,
          base: false,
          group: group,
        });
    
        return album.albumName;
      }
    

Delete

async deletePost(postId: number): Promise<string> {
    const post = await this.postRepository.findOne(postId, { relations: ["images"] });
    if (!post) throw new NotFoundException(`Not found post with the id ${postId}`);

    this.postRepository.softRemove(post);

    return "Post delete success!!";
  }
async deletePost(postId: number): Promise<string> {
    const post = await this.postRepository.findOne(postId);
    if (!post) throw new NotFoundException(`Not found post with the id ${postId}`);

    this.postRepository.softRemove(post);

    return "Post delete success!!";
  }

group안에 있는 앨범과 앨범에 연관된 게시글들 가져오는 쿼리