Skip to content

Commit 47baaaf

Browse files
committed
PM-1100 - PR feedback
1 parent 7c485b9 commit 47baaaf

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"@nestjs/platform-express": "^11.0.1",
2727
"@nestjs/swagger": "^11.0.3",
2828
"@prisma/client": "^6.5.0",
29-
"axios": "^1.8.4",
3029
"class-transformer": "^0.5.1",
3130
"class-validator": "^0.14.1",
3231
"cors": "^2.8.5",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/shared/global/trolley.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import crypto from 'crypto';
33
import trolley from 'trolleyhq';
44
import { Injectable } from '@nestjs/common';
55

6-
const { TORLLEY_ACCESS_KEY, TORLLEY_SECRET_KEY, TROLLEY_WIDGET_BASE_URL } =
6+
const { TROLLEY_ACCESS_KEY, TROLLEY_SECRET_KEY, TROLLEY_WIDGET_BASE_URL } =
77
process.env;
88

99
const client = trolley({
10-
key: TORLLEY_ACCESS_KEY as string,
11-
secret: TORLLEY_SECRET_KEY as string,
10+
key: TROLLEY_ACCESS_KEY as string,
11+
secret: TROLLEY_SECRET_KEY as string,
1212
});
1313

1414
@Injectable()
@@ -23,14 +23,14 @@ export class TrolleyService {
2323
* @param recipient - recipient's details
2424
* @returns A string representing the fully constructed and signed URL for the Trolley widget.
2525
*
26-
* @throws This function assumes that `TROLLEY_WIDGET_BASE_URL`, `TORLLEY_ACCESS_KEY`,
27-
* and `TORLLEY_SECRET_KEY` are defined and valid. Ensure these constants are properly set.
26+
* @throws This function assumes that `TROLLEY_WIDGET_BASE_URL`, `TROLLEY_ACCESS_KEY`,
27+
* and `TROLLEY_SECRET_KEY` are defined and valid. Ensure these constants are properly set.
2828
*/
2929
getRecipientPortalUrl(recipient: { email: string; trolleyId: string }) {
3030
const widgetBaseUrl = new url.URL(TROLLEY_WIDGET_BASE_URL as string);
3131
const querystring = new url.URLSearchParams({
3232
ts: `${Math.floor(new Date().getTime() / 1000)}`,
33-
key: TORLLEY_ACCESS_KEY,
33+
key: TROLLEY_ACCESS_KEY,
3434
email: recipient.email,
3535
refid: recipient.trolleyId,
3636
hideEmail: 'false',
@@ -41,7 +41,7 @@ export class TrolleyService {
4141
.toString()
4242
.replace(/\+/g, '%20');
4343

44-
const hmac = crypto.createHmac('sha256', TORLLEY_SECRET_KEY as string);
44+
const hmac = crypto.createHmac('sha256', TROLLEY_SECRET_KEY as string);
4545
hmac.update(querystring);
4646

4747
// Signature is only valid for 30 seconds

src/shared/topcoder/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './member.types'
1+
export * from './member.types';

src/shared/topcoder/members.service.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import axios from 'axios';
21
import { chunk } from 'lodash';
32
import { Injectable } from '@nestjs/common';
43
import { MEMBER_FIELDS } from './member.types';
@@ -23,9 +22,10 @@ export class TopcoderMembersService {
2322
// Split the unique user IDs into chunks of 100 to comply with API request limits
2423
const requests = chunk(uniqUserIds, 30).map((chunk) => {
2524
const requestUrl = `${process.env.TOPCODER_API_BASE_URL}/members?${chunk.map((id) => `userIds[]=${id}`).join('&')}&fields=handle,userId`;
26-
return axios
27-
.get(requestUrl)
28-
.then(({ data }) => data as { handle: string; userId: string });
25+
return fetch(requestUrl).then(
26+
async (response) =>
27+
(await response.json()) as { handle: string; userId: string },
28+
);
2929
});
3030

3131
try {
@@ -57,13 +57,22 @@ export class TopcoderMembersService {
5757
options = {} as { fields: MEMBER_FIELDS[] },
5858
) {
5959
const { fields } = options;
60-
const m2mToken = await this.m2MService.getToken();
60+
61+
let m2mToken: string | undefined;
62+
try {
63+
m2mToken = await this.m2MService.getToken();
64+
} catch (e) {
65+
console.error(
66+
'Failed to fetch m2m token for fetching member details!',
67+
e.message ?? e,
68+
);
69+
}
6170
const requestUrl = `${process.env.TOPCODER_API_BASE_URL}/members/${handle}${fields ? `?fields=${fields.join(',')}` : ''}`;
6271

6372
try {
64-
const response = await axios
65-
.get(requestUrl, { headers: { Authorization: `Bearer ${m2mToken}` } })
66-
.then(({ data }) => data as { [key: string]: string });
73+
const response: { [key: string]: string } = await fetch(requestUrl, {
74+
headers: { Authorization: `Bearer ${m2mToken}` },
75+
}).then((r) => r.json());
6776
return response;
6877
} catch (e) {
6978
console.error(

src/shared/topcoder/topcoder-m2m.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class TopcoderM2MService {
3838
return m2mToken;
3939
} catch (error) {
4040
// eslint-disable-next-line no-console
41-
console.log('Failed fetching TC M2M Token!', error);
41+
console.error('Failed fetching TC M2M Token!', error);
4242
return undefined;
4343
}
4444
}

0 commit comments

Comments
 (0)