-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
create-user.graphql-resolver.ts
26 lines (22 loc) · 985 Bytes
/
create-user.graphql-resolver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { CommandBus } from '@nestjs/cqrs';
import { CreateUserCommand } from '../create-user.command';
import { CreateUserGqlRequestDto } from './dtos/create-user.gql-request.dto';
import { IdGqlResponse } from './dtos/id.gql-response.dto';
import { AggregateID } from '@src/libs/ddd';
import { UserAlreadyExistsError } from '@src/modules/user/domain/user.errors';
import { Result } from 'oxide.ts';
// If you are Using GraphQL you'll need a Resolver instead of a Controller
@Resolver()
export class CreateUserGraphqlResolver {
constructor(private readonly commandBus: CommandBus) {}
@Mutation(() => IdGqlResponse)
async create(
@Args('input') input: CreateUserGqlRequestDto,
): Promise<IdGqlResponse> {
const command = new CreateUserCommand(input);
const id: Result<AggregateID, UserAlreadyExistsError> =
await this.commandBus.execute(command);
return new IdGqlResponse(id.unwrap());
}
}