feat(projects): normalization name.

This commit is contained in:
Ivan Li
2021-05-04 21:05:20 +08:00
parent 246c0bd8f8
commit 86c8bce9ea
10 changed files with 15310 additions and 48 deletions

View File

@@ -21,7 +21,10 @@ export class CreateProjectInput {
comment: string;
@Matches(
/^(?:ssh:\/\/)?(?:[\w\d-_]+@)(?:[\w\d-_]+\.)*\w{2,10}(?::\d{1,5})?(?:\/[\w\d-_.]+)*/,
/^(?:ssh:\/\/)?(?:[\w\d-_]+@)?(?:[\w\d-_]+\.)*\w{2,10}(?::\d{1,5})?(?:\/[\w\d-_.]+)*/,
{
message: 'wrong ssh url',
},
)
@MaxLength(256)
sshUrl: string;

View File

@@ -1,5 +1,9 @@
import { InputType } from '@nestjs/graphql';
import { IsUUID } from 'class-validator';
import { CreateProjectInput } from './create-project.input';
@InputType()
export class UpdateProjectInput extends CreateProjectInput {}
export class UpdateProjectInput extends CreateProjectInput {
@IsUUID()
id: string;
}

View File

@@ -8,12 +8,12 @@ import { ProjectsService } from './projects.service';
export class ProjectsResolver {
constructor(private readonly service: ProjectsService) {}
@Query(() => [Project])
async findProjects() {
async projects() {
return await this.service.list();
}
@Query(() => Project)
async findProject(@Args('id', { type: () => String }) id: string) {
async project(@Args('id', { type: () => String }) id: string) {
return await this.service.findOne(id);
}
@@ -26,18 +26,17 @@ export class ProjectsResolver {
}
@Mutation(() => Project)
async modifyProject(
@Args('id', { type: () => String }) id: string,
async updateProject(
@Args('project', { type: () => UpdateProjectInput })
dto: UpdateProjectInput,
) {
const tmp = await this.service.update(id, dto);
const tmp = await this.service.update(dto);
console.log(tmp);
return tmp;
}
@Mutation(() => Number)
async deleteProject(@Args('id', { type: () => String }) id: string) {
async removeProject(@Args('id', { type: () => String }) id: string) {
return await this.service.remove(id);
}
}

View File

@@ -25,9 +25,9 @@ export class ProjectsService extends BaseDbService<Project> {
return await this.repository.save(this.repository.create(dto));
}
async update(id: string, dto: UpdateProjectInput) {
await this.isDuplicateEntityForUpdate(id, dto);
const old = await this.findOne(id);
async update(dto: UpdateProjectInput) {
await this.isDuplicateEntityForUpdate(dto.id, dto);
const old = await this.findOne(dto.id);
return await this.repository.save(this.repository.merge(old, dto));
}