-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
create-user.cli.controller.ts
40 lines (36 loc) · 1.01 KB
/
create-user.cli.controller.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Inject, Logger } from '@nestjs/common';
import { Command, Console } from 'nestjs-console';
import { CommandBus } from '@nestjs/cqrs';
import { CreateUserCommand } from './create-user.command';
import { LoggerPort } from '@libs/ports/logger.port';
// Allows creating a user using CLI (Command Line Interface)
@Console({
command: 'new',
description: 'A command to create a user',
})
export class CreateUserCliController {
constructor(
private readonly commandBus: CommandBus,
@Inject(Logger)
private readonly logger: LoggerPort,
) {}
@Command({
command: 'user <email> <country> <postalCode> <street>',
description: 'Create a user',
})
async createUser(
email: string,
country: string,
postalCode: string,
street: string,
): Promise<void> {
const command = new CreateUserCommand({
email,
country,
postalCode,
street,
});
const result = await this.commandBus.execute(command);
this.logger.log('User created:', result.unwrap());
}
}