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

Commit 22c9e75

Browse files
authored
Merge pull request #70 from afrisalyp/develop
Split UserMapping.
2 parents f39b443 + c675764 commit 22c9e75

File tree

5 files changed

+57
-27
lines changed

5 files changed

+57
-27
lines changed

models/UserMapping.js renamed to models/GithubUserMapping.js

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This defines user mapping model.
2+
* This defines github user mapping model.
33
*/
44
'use strict';
55

@@ -32,15 +32,6 @@ const schema = new Schema({
3232
name: 'GithubUsernameIndex'
3333
}
3434
},
35-
gitlabUsername: {
36-
type: String,
37-
index: {
38-
global: true,
39-
project: true,
40-
rangKey: 'id',
41-
name: 'GitlabUsernameIndex'
42-
}
43-
},
4435
githubUserId: {
4536
type: Number,
4637
index: {
@@ -49,15 +40,6 @@ const schema = new Schema({
4940
rangKey: 'id',
5041
name: 'GithubUserIdIndex'
5142
}
52-
},
53-
gitlabUserId: {
54-
type: Number,
55-
index: {
56-
global: true,
57-
project: true,
58-
rangKey: 'id',
59-
name: 'GitlabUserIdIndex'
60-
}
6143
}
6244
});
6345

models/GitlabUserMapping.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* This defines gitlab user mapping model.
3+
*/
4+
'use strict';
5+
6+
const dynamoose = require('dynamoose');
7+
8+
const Schema = dynamoose.Schema;
9+
10+
const schema = new Schema({
11+
id: {
12+
type: String,
13+
required: true,
14+
hashKey: true
15+
},
16+
topcoderUsername: {
17+
type: String,
18+
required: true,
19+
index: {
20+
global: true,
21+
project: true,
22+
rangKey: 'id',
23+
name: 'TopcoderUsernameIndex'
24+
}
25+
},
26+
gitlabUsername: {
27+
type: String,
28+
index: {
29+
global: true,
30+
project: true,
31+
rangKey: 'id',
32+
name: 'GitlabUsernameIndex'
33+
}
34+
},
35+
gitlabUserId: {
36+
type: Number,
37+
index: {
38+
global: true,
39+
project: true,
40+
rangKey: 'id',
41+
name: 'GitlabUserIdIndex'
42+
}
43+
}
44+
});
45+
46+
module.exports = schema;

models/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ const models = {
3838
Issue: dynamoose.model('Topcoder_X.Issue', require('./Issue')),
3939
Project: dynamoose.model('Topcoder_X.Project', require('./Project')),
4040
User: dynamoose.model('Topcoder_X.User', require('./User')),
41-
UserMapping: dynamoose.model('Topcoder_X.UserMapping', require('./UserMapping')),
42-
CopilotPayment: dynamoose.model('Topcoder_X.CopilotPayment', require('./CopilotPayment'))
41+
CopilotPayment: dynamoose.model('Topcoder_X.CopilotPayment', require('./CopilotPayment')),
42+
GithubUserMapping: dynamoose.model('Topcoder_X.GithubUserMapping', require('./GithubUserMapping')),
43+
GitlabUserMapping: dynamoose.model('Topcoder_X.GitlabUserMapping', require('./GitlabUserMapping'))
4344
};
4445
/* eslint-enable global-require */
4546

services/UserService.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ async function getTCUserName(provider, gitUser) {
2828
const criteria = {};
2929
if (_.isNumber(gitUser) || v.isUUID(gitUser)) {
3030
if (provider === 'github') {
31-
return await dbHelper.queryOneUserMappingByGithubUserId(models.UserMapping, gitUser);
31+
return await dbHelper.queryOneUserMappingByGithubUserId(models.GithubUserMapping, gitUser);
3232
} else if (provider === 'gitlab') {
33-
return await dbHelper.queryOneUserMappingByGitlabUserId(models.UserMapping, gitUser);
33+
return await dbHelper.queryOneUserMappingByGitlabUserId(models.GitlabUserMapping, gitUser);
3434
}
3535
} else if (_.isString(gitUser) || v.isEmail(gitUser)) {
3636
if (provider === 'github') {
37-
return await dbHelper.queryOneUserMappingByGithubUsername(models.UserMapping, gitUser);
37+
return await dbHelper.queryOneUserMappingByGithubUsername(models.GithubUserMapping, gitUser);
3838
} else if (provider === 'gitlab') {
39-
return await dbHelper.queryOneUserMappingByGitlabUsername(models.UserMapping, gitUser);
39+
return await dbHelper.queryOneUserMappingByGitlabUsername(models.GitlabUserMapping, gitUser);
4040
}
4141
}
4242
if (_.isEmpty(criteria)) {
@@ -73,7 +73,8 @@ async function getRepositoryCopilotOrOwner(provider, repoFullName) {
7373
}
7474

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

7879
logger.debug('userMapping');
7980
logger.debug(userMapping);

utils/db-helper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async function queryOneUserMappingByTCUsername(model, tcusername) {
129129
model.queryOne('topcoderUsername').eq(tcusername)
130130
.all()
131131
.exec((err, result) => {
132-
if (err || !result) {
132+
if (err) {
133133
logger.debug(`queryOneUserMappingByTCUsername. Error. ${err}`);
134134
return reject(err);
135135
}

0 commit comments

Comments
 (0)