mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
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:
@@ -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';
|
||||
|
||||
12
server/src/api-v1/sharing/dto/update-shared-album.dto.ts
Normal file
12
server/src/api-v1/sharing/dto/update-shared-album.dto.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class UpdateShareAlbumDto {
|
||||
@IsNotEmpty()
|
||||
albumId: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
albumName: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
ownerId: string;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user