feat_the_progress_of_tasks #5
@@ -53,8 +53,22 @@ export class BaseDbService<Entity extends AppBaseEntity> extends TypeormHelper {
 | 
			
		||||
  async isDuplicateEntityForUpdate<Dto extends Entity>(
 | 
			
		||||
    id: string,
 | 
			
		||||
    dto: Partial<Dto>,
 | 
			
		||||
    extendsFields?: Array<keyof Dto & string>,
 | 
			
		||||
  ): Promise<false | never>;
 | 
			
		||||
  async isDuplicateEntityForUpdate<Dto extends Entity>(
 | 
			
		||||
    old: Entity,
 | 
			
		||||
    dto: Partial<Dto>,
 | 
			
		||||
    extendsFields?: Array<keyof Dto & string>,
 | 
			
		||||
  ): Promise<false | never>;
 | 
			
		||||
  async isDuplicateEntityForUpdate<Dto extends Entity>(
 | 
			
		||||
    id: string | Entity,
 | 
			
		||||
    dto: Partial<Dto>,
 | 
			
		||||
    extendsFields: Array<keyof Dto & string> = [],
 | 
			
		||||
  ): Promise<false | never> {
 | 
			
		||||
    if (typeof id !== 'string') {
 | 
			
		||||
      dto = Object.assign({}, id, dto);
 | 
			
		||||
      id = id.id;
 | 
			
		||||
    }
 | 
			
		||||
    const qb = this.repository.createQueryBuilder('entity');
 | 
			
		||||
    const compareFields = this.getCompareFields(dto, [
 | 
			
		||||
      ...this.uniqueFields,
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,10 @@
 | 
			
		||||
import { InputType, ObjectType } from '@nestjs/graphql';
 | 
			
		||||
import { Field, InputType, Int, ObjectType } from '@nestjs/graphql';
 | 
			
		||||
import { WorkUnit } from './work-unit.model';
 | 
			
		||||
 | 
			
		||||
@InputType('WorkUnitMetadataInput')
 | 
			
		||||
@ObjectType()
 | 
			
		||||
export class WorkUnitMetadata {
 | 
			
		||||
  @Field(() => Int)
 | 
			
		||||
  version = 1;
 | 
			
		||||
  units: WorkUnit[];
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,9 @@
 | 
			
		||||
import { InputType } from '@nestjs/graphql';
 | 
			
		||||
import { InputType, OmitType } from '@nestjs/graphql';
 | 
			
		||||
import { CreatePipelineInput } from './create-pipeline.input';
 | 
			
		||||
 | 
			
		||||
@InputType()
 | 
			
		||||
export class UpdatePipelineInput extends CreatePipelineInput {
 | 
			
		||||
export class UpdatePipelineInput extends OmitType(CreatePipelineInput, [
 | 
			
		||||
  'projectId',
 | 
			
		||||
]) {
 | 
			
		||||
  id: string;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,14 +21,14 @@ export class PipelinesResolver {
 | 
			
		||||
  @Mutation(() => Pipeline)
 | 
			
		||||
  async createPipeline(
 | 
			
		||||
    @Args('pipeline', { type: () => CreatePipelineInput })
 | 
			
		||||
    dto: UpdatePipelineInput,
 | 
			
		||||
    dto: CreatePipelineInput,
 | 
			
		||||
  ) {
 | 
			
		||||
    return await this.service.create(dto);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Mutation(() => Pipeline)
 | 
			
		||||
  async updatePipeline(
 | 
			
		||||
    @Args('Pipeline', { type: () => UpdatePipelineInput })
 | 
			
		||||
    @Args('pipeline', { type: () => UpdatePipelineInput })
 | 
			
		||||
    dto: UpdatePipelineInput,
 | 
			
		||||
  ) {
 | 
			
		||||
    const tmp = await this.service.update(dto);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ import {
 | 
			
		||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
 | 
			
		||||
import { Commit } from '../repos/dtos/log-list.model';
 | 
			
		||||
import { getAppInstanceRouteKey } from '../commons/utils/rabbit-mq';
 | 
			
		||||
import { ApplicationException } from '../commons/exceptions/application.exception';
 | 
			
		||||
import { plainToClass } from 'class-transformer';
 | 
			
		||||
 | 
			
		||||
@Injectable()
 | 
			
		||||
export class PipelinesService extends BaseDbService<Pipeline> {
 | 
			
		||||
@@ -42,8 +44,8 @@ export class PipelinesService extends BaseDbService<Pipeline> {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  async update(dto: UpdatePipelineInput) {
 | 
			
		||||
    await this.isDuplicateEntityForUpdate(dto.id, dto);
 | 
			
		||||
    const old = await this.findOne(dto.id);
 | 
			
		||||
    await this.isDuplicateEntityForUpdate(old, dto);
 | 
			
		||||
    return await this.repository.save(this.repository.merge(old, dto));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -60,17 +62,17 @@ export class PipelinesService extends BaseDbService<Pipeline> {
 | 
			
		||||
  }
 | 
			
		||||
  async listCommits(pipeline: Pipeline) {
 | 
			
		||||
    return await this.amqpConnection
 | 
			
		||||
      .request<Commit[]>({
 | 
			
		||||
      .request<[Error, Commit[]]>({
 | 
			
		||||
        exchange: EXCHANGE_REPO,
 | 
			
		||||
        routingKey: ROUTE_LIST_COMMITS,
 | 
			
		||||
        payload: pipeline,
 | 
			
		||||
        timeout: 10_000,
 | 
			
		||||
        timeout: 30_000,
 | 
			
		||||
      })
 | 
			
		||||
      .then((list) =>
 | 
			
		||||
        list.map((item) => {
 | 
			
		||||
          item.date = new Date(item.date);
 | 
			
		||||
          return item;
 | 
			
		||||
        }),
 | 
			
		||||
      );
 | 
			
		||||
      .then(([error, list]) => {
 | 
			
		||||
        if (error) {
 | 
			
		||||
          throw new ApplicationException(error);
 | 
			
		||||
        }
 | 
			
		||||
        return plainToClass(Commit, list);
 | 
			
		||||
      });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user