#how to keep SRP (single responsiblity pattern) in nestjs

2 messages · Page 1 of 1 (latest)

lilac birch
#

0

I have the below scenerio, I could complete it simply calling each responsible service within other services but this will violate the SRP.

its a post method accessed via /organization. when user send request to this method, I must do the following tasks in the same pattern:

create organization (its a separate module with own repisitory)
create a user (same)
assign user to organization (same)
send email to user (separate module)
How do I handle this in the organization controller as soon as the request is received? I dont want to inject the UserService inside the OrganizationService and so on for the rest of them.

I am a developer with few months of experience in NestJS and this is bothering me.

I have alread done it this way (psudo code):

OrganizationController {
/organization
saveOrganization(body){

const org = this.organizationService.create(body)
const user = this.userService.create(org.id)
const orgUser = this.orgUserService.create(user.id,org.id)
triggerEvent('user.created',{payload})

}}

normal dagger
#

@lilac birch you can use an approach as in your pseudo code