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

Version 1.1 #71

Merged
merged 7 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split UserMapping.
  • Loading branch information
afrisalyp committed Jul 9, 2021
commit c675764a46b6520fea28c46d2fc02795deea9445
20 changes: 1 addition & 19 deletions models/UserMapping.js → models/GithubUserMapping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This defines user mapping model.
* This defines github user mapping model.
*/
'use strict';

Expand Down Expand Up @@ -32,15 +32,6 @@ const schema = new Schema({
name: 'GithubUsernameIndex'
}
},
gitlabUsername: {
type: String,
index: {
global: true,
project: true,
rangKey: 'id',
name: 'GitlabUsernameIndex'
}
},
githubUserId: {
type: Number,
index: {
Expand All @@ -49,15 +40,6 @@ const schema = new Schema({
rangKey: 'id',
name: 'GithubUserIdIndex'
}
},
gitlabUserId: {
type: Number,
index: {
global: true,
project: true,
rangKey: 'id',
name: 'GitlabUserIdIndex'
}
}
});

Expand Down
46 changes: 46 additions & 0 deletions models/GitlabUserMapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* This defines gitlab user mapping model.
*/
'use strict';

const dynamoose = require('dynamoose');

const Schema = dynamoose.Schema;

const schema = new Schema({
id: {
type: String,
required: true,
hashKey: true
},
topcoderUsername: {
type: String,
required: true,
index: {
global: true,
project: true,
rangKey: 'id',
name: 'TopcoderUsernameIndex'
}
},
gitlabUsername: {
type: String,
index: {
global: true,
project: true,
rangKey: 'id',
name: 'GitlabUsernameIndex'
}
},
gitlabUserId: {
type: Number,
index: {
global: true,
project: true,
rangKey: 'id',
name: 'GitlabUserIdIndex'
}
}
});

module.exports = schema;
5 changes: 3 additions & 2 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const models = {
Issue: dynamoose.model('Topcoder_X.Issue', require('./Issue')),
Project: dynamoose.model('Topcoder_X.Project', require('./Project')),
User: dynamoose.model('Topcoder_X.User', require('./User')),
UserMapping: dynamoose.model('Topcoder_X.UserMapping', require('./UserMapping')),
CopilotPayment: dynamoose.model('Topcoder_X.CopilotPayment', require('./CopilotPayment'))
CopilotPayment: dynamoose.model('Topcoder_X.CopilotPayment', require('./CopilotPayment')),
GithubUserMapping: dynamoose.model('Topcoder_X.GithubUserMapping', require('./GithubUserMapping')),
GitlabUserMapping: dynamoose.model('Topcoder_X.GitlabUserMapping', require('./GitlabUserMapping'))
};
/* eslint-enable global-require */

Expand Down
11 changes: 6 additions & 5 deletions services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ async function getTCUserName(provider, gitUser) {
const criteria = {};
if (_.isNumber(gitUser) || v.isUUID(gitUser)) {
if (provider === 'github') {
return await dbHelper.queryOneUserMappingByGithubUserId(models.UserMapping, gitUser);
return await dbHelper.queryOneUserMappingByGithubUserId(models.GithubUserMapping, gitUser);
} else if (provider === 'gitlab') {
return await dbHelper.queryOneUserMappingByGitlabUserId(models.UserMapping, gitUser);
return await dbHelper.queryOneUserMappingByGitlabUserId(models.GitlabUserMapping, gitUser);
}
} else if (_.isString(gitUser) || v.isEmail(gitUser)) {
if (provider === 'github') {
return await dbHelper.queryOneUserMappingByGithubUsername(models.UserMapping, gitUser);
return await dbHelper.queryOneUserMappingByGithubUsername(models.GithubUserMapping, gitUser);
} else if (provider === 'gitlab') {
return await dbHelper.queryOneUserMappingByGitlabUsername(models.UserMapping, gitUser);
return await dbHelper.queryOneUserMappingByGitlabUsername(models.GitlabUserMapping, gitUser);
}
}
if (_.isEmpty(criteria)) {
Expand Down Expand Up @@ -73,7 +73,8 @@ async function getRepositoryCopilotOrOwner(provider, repoFullName) {
}

const userMapping = await dbHelper.queryOneUserMappingByTCUsername(
models.UserMapping, hasCopilot ? project.copilot.toLowerCase() : project.owner.toLowerCase());
provider === 'github' ? models.GithubUserMapping : models.GitlabUserMapping,
hasCopilot ? project.copilot.toLowerCase() : project.owner.toLowerCase());

logger.debug('userMapping');
logger.debug(userMapping);
Expand Down
2 changes: 1 addition & 1 deletion utils/db-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
model.queryOne('topcoderUsername').eq(tcusername)
.all()
.exec((err, result) => {
if (err || !result) {
if (err) {
logger.debug(`queryOneUserMappingByTCUsername. Error. ${err}`);
return reject(err);
}
Expand Down