Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 21e9acc

Browse files
author
dengjun
committed
fix: issue 131
1 parent b049aa4 commit 21e9acc

File tree

6 files changed

+82
-3
lines changed

6 files changed

+82
-3
lines changed

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
COMMUNITY_APP: "https://community-app.topcoder-dev.com",
1313
PLATFORM_WEBSITE_URL: "https://platform.topcoder-dev.com",
1414
},
15-
RECRUIT_API: "https://www.topcoder-dev.com",
15+
RECRUIT_API: process.env.RECRUIT_API || "https://www.topcoder-dev.com",
1616
// the server api base path
1717
API_BASE_PATH: process.env.API_BASE_PATH || "/earn-app/api/my-gigs",
1818
// the log level, default is 'debug'

config/development.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports = {
1111
COMMUNITY_APP: "https://community-app.topcoder-dev.com",
1212
PLATFORM_WEBSITE_URL: "https://platform.topcoder-dev.com",
1313
},
14-
RECRUIT_API: "https://www.topcoder-dev.com",
14+
RECRUIT_API: process.env.RECRUIT_API || "https://www.topcoder-dev.com",
1515
};

config/production.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports = {
1111
COMMUNITY_APP: "https://community-app.topcoder.com",
1212
PLATFORM_WEBSITE_URL: "https://platform.topcoder.com",
1313
},
14-
RECRUIT_API: "https://www.topcoder.com",
14+
RECRUIT_API: process.env.RECRUIT_API || "https://www.topcoder.com",
1515
};

src/api/common/helper.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,26 @@ async function getMember(handle, query) {
335335
return res.body;
336336
}
337337

338+
/**
339+
* Get member traits info
340+
* @param {string} handle the handle of the user
341+
* @param {string} query the query criteria
342+
* @returns the object of member traitsdetails
343+
*/
344+
async function getMemberTraits(handle, query) {
345+
const token = await getM2MToken();
346+
const url = `${config.API.V5}/members/${handle}/traits`;
347+
const res = await request
348+
.get(url)
349+
.query(query)
350+
.set("Authorization", `Bearer ${token}`)
351+
.set("Accept", "application/json");
352+
localLogger.debug({
353+
context: "getMemberTraits",
354+
message: `response body: ${JSON.stringify(res.body)}`,
355+
});
356+
return res.body;
357+
}
338358
/**
339359
* Update member details
340360
* @param {string} handle the handle of the user
@@ -357,6 +377,28 @@ async function updateMember(currentUser, data) {
357377
return res.body;
358378
}
359379

380+
/**
381+
* Update member traits
382+
* @param {string} handle the handle of the user
383+
* @param {object} data the data to be updated
384+
* @return {object} the object of updated member details
385+
*/
386+
async function updateMemberTraits(currentUser, data) {
387+
const token = currentUser.jwtToken;
388+
const url = `${config.API.V5}/members/${currentUser.handle}/traits`;
389+
const res = await request
390+
.put(url)
391+
.set("Authorization", token)
392+
.set("Content-Type", "application/json")
393+
.set("Accept", "application/json")
394+
.send(data);
395+
localLogger.debug({
396+
context: "updateMemberTraits",
397+
message: `response body: ${JSON.stringify(res.body)}`,
398+
});
399+
return res.body;
400+
}
401+
360402
/**
361403
* Get Recruit CRM profile details
362404
* @param {object} currentUser the user who performs the operation
@@ -412,7 +454,9 @@ module.exports = {
412454
getJobCandidates,
413455
getJobs,
414456
getMember,
457+
getMemberTraits,
415458
updateMember,
459+
updateMemberTraits,
416460
getRCRMProfile,
417461
updateRCRMProfile,
418462
};

src/api/services/ProfileService.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,65 @@ async function updateMyProfile(currentUser, files, data) {
7575
"fields=addresses,competitionCountryCode,homeCountryCode"
7676
);
7777
const update = {};
78+
let shouldUpdateTrait = false;
7879
// update member data if city is different from existing one
7980
if (_.get(member, "addresses[0].city") !== data.city) {
8081
update.addresses = _.cloneDeep(member.addresses);
8182
if (!_.isEmpty(update.addresses)) {
8283
update.addresses[0].city = data.city;
8384
delete update.addresses[0].createdAt;
8485
delete update.addresses[0].updatedAt;
86+
update.addresses[0].streetAddr1 = update.addresses[0].streetAddr1
87+
? update.addresses[0].streetAddr1
88+
: " ";
89+
update.addresses[0].type = update.addresses[0].type
90+
? update.addresses[0].type
91+
: "HOME";
92+
update.addresses[0].stateCode = update.addresses[0].stateCode
93+
? update.addresses[0].stateCode
94+
: "000";
95+
update.addresses[0].zip = update.addresses[0].zip
96+
? update.addresses[0].zip
97+
: "000";
8598
} else {
8699
update.addresses = [
87100
{
88101
city: data.city,
102+
type: "HOME",
103+
stateCode: "000",
104+
zip: "000",
89105
},
90106
];
91107
}
92108
}
93109
// update member data if competitionCountryCode is different from existing one
94110
if (_.get(member, "competitionCountryCode") !== data.country) {
95111
update.competitionCountryCode = data.country;
112+
shouldUpdateTrait = true;
96113
}
97114
if (_.get(member, "homeCountryCode") !== data.country) {
98115
update.homeCountryCode = data.country;
116+
shouldUpdateTrait = true;
99117
}
100118
// avoid unnecessary api calls
101119
if (!_.isEmpty(update)) {
102120
await helper.updateMember(currentUser, update);
103121
}
122+
if (shouldUpdateTrait) {
123+
const memberTraits = await helper.getMemberTraits(
124+
currentUser.handle,
125+
`traitIds=basic_info`
126+
);
127+
if (memberTraits && memberTraits.length) {
128+
memberTraits[0]["traits"].data[0].country = data.countryName;
129+
delete memberTraits[0].createdAt;
130+
delete memberTraits[0].createdBy;
131+
delete memberTraits[0].updatedAt;
132+
delete memberTraits[0].updatedBy;
133+
delete memberTraits[0].userId;
134+
await helper.updateMemberTraits(currentUser, memberTraits);
135+
}
136+
}
104137
await helper.updateRCRMProfile(currentUser, files.resume, {
105138
phone: data.phone,
106139
availability: data.availability,
@@ -119,6 +152,7 @@ updateMyProfile.schema = Joi.object()
119152
.keys({
120153
city: Joi.string().required(),
121154
country: Joi.string().required(),
155+
countryName: Joi.string().required(),
122156
phone: Joi.string().required(),
123157
availability: Joi.boolean().required(),
124158
})

src/services/myGigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ async function updateProfile(profile) {
129129
const payload = {
130130
city: profile.city,
131131
country: profile.countryCode,
132+
countryName: profile.country,
132133
phone: profile.phone,
133134
availability: profile.status === GIG_STATUS.AVAILABLE ? true : false,
134135
resume: profile.file,

0 commit comments

Comments
 (0)