1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

refactro(server): job dto (#3057)

This commit is contained in:
Jason Rasmussen 2023-07-01 00:41:12 -04:00 committed by GitHub
parent 49f1f6cad7
commit 2feac54382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 27 additions and 35 deletions

View File

@ -1,2 +0,0 @@
export * from './job-command.dto';
export * from './job-id.dto';

View File

@ -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;
}

View File

@ -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;
}

View File

@ -1,6 +1,5 @@
export * from './dto';
export * from './job.constants'; export * from './job.constants';
export * from './job.dto';
export * from './job.interface'; export * from './job.interface';
export * from './job.repository'; export * from './job.repository';
export * from './job.service'; export * from './job.service';
export * from './response-dto';

View File

@ -1,5 +1,24 @@
import { ApiProperty } from '@nestjs/swagger'; 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 { export class JobCountsDto {
@ApiProperty({ type: 'integer' }) @ApiProperty({ type: 'integer' })

View File

@ -7,11 +7,13 @@ import {
newJobRepositoryMock, newJobRepositoryMock,
newSystemConfigRepositoryMock, newSystemConfigRepositoryMock,
} from '@test'; } from '@test';
import { IJobRepository, JobCommand, JobHandler, JobItem, JobName, JobService, QueueName } from '.';
import { IAssetRepository } from '../asset'; import { IAssetRepository } from '../asset';
import { ICommunicationRepository } from '../communication'; import { ICommunicationRepository } from '../communication';
import { ISystemConfigRepository } from '../system-config'; import { ISystemConfigRepository } from '../system-config';
import { SystemConfigCore } from '../system-config/system-config.core'; 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 makeMockHandlers = (success: boolean) => {
const mock = jest.fn().mockResolvedValue(success); const mock = jest.fn().mockResolvedValue(success);

View File

@ -4,10 +4,9 @@ import { CommunicationEvent, ICommunicationRepository } from '../communication';
import { assertMachineLearningEnabled } from '../domain.constant'; import { assertMachineLearningEnabled } from '../domain.constant';
import { ISystemConfigRepository } from '../system-config'; import { ISystemConfigRepository } from '../system-config';
import { SystemConfigCore } from '../system-config/system-config.core'; import { SystemConfigCore } from '../system-config/system-config.core';
import { JobCommandDto } from './dto';
import { JobCommand, JobName, QueueName } from './job.constants'; import { JobCommand, JobName, QueueName } from './job.constants';
import { AllJobStatusResponseDto, JobCommandDto, JobStatusDto } from './job.dto';
import { IJobRepository, JobHandler, JobItem } from './job.repository'; import { IJobRepository, JobHandler, JobItem } from './job.repository';
import { AllJobStatusResponseDto, JobStatusDto } from './response-dto';
@Injectable() @Injectable()
export class JobService { export class JobService {

View File

@ -1 +0,0 @@
export * from './all-job-status-response.dto';

View File

@ -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 { Body, Controller, Get, Param, Put } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger'; import { ApiTags } from '@nestjs/swagger';
import { Authenticated } from '../decorators/authenticated.decorator'; import { Authenticated } from '../decorators/authenticated.decorator';
@ -17,7 +17,7 @@ export class JobController {
} }
@Put(':id') @Put(':id')
sendJobCommand(@Param() { id }: JobIdDto, @Body() dto: JobCommandDto): Promise<JobStatusDto> { sendJobCommand(@Param() { id }: JobIdParamDto, @Body() dto: JobCommandDto): Promise<JobStatusDto> {
return this.service.handleCommand(id, dto); return this.service.handleCommand(id, dto);
} }
} }