Entry module commands
To make the business logic around changes to entry models easier to extend, we will first need to extract out the methods in the module’s services that update the database as individual commands. Let’s start with converting the blog entry create
method to a command in Nest.js CQRS fashion.
export
class
CreateEntryCommand
implements
ICommand
{
constructor
(
public
readonly
title
:string
,
public
readonly
content
:string
,
public
readonly
userId
:number
)
{}
}
Our command is a simple object that implemented the ICommand
interface. The ICommand
interface is used internally by Nest.js to indicate an object is a command. This file is typically created in a sub-directory of our module with a pattern similar to commands/impl/
. Now that we have one example done, let’s finish up the remaining commands for the comment module.
export
class
UpdateEntryCommand
implements
ICommand
{
constructor
(
public
readonly
id...