mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(server) added TagResponseDto for TagController (#1065)
* fix(server) added TagResponseDto for TagController * Added userId to DTO
This commit is contained in:
parent
db34f2f7fd
commit
f91bdc2785
13 changed files with 107 additions and 941 deletions
|
|
@ -9,6 +9,10 @@ export class TagResponseDto {
|
|||
type!: string;
|
||||
|
||||
name!: string;
|
||||
|
||||
userId!: string;
|
||||
|
||||
renameTagId?: string | null;
|
||||
}
|
||||
|
||||
export function mapTag(entity: TagEntity): TagResponseDto {
|
||||
|
|
@ -16,5 +20,7 @@ export function mapTag(entity: TagEntity): TagResponseDto {
|
|||
id: entity.id,
|
||||
type: entity.type,
|
||||
name: entity.name,
|
||||
userId: entity.userId,
|
||||
renameTagId: entity.renameTagId,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { UpdateTagDto } from './dto/update-tag.dto';
|
|||
import { Authenticated } from '../../decorators/authenticated.decorator';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
||||
import { TagEntity } from '@app/database/entities/tag.entity';
|
||||
import { mapTag, TagResponseDto } from "./response-dto/tag-response.dto";
|
||||
|
||||
@Authenticated()
|
||||
@ApiTags('Tag')
|
||||
|
|
@ -14,18 +14,19 @@ export class TagController {
|
|||
constructor(private readonly tagService: TagService) {}
|
||||
|
||||
@Post()
|
||||
create(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) createTagDto: CreateTagDto): Promise<TagEntity> {
|
||||
create(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) createTagDto: CreateTagDto): Promise<TagResponseDto> {
|
||||
return this.tagService.create(authUser, createTagDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(@GetAuthUser() authUser: AuthUserDto) {
|
||||
findAll(@GetAuthUser() authUser: AuthUserDto): Promise<TagResponseDto[]> {
|
||||
return this.tagService.findAll(authUser);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@GetAuthUser() authUser: AuthUserDto, @Param('id') id: string) {
|
||||
return this.tagService.findOne(authUser, id);
|
||||
async findOne(@GetAuthUser() authUser: AuthUserDto, @Param('id') id: string): Promise<TagResponseDto> {
|
||||
const tag = await this.tagService.findOne(authUser, id);
|
||||
return mapTag(tag);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
|
|
@ -33,12 +34,12 @@ export class TagController {
|
|||
@GetAuthUser() authUser: AuthUserDto,
|
||||
@Param('id') id: string,
|
||||
@Body(ValidationPipe) updateTagDto: UpdateTagDto,
|
||||
) {
|
||||
): Promise<TagResponseDto> {
|
||||
return this.tagService.update(authUser, id, updateTagDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
delete(@GetAuthUser() authUser: AuthUserDto, @Param('id') id: string) {
|
||||
delete(@GetAuthUser() authUser: AuthUserDto, @Param('id') id: string): Promise<void> {
|
||||
return this.tagService.remove(authUser, id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
|||
import { CreateTagDto } from './dto/create-tag.dto';
|
||||
import { UpdateTagDto } from './dto/update-tag.dto';
|
||||
import { ITagRepository, TAG_REPOSITORY } from './tag.repository';
|
||||
import { mapTag, TagResponseDto } from "./response-dto/tag-response.dto";
|
||||
|
||||
@Injectable()
|
||||
export class TagService {
|
||||
|
|
@ -13,7 +14,8 @@ export class TagService {
|
|||
|
||||
async create(authUser: AuthUserDto, createTagDto: CreateTagDto) {
|
||||
try {
|
||||
return await this._tagRepository.create(authUser.id, createTagDto.type, createTagDto.name);
|
||||
const newTag = await this._tagRepository.create(authUser.id, createTagDto.type, createTagDto.name);
|
||||
return mapTag(newTag);
|
||||
} catch (e: any) {
|
||||
this.logger.error(e, e.stack);
|
||||
throw new BadRequestException(`Failed to create tag: ${e.detail}`);
|
||||
|
|
@ -21,7 +23,8 @@ export class TagService {
|
|||
}
|
||||
|
||||
async findAll(authUser: AuthUserDto) {
|
||||
return await this._tagRepository.getByUserId(authUser.id);
|
||||
const tags = await this._tagRepository.getByUserId(authUser.id);
|
||||
return tags.map(mapTag);
|
||||
}
|
||||
|
||||
async findOne(authUser: AuthUserDto, id: string): Promise<TagEntity> {
|
||||
|
|
@ -34,15 +37,16 @@ export class TagService {
|
|||
return tag;
|
||||
}
|
||||
|
||||
async update(authUser: AuthUserDto, id: string, updateTagDto: UpdateTagDto) {
|
||||
async update(authUser: AuthUserDto, id: string, updateTagDto: UpdateTagDto): Promise<TagResponseDto> {
|
||||
const tag = await this.findOne(authUser, id);
|
||||
|
||||
return this._tagRepository.update(tag, updateTagDto);
|
||||
await this._tagRepository.update(tag, updateTagDto);
|
||||
|
||||
return mapTag(tag);
|
||||
}
|
||||
|
||||
async remove(authUser: AuthUserDto, id: string) {
|
||||
async remove(authUser: AuthUserDto, id: string): Promise<void> {
|
||||
const tag = await this.findOne(authUser, id);
|
||||
|
||||
return this._tagRepository.remove(tag);
|
||||
await this._tagRepository.remove(tag);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue