-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathonboard-user.usecase.ts
More file actions
62 lines (57 loc) · 1.97 KB
/
onboard-user.usecase.ts
File metadata and controls
62 lines (57 loc) · 1.97 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Injectable } from '@nestjs/common';
import { UserRepository } from '@impler/dal';
import { PaymentAPIService } from '@impler/services';
import { LEAD_SIGNUP_USING } from '@shared/constants';
import { OnboardUserCommand } from './onboard-user.command';
import { LeadService } from '@shared/services/lead.service';
import { captureException } from '@shared/helpers/common.helper';
import { CreateProject, CreateProjectCommand } from 'app/project/usecases';
@Injectable()
export class OnboardUser {
constructor(
private leadService: LeadService,
private createProject: CreateProject,
private userRepository: UserRepository,
private paymentAPIService: PaymentAPIService
) {}
async execute(command: OnboardUserCommand) {
const createdProject = await this.createProject.execute(
CreateProjectCommand.create({
_userId: command._userId,
name: command.projectName,
onboarding: true,
})
);
await this.userRepository.update(
{ _id: command._userId },
{
role: command.role,
companySize: command.companySize,
source: command.source,
}
);
const updatedUser = await this.userRepository.findOne({ _id: command._userId });
if (updatedUser) {
try {
const userData = {
name: updatedUser.firstName + ' ' + updatedUser.lastName,
email: updatedUser.email,
externalId: updatedUser.email,
};
await this.paymentAPIService.createUser(userData);
await this.leadService.createLead({
'First Name': updatedUser.firstName,
'Last Name': updatedUser.lastName,
'Lead Email': updatedUser.email,
'CRM Source': updatedUser.source,
Role: updatedUser.role,
'Signup Method': updatedUser.signupMethod as LEAD_SIGNUP_USING,
'Est. Employees': updatedUser.companySize,
});
} catch (error) {
captureException(error);
}
}
return createdProject;
}
}