Implemented editable album title (#130)

* Replace static title text with a text edit field
* Implement endpoint for updating album info
* Implement changing title
* Only the owner can change the title
This commit is contained in:
Alex
2022-04-28 23:46:37 -05:00
committed by GitHub
parent c5c7a134dd
commit 38e0178c81
10 changed files with 290 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ import {
Headers,
Delete,
Logger,
Patch,
} from '@nestjs/common';
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
import { AssetService } from './asset.service';

View File

@@ -0,0 +1,12 @@
import { IsNotEmpty } from 'class-validator';
export class UpdateShareAlbumDto {
@IsNotEmpty()
albumId: string;
@IsNotEmpty()
albumName: string;
@IsNotEmpty()
ownerId: string;
}

View File

@@ -2,10 +2,11 @@ import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Validatio
import { SharingService } from './sharing.service';
import { CreateSharedAlbumDto } from './dto/create-shared-album.dto';
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
import { GetAuthUser } from '../../decorators/auth-user.decorator';
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
import { AddAssetsDto } from './dto/add-assets.dto';
import { AddUsersDto } from './dto/add-users.dto';
import { RemoveAssetsDto } from './dto/remove-assets.dto';
import { UpdateShareAlbumDto } from './dto/update-shared-album.dto';
@UseGuards(JwtAuthGuard)
@Controller('shared')
@@ -52,4 +53,9 @@ export class SharingController {
async leaveAlbum(@GetAuthUser() authUser, @Param('albumId') albumId: string) {
return await this.sharingService.leaveAlbum(authUser, albumId);
}
@Patch('/updateInfo')
async updateAlbumInfo(@GetAuthUser() authUser, @Body(ValidationPipe) updateAlbumInfoDto: UpdateShareAlbumDto) {
return await this.sharingService.updateAlbumTitle(authUser, updateAlbumInfoDto);
}
}

View File

@@ -12,6 +12,7 @@ import { UserSharedAlbumEntity } from './entities/user-shared-album.entity';
import _ from 'lodash';
import { AddUsersDto } from './dto/add-users.dto';
import { RemoveAssetsDto } from './dto/remove-assets.dto';
import { UpdateShareAlbumDto } from './dto/update-shared-album.dto';
@Injectable()
export class SharingService {
@@ -184,4 +185,15 @@ export class SharingService {
return await this.assetSharedAlbumRepository.save([...newRecords]);
}
async updateAlbumTitle(authUser: AuthUserDto, updateShareAlbumDto: UpdateShareAlbumDto) {
if (authUser.id != updateShareAlbumDto.ownerId) {
throw new BadRequestException('Unauthorized to change album info');
}
const sharedAlbum = await this.sharedAlbumRepository.findOne({ where: { id: updateShareAlbumDto.albumId } });
sharedAlbum.albumName = updateShareAlbumDto.albumName;
return await this.sharedAlbumRepository.save(sharedAlbum);
}
}