diff --git a/src/entities/user/input.dto.ts b/src/entities/user/input.dto.ts new file mode 100644 index 0000000..eb26ee3 --- /dev/null +++ b/src/entities/user/input.dto.ts @@ -0,0 +1,34 @@ +import { Field, InputType, Int, PartialType } from "@nestjs/graphql"; + +@InputType() +export class CreateUserInputType { + @Field(() => Int, { nullable: true }) + identification_number: number; + + @Field() + email: string; + + @Field() + fname: string; + + @Field() + lname: string; + + @Field({ nullable: true }) + mname: string; + + @Field({ nullable: true }) + age: number; + + @Field(() => String, { nullable: true }) + phone: string; + + @Field({ nullable: true }) + is_active: boolean; +} + +@InputType() +export class UpdateUserInputType extends PartialType(CreateUserInputType) { + @Field(() => Int) + id: number; +} \ No newline at end of file diff --git a/src/entities/user/user.resolver.ts b/src/entities/user/user.resolver.ts index c3d83a8..414698e 100644 --- a/src/entities/user/user.resolver.ts +++ b/src/entities/user/user.resolver.ts @@ -1,4 +1,4 @@ -import { Query, ResolveField, Resolver } from '@nestjs/graphql'; +import { Args, Mutation, Query, ResolveField, Resolver } from '@nestjs/graphql'; import { InjectRepository } from '@nestjs/typeorm'; import { Brackets, In, Repository } from 'typeorm'; import { Filter, GraphqlFilter, GraphqlLoader, GraphqlSorting, Loader, LoaderData, SelectedFields, SelectedFieldsResult, SelectedUnionTypes, SortArgs, Sorting } from '../../../lib'; @@ -6,6 +6,7 @@ import { StoryModel } from '../story/story.entity'; import { TaskObjectType } from '../task/task.dto'; import { Task } from '../task/task.entity'; import { TaskFilterInputType, UserFilterInputType } from './fillter.dto'; +import { UpdateUserInputType } from './input.dto'; import { TaskSortingInputType, UserSortingInputType } from './sorting.dto'; import { SearchTasksUnion, UserAggregationType, UserObjectType } from './user.dto'; import { User } from './user.entity'; @@ -109,4 +110,15 @@ export class UserResolver { return qb.getRawOne(); } + + @Mutation(() => UserObjectType) + async updateUser( + @Args({name: 'user', type: () => UpdateUserInputType}) user: UpdateUserInputType + ) { + await this.userRepository.update({ + id: user.id + }, user) + + return this.userRepository.findOne({where: {id: user.id}}) + } } \ No newline at end of file