fix(projects): 修复若干问题。

This commit is contained in:
Ivan Li 2021-02-17 14:32:44 +08:00
parent db6b699663
commit c2c5340278
3 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,11 @@
import { InputType } from '@nestjs/graphql'; import { InputType } from '@nestjs/graphql';
import { IsString, IsUrl, MaxLength, MinLength } from 'class-validator'; import {
IsOptional,
IsString,
IsUrl,
MaxLength,
MinLength,
} from 'class-validator';
@InputType({ isAbstract: true }) @InputType({ isAbstract: true })
export class CreateProjectInput { export class CreateProjectInput {
@ -18,6 +24,7 @@ export class CreateProjectInput {
sshUrl: string; sshUrl: string;
@IsUrl() @IsUrl()
@IsOptional()
@MaxLength(256) @MaxLength(256)
webUrl?: string; webUrl?: string;

View File

@ -25,13 +25,15 @@ export class ProjectsResolver {
return await this.service.create(dto); return await this.service.create(dto);
} }
@Mutation(() => Boolean) @Mutation(() => Project)
async modifyProject( async modifyProject(
@Args('id', { type: () => String }) id: string, @Args('id', { type: () => String }) id: string,
@Args('project', { type: () => UpdateProjectInput }) @Args('project', { type: () => UpdateProjectInput })
dto: UpdateProjectInput, dto: UpdateProjectInput,
) { ) {
return await this.service.update(id, dto); const tmp = await this.service.update(id, dto);
console.log(tmp);
return tmp;
} }
@Mutation(() => Number) @Mutation(() => Number)

View File

@ -26,7 +26,8 @@ export class ProjectsService extends BaseDbService<Project> {
async update(id: string, dto: CreateProjectInput) { async update(id: string, dto: CreateProjectInput) {
await this.isDuplicateEntityForUpdate(id, dto); await this.isDuplicateEntityForUpdate(id, dto);
await this.repository.update({ id }, dto); const old = await this.findOne(id);
return await this.repository.save(this.repository.merge(old, dto));
} }
async remove(id: string) { async remove(id: string) {