From 2feac543824b7ff58f6629b7b8c2277b5e5f29a3 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Sat, 1 Jul 2023 00:41:12 -0400 Subject: [PATCH] refactro(server): job dto (#3057) --- server/src/domain/job/dto/index.ts | 2 -- server/src/domain/job/dto/job-command.dto.ts | 14 ------------- server/src/domain/job/dto/job-id.dto.ts | 10 --------- server/src/domain/job/index.ts | 3 +-- ...-job-status-response.dto.ts => job.dto.ts} | 21 ++++++++++++++++++- server/src/domain/job/job.service.spec.ts | 4 +++- server/src/domain/job/job.service.ts | 3 +-- server/src/domain/job/response-dto/index.ts | 1 - .../src/immich/controllers/job.controller.ts | 4 ++-- 9 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 server/src/domain/job/dto/index.ts delete mode 100644 server/src/domain/job/dto/job-command.dto.ts delete mode 100644 server/src/domain/job/dto/job-id.dto.ts rename server/src/domain/job/{response-dto/all-job-status-response.dto.ts => job.dto.ts} (75%) delete mode 100644 server/src/domain/job/response-dto/index.ts diff --git a/server/src/domain/job/dto/index.ts b/server/src/domain/job/dto/index.ts deleted file mode 100644 index abb9f96817..0000000000 --- a/server/src/domain/job/dto/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './job-command.dto'; -export * from './job-id.dto'; diff --git a/server/src/domain/job/dto/job-command.dto.ts b/server/src/domain/job/dto/job-command.dto.ts deleted file mode 100644 index 94ddbb9745..0000000000 --- a/server/src/domain/job/dto/job-command.dto.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { IsBoolean, IsEnum, IsNotEmpty, IsOptional } from 'class-validator'; -import { JobCommand } from '../job.constants'; - -export class JobCommandDto { - @IsNotEmpty() - @IsEnum(JobCommand) - @ApiProperty({ type: 'string', enum: JobCommand, enumName: 'JobCommand' }) - command!: JobCommand; - - @IsOptional() - @IsBoolean() - force!: boolean; -} diff --git a/server/src/domain/job/dto/job-id.dto.ts b/server/src/domain/job/dto/job-id.dto.ts deleted file mode 100644 index 3fd001406b..0000000000 --- a/server/src/domain/job/dto/job-id.dto.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { ApiProperty } from '@nestjs/swagger'; -import { IsEnum, IsNotEmpty } from 'class-validator'; -import { QueueName } from '../job.constants'; - -export class JobIdDto { - @IsNotEmpty() - @IsEnum(QueueName) - @ApiProperty({ type: String, enum: QueueName, enumName: 'JobName' }) - id!: QueueName; -} diff --git a/server/src/domain/job/index.ts b/server/src/domain/job/index.ts index 755d7994a7..f125b969af 100644 --- a/server/src/domain/job/index.ts +++ b/server/src/domain/job/index.ts @@ -1,6 +1,5 @@ -export * from './dto'; export * from './job.constants'; +export * from './job.dto'; export * from './job.interface'; export * from './job.repository'; export * from './job.service'; -export * from './response-dto'; diff --git a/server/src/domain/job/response-dto/all-job-status-response.dto.ts b/server/src/domain/job/job.dto.ts similarity index 75% rename from server/src/domain/job/response-dto/all-job-status-response.dto.ts rename to server/src/domain/job/job.dto.ts index 6003c15c67..1c59409567 100644 --- a/server/src/domain/job/response-dto/all-job-status-response.dto.ts +++ b/server/src/domain/job/job.dto.ts @@ -1,5 +1,24 @@ import { ApiProperty } from '@nestjs/swagger'; -import { QueueName } from '../job.constants'; +import { IsBoolean, IsEnum, IsNotEmpty, IsOptional } from 'class-validator'; +import { JobCommand, QueueName } from './job.constants'; + +export class JobIdParamDto { + @IsNotEmpty() + @IsEnum(QueueName) + @ApiProperty({ type: String, enum: QueueName, enumName: 'JobName' }) + id!: QueueName; +} + +export class JobCommandDto { + @IsNotEmpty() + @IsEnum(JobCommand) + @ApiProperty({ type: 'string', enum: JobCommand, enumName: 'JobCommand' }) + command!: JobCommand; + + @IsOptional() + @IsBoolean() + force!: boolean; +} export class JobCountsDto { @ApiProperty({ type: 'integer' }) diff --git a/server/src/domain/job/job.service.spec.ts b/server/src/domain/job/job.service.spec.ts index 7da2f8e670..e9a8f641a8 100644 --- a/server/src/domain/job/job.service.spec.ts +++ b/server/src/domain/job/job.service.spec.ts @@ -7,11 +7,13 @@ import { newJobRepositoryMock, newSystemConfigRepositoryMock, } from '@test'; -import { IJobRepository, JobCommand, JobHandler, JobItem, JobName, JobService, QueueName } from '.'; import { IAssetRepository } from '../asset'; import { ICommunicationRepository } from '../communication'; import { ISystemConfigRepository } from '../system-config'; import { SystemConfigCore } from '../system-config/system-config.core'; +import { JobCommand, JobName, QueueName } from './job.constants'; +import { IJobRepository, JobHandler, JobItem } from './job.repository'; +import { JobService } from './job.service'; const makeMockHandlers = (success: boolean) => { const mock = jest.fn().mockResolvedValue(success); diff --git a/server/src/domain/job/job.service.ts b/server/src/domain/job/job.service.ts index edc6aacd0e..8bfdd6c6b0 100644 --- a/server/src/domain/job/job.service.ts +++ b/server/src/domain/job/job.service.ts @@ -4,10 +4,9 @@ import { CommunicationEvent, ICommunicationRepository } from '../communication'; import { assertMachineLearningEnabled } from '../domain.constant'; import { ISystemConfigRepository } from '../system-config'; import { SystemConfigCore } from '../system-config/system-config.core'; -import { JobCommandDto } from './dto'; import { JobCommand, JobName, QueueName } from './job.constants'; +import { AllJobStatusResponseDto, JobCommandDto, JobStatusDto } from './job.dto'; import { IJobRepository, JobHandler, JobItem } from './job.repository'; -import { AllJobStatusResponseDto, JobStatusDto } from './response-dto'; @Injectable() export class JobService { diff --git a/server/src/domain/job/response-dto/index.ts b/server/src/domain/job/response-dto/index.ts deleted file mode 100644 index 7229910ae5..0000000000 --- a/server/src/domain/job/response-dto/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './all-job-status-response.dto'; diff --git a/server/src/immich/controllers/job.controller.ts b/server/src/immich/controllers/job.controller.ts index 7f26f5834f..b4e3ebed3a 100644 --- a/server/src/immich/controllers/job.controller.ts +++ b/server/src/immich/controllers/job.controller.ts @@ -1,4 +1,4 @@ -import { AllJobStatusResponseDto, JobCommandDto, JobIdDto, JobService, JobStatusDto } from '@app/domain'; +import { AllJobStatusResponseDto, JobCommandDto, JobIdParamDto, JobService, JobStatusDto } from '@app/domain'; import { Body, Controller, Get, Param, Put } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { Authenticated } from '../decorators/authenticated.decorator'; @@ -17,7 +17,7 @@ export class JobController { } @Put(':id') - sendJobCommand(@Param() { id }: JobIdDto, @Body() dto: JobCommandDto): Promise { + sendJobCommand(@Param() { id }: JobIdParamDto, @Body() dto: JobCommandDto): Promise { return this.service.handleCommand(id, dto); } }