Skip to content

Commit

Permalink
Added simple mutation for better testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrinalin4ik committed Feb 16, 2023
1 parent 428efa9 commit bd85900
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/entities/user/input.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
14 changes: 13 additions & 1 deletion src/entities/user/user.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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';
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';
Expand Down Expand Up @@ -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}})
}
}

0 comments on commit bd85900

Please sign in to comment.