Skip to content

Commit

Permalink
minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
annarhughes committed May 28, 2024
1 parent d447f80 commit f812039
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 36 deletions.
60 changes: 30 additions & 30 deletions src/api/crisp/crisp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ const headers = {

const logger = new Logger('UserService');

export const getCrispPeopleData = async (email: string): Promise<AxiosResponse<CrispResponse>> => {
return await apiCall({
url: `${baseUrl}/people/data/${email}`,
type: 'get',
headers,
});
};

export const addCrispProfile = async (
export const createMailchimpProfile = async (
newPeopleProfile: NewPeopleProfile,
): Promise<AxiosResponse<NewPeopleProfileResponse>> => {
try {
Expand All @@ -46,22 +38,22 @@ export const addCrispProfile = async (
}
};

export const updateCrispProfileData = async (
peopleData: PeopleData,
export const getCrispProfile = async (
email: string,
): Promise<AxiosResponse<CrispResponse>> => {
try {
return await apiCall({
url: `${baseUrl}/people/data/${email}`,
type: 'patch',
data: { data: peopleData },
headers,
});
} catch (error) {
logger.error(`Could not update crisp profile for user: ${email}`);
): Promise<AxiosResponse<CrispProfileResponse>> => {
return await apiCall({
url: `${baseUrl}/people/profile/${email}`,
type: 'get',
headers,
});
};

throw error;
}
export const getCrispPeopleData = async (email: string): Promise<AxiosResponse<CrispResponse>> => {
return await apiCall({
url: `${baseUrl}/people/data/${email}`,
type: 'get',
headers,
});
};

export const updateCrispProfile = async (
Expand All @@ -76,14 +68,22 @@ export const updateCrispProfile = async (
});
};

export const getCrispProfile = async (
export const updateCrispProfileData = async (
peopleData: PeopleData,
email: string,
): Promise<AxiosResponse<CrispProfileResponse>> => {
return await apiCall({
url: `${baseUrl}/people/profile/${email}`,
type: 'get',
headers,
});
): Promise<AxiosResponse<CrispResponse>> => {
try {
return await apiCall({
url: `${baseUrl}/people/data/${email}`,
type: 'patch',
data: { data: peopleData },
headers,
});
} catch (error) {
logger.error(`Could not update crisp profile for user: ${email}`);

throw error;
}
};

export const deleteCrispProfile = async (email: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/mailchimp/mailchimp-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function ping() {
console.log(response);
}

export async function createContact(user: UserEntity) {
export async function createMailchimpProfile(user: UserEntity) {
const response = await mailchimp.lists.addListMember(mailchimpAudienceId, {
email_address: user.email,
status: 'subscribed',
Expand Down
6 changes: 3 additions & 3 deletions src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { HttpException, HttpStatus } from '@nestjs/common';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { addCrispProfile } from 'src/api/crisp/crisp-api';
import { createMailchimpProfile } from 'src/api/crisp/crisp-api';
import { PartnerAccessEntity } from 'src/entities/partner-access.entity';
import { PartnerEntity } from 'src/entities/partner.entity';
import { PartnerAccessCodeStatusEnum } from 'src/utils/constants';
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('UserService', () => {
expect(user.partnerAdmin).toBeNull();
expect(user.partnerAccesses).toBeNull();
expect(repoSaveSpy).toHaveBeenCalledWith(createUserRepositoryDto);
expect(addCrispProfile).toHaveBeenCalledWith({
expect(createMailchimpProfile).toHaveBeenCalledWith({
email: user.user.email,
person: { nickname: 'name' },
segments: ['public'],
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('UserService', () => {
{ ...partnerAccessData, therapySessions: therapySession },
]);

expect(addCrispProfile).toHaveBeenCalledWith({
expect(createMailchimpProfile).toHaveBeenCalledWith({
email: user.user.email,
person: { nickname: 'name' },
segments: ['bumble'],
Expand Down
4 changes: 2 additions & 2 deletions src/utils/profileData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addCrispProfile, updateCrispProfileData } from 'src/api/crisp/crisp-api';
import { createMailchimpProfile, updateCrispProfileData } from 'src/api/crisp/crisp-api';
import { CourseUserEntity } from 'src/entities/course-user.entity';
import { PartnerAccessEntity } from 'src/entities/partner-access.entity';
import { PartnerEntity } from 'src/entities/partner.entity';
Expand All @@ -17,7 +17,7 @@ export const createServicesProfiles = async (
partner: PartnerEntity,
partnerAccess: PartnerAccessEntity,
) => {
await addCrispProfile({
await createMailchimpProfile({
email: user.email,
person: { nickname: user.name },
segments: [partner?.name.toLowerCase() || 'public'],
Expand Down

0 comments on commit f812039

Please sign in to comment.