mirror of
https://github.com/immich-app/immich.git
synced 2025-12-18 17:23:16 +03:00
fix(server) added TagResponseDto for TagController (#1065)
* fix(server) added TagResponseDto for TagController * Added userId to DTO
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1490,7 +1490,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
"$ref": "#/components/schemas/TagResponseDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1511,7 +1511,7 @@
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
"$ref": "#/components/schemas/TagResponseDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1542,7 +1542,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
"$ref": "#/components/schemas/TagResponseDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1580,7 +1580,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object"
|
||||
"$ref": "#/components/schemas/TagResponseDto"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1604,14 +1604,7 @@
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
}
|
||||
}
|
||||
}
|
||||
"description": ""
|
||||
}
|
||||
},
|
||||
"tags": [
|
||||
@@ -2527,12 +2520,20 @@
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"type": "string"
|
||||
},
|
||||
"renameTagId": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"type",
|
||||
"name"
|
||||
"name",
|
||||
"userId"
|
||||
]
|
||||
},
|
||||
"AssetResponseDto": {
|
||||
@@ -3025,372 +3026,6 @@
|
||||
"name"
|
||||
]
|
||||
},
|
||||
"ExifEntity": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string"
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "General info"
|
||||
},
|
||||
"exifImageWidth": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"exifImageHeight": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"fileSizeInByte": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"orientation": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"dateTimeOriginal": {
|
||||
"format": "date-time",
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"modifyDate": {
|
||||
"format": "date-time",
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"latitude": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"longitude": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"city": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"state": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"country": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"make": {
|
||||
"type": "string",
|
||||
"nullable": true,
|
||||
"description": "Image info"
|
||||
},
|
||||
"model": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"imageName": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"lensModel": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"fNumber": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"focalLength": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"iso": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"exposureTime": {
|
||||
"type": "number",
|
||||
"nullable": true
|
||||
},
|
||||
"fps": {
|
||||
"type": "number",
|
||||
"nullable": true,
|
||||
"description": "Video info"
|
||||
},
|
||||
"asset": {
|
||||
"$ref": "#/components/schemas/AssetEntity"
|
||||
},
|
||||
"exifTextSearchableColumn": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"assetId",
|
||||
"description",
|
||||
"exifImageWidth",
|
||||
"exifImageHeight",
|
||||
"fileSizeInByte",
|
||||
"orientation",
|
||||
"dateTimeOriginal",
|
||||
"modifyDate",
|
||||
"latitude",
|
||||
"longitude",
|
||||
"city",
|
||||
"state",
|
||||
"country",
|
||||
"make",
|
||||
"model",
|
||||
"imageName",
|
||||
"lensModel",
|
||||
"fNumber",
|
||||
"focalLength",
|
||||
"iso",
|
||||
"exposureTime",
|
||||
"exifTextSearchableColumn"
|
||||
]
|
||||
},
|
||||
"SmartInfoEntity": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"assetId": {
|
||||
"type": "string"
|
||||
},
|
||||
"tags": {
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"objects": {
|
||||
"nullable": true,
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"asset": {
|
||||
"$ref": "#/components/schemas/AssetEntity"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"assetId",
|
||||
"tags",
|
||||
"objects"
|
||||
]
|
||||
},
|
||||
"UserEntity": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"firstName": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastName": {
|
||||
"type": "string"
|
||||
},
|
||||
"isAdmin": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"salt": {
|
||||
"type": "string"
|
||||
},
|
||||
"oauthId": {
|
||||
"type": "string"
|
||||
},
|
||||
"profileImagePath": {
|
||||
"type": "string"
|
||||
},
|
||||
"shouldChangePassword": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"deletedAt": {
|
||||
"format": "date-time",
|
||||
"type": "string"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"firstName",
|
||||
"lastName",
|
||||
"isAdmin",
|
||||
"email",
|
||||
"oauthId",
|
||||
"profileImagePath",
|
||||
"shouldChangePassword",
|
||||
"createdAt",
|
||||
"tags"
|
||||
]
|
||||
},
|
||||
"TagEntity": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"enum": [
|
||||
"OBJECT",
|
||||
"FACE",
|
||||
"CUSTOM"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"type": "string"
|
||||
},
|
||||
"renameTagId": {
|
||||
"type": "string"
|
||||
},
|
||||
"assets": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/AssetEntity"
|
||||
}
|
||||
},
|
||||
"user": {
|
||||
"$ref": "#/components/schemas/UserEntity"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"type",
|
||||
"name",
|
||||
"userId",
|
||||
"renameTagId",
|
||||
"assets",
|
||||
"user"
|
||||
]
|
||||
},
|
||||
"AssetEntity": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"deviceAssetId": {
|
||||
"type": "string"
|
||||
},
|
||||
"userId": {
|
||||
"type": "string"
|
||||
},
|
||||
"deviceId": {
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"IMAGE",
|
||||
"VIDEO",
|
||||
"AUDIO",
|
||||
"OTHER"
|
||||
]
|
||||
},
|
||||
"originalPath": {
|
||||
"type": "string"
|
||||
},
|
||||
"resizePath": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"webpPath": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"encodedVideoPath": {
|
||||
"type": "string"
|
||||
},
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"modifiedAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"isFavorite": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"mimeType": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"checksum": {
|
||||
"type": "object",
|
||||
"nullable": true
|
||||
},
|
||||
"duration": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"isVisible": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"livePhotoVideoId": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"exifInfo": {
|
||||
"$ref": "#/components/schemas/ExifEntity"
|
||||
},
|
||||
"smartInfo": {
|
||||
"$ref": "#/components/schemas/SmartInfoEntity"
|
||||
},
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/TagEntity"
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"deviceAssetId",
|
||||
"userId",
|
||||
"deviceId",
|
||||
"type",
|
||||
"originalPath",
|
||||
"resizePath",
|
||||
"webpPath",
|
||||
"encodedVideoPath",
|
||||
"createdAt",
|
||||
"modifiedAt",
|
||||
"isFavorite",
|
||||
"mimeType",
|
||||
"duration",
|
||||
"isVisible",
|
||||
"livePhotoVideoId",
|
||||
"tags"
|
||||
]
|
||||
},
|
||||
"UpdateTagDto": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
Reference in New Issue
Block a user