Skip to content

Commit

Permalink
Merge pull request #458 from harkotha2/camelCase1
Browse files Browse the repository at this point in the history
New: Update graphql variables to camelCase
  • Loading branch information
dalehille committed Jul 2, 2020
2 parents 0a9017b + 677a741 commit d358863
Show file tree
Hide file tree
Showing 84 changed files with 807 additions and 660 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -7,7 +7,8 @@ services:

script:
# Audit npm packages. Fail build whan a PR audit fails, otherwise report the vulnerability and proceed.
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --low; else npx audit-ci --low || true; fi
# see https://www.npmjs.com/advisories/1523 and https://github.com/lodash/lodash/pull/4759 discussion
- if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --low -a 1523; else npx audit-ci --low -a 1523 || true; fi
- npm run lint
- npm test
- npm run test:apollo:default
Expand Down
1 change: 1 addition & 0 deletions app/apollo/models/channel.schema.js
Expand Up @@ -22,6 +22,7 @@ const ChannelSchema = new mongoose.Schema({
},
org_id: {
type: String,
alias: 'orgId',
},
name: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions app/apollo/models/cluster.js
Expand Up @@ -16,7 +16,9 @@

const mongoose = require('mongoose');
const ClusterSchema = require('./cluster.schema');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');

ClusterSchema.plugin(mongooseLeanVirtuals);
const Cluster = mongoose.model('clusters', ClusterSchema);

module.exports = Cluster;
6 changes: 5 additions & 1 deletion app/apollo/models/cluster.schema.js
Expand Up @@ -19,9 +19,11 @@ const { CLUSTER_REG_STATES } = require('./const');
const ClusterSchema = new mongoose.Schema({
org_id: {
type: String,
alias: 'orgId',
},
cluster_id: {
type: String,
alias: 'clusterId',
},
groups: [
{
Expand Down Expand Up @@ -68,6 +70,7 @@ const ClusterSchema = new mongoose.Schema({
{
user_id: {
type: String,
alias: 'userId',
},
content: {
type: String,
Expand All @@ -85,7 +88,8 @@ const ClusterSchema = new mongoose.Schema({
reg_state: {
type: String,
enum: [CLUSTER_REG_STATES.REGISTERING, CLUSTER_REG_STATES.PENDING, CLUSTER_REG_STATES.REGISTERED],
default: CLUSTER_REG_STATES.REGISTERING,
default: CLUSTER_REG_STATES.REGISTERING,
alias: 'regState',
},

dirty: {
Expand Down
3 changes: 3 additions & 0 deletions app/apollo/models/deployableVersion.schema.js
Expand Up @@ -22,12 +22,15 @@ const DeployableVersionSchema = new mongoose.Schema({
},
org_id: {
type: String,
alias: 'orgId',
},
channel_id: {
type: String,
alias: 'channelId',
},
channel_name: {
type: String,
alias: 'channelName',
},
name: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions app/apollo/models/group.js
Expand Up @@ -16,7 +16,9 @@

const mongoose = require('mongoose');
const GroupSchema = require('./group.schema');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');

GroupSchema.plugin(mongooseLeanVirtuals);
const Group = mongoose.model('groups', GroupSchema);

module.exports = Group;
1 change: 1 addition & 0 deletions app/apollo/models/group.schema.js
Expand Up @@ -23,6 +23,7 @@ const GroupSchema = new mongoose.Schema({
},
org_id: {
type: String,
alias: 'orgId',
},
name: {
type: String,
Expand Down
1 change: 1 addition & 0 deletions app/apollo/models/organization.default.schema.js
Expand Up @@ -19,6 +19,7 @@ const { v4: uuid } = require('uuid');
const OrganizationDefaultSchema = new mongoose.Schema({
_id: {
type: String,
alias: 'id',
},
name: {
type: String,
Expand Down
3 changes: 2 additions & 1 deletion app/apollo/models/organization.js
Expand Up @@ -14,11 +14,12 @@
* limitations under the License.
*/
const mongoose = require('mongoose');

const mongooseLeanVirtuals = require('mongoose-lean-virtuals');
const { AUTH_MODEL } = require('./const');

const OrganizationSchema = require(`./organization.${AUTH_MODEL}.schema`);

OrganizationSchema.plugin(mongooseLeanVirtuals);
const Organization = mongoose.model('orgs', OrganizationSchema);

module.exports = Organization;
1 change: 1 addition & 0 deletions app/apollo/models/organization.local.schema.js
Expand Up @@ -19,6 +19,7 @@ const { v4: uuid } = require('uuid');
const OrganizationLocalSchema = new mongoose.Schema({
_id: {
type: String,
alias: 'id',
},
name: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions app/apollo/models/resource.js
Expand Up @@ -16,7 +16,9 @@

const mongoose = require('mongoose');
const ResourceSchema = require('./resource.schema');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');

ResourceSchema.plugin(mongooseLeanVirtuals);
const Resource = mongoose.model('resources', ResourceSchema);

module.exports = Resource;
2 changes: 2 additions & 0 deletions app/apollo/models/resource.schema.js
Expand Up @@ -19,9 +19,11 @@ const mongoose = require('mongoose');
const ResourceSchema = new mongoose.Schema({
org_id: {
type: String,
alias: 'orgId',
},
cluster_id: {
type: String,
alias: 'clusterId',
},
selfLink: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions app/apollo/models/resourceYamlHist.js
Expand Up @@ -16,7 +16,9 @@

const mongoose = require('mongoose');
const ResourceYamlHistSchema = require('./resourceYamlHist.schema');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');

ResourceYamlHistSchema.plugin(mongooseLeanVirtuals);
const ResourceYamlHist = mongoose.model('resourceYamlHist', ResourceYamlHistSchema, 'resourceYamlHist');

module.exports = ResourceYamlHist;
1 change: 1 addition & 0 deletions app/apollo/models/resourceYamlHist.schema.js
Expand Up @@ -19,6 +19,7 @@ const mongoose = require('mongoose');
const ResourceYamlHistSchema = new mongoose.Schema({
_id:{
type: String,
alias: 'id',
},
org_id: {
type: String,
Expand Down
2 changes: 2 additions & 0 deletions app/apollo/models/subscription.js
Expand Up @@ -16,7 +16,9 @@

const mongoose = require('mongoose');
const SubscriptionSchema = require('./subscription.schema');
const mongooseLeanVirtuals = require('mongoose-lean-virtuals');

SubscriptionSchema.plugin(mongooseLeanVirtuals);
const Subscription = mongoose.model('subscriptions', SubscriptionSchema);

module.exports = Subscription;
3 changes: 3 additions & 0 deletions app/apollo/models/subscription.schema.js
Expand Up @@ -22,6 +22,7 @@ const SubscriptionSchema = new mongoose.Schema({
},
org_id: {
type: String,
alias: 'orgId',
},
name: {
type: String,
Expand All @@ -36,6 +37,7 @@ const SubscriptionSchema = new mongoose.Schema({
],
channel_uuid: {
type: String,
alias: 'channelUuid',
},
channel: {
type: String,
Expand All @@ -45,6 +47,7 @@ const SubscriptionSchema = new mongoose.Schema({
},
version_uuid: {
type: String,
alias: 'versionUuid',
},
owner: {
type: String,
Expand Down
14 changes: 7 additions & 7 deletions app/apollo/models/user.default.schema.js
Expand Up @@ -159,7 +159,7 @@ UserDefaultSchema.statics.getOrgs = async function(context) {
// of the github|bitbucket orgs a user belongs to, find ones that are registered in razee
const orgFromDB = await models.Organization.findOne({ gheOrgId: org.gheOrgId }).lean();
if (orgFromDB) {
results.push({ name: orgFromDB.name, _id: orgFromDB._id });
results.push({ name: orgFromDB.name, id: orgFromDB._id });
}
}
}
Expand All @@ -171,7 +171,7 @@ UserDefaultSchema.statics.getOrgById = async function(models, orgId) {
};

UserDefaultSchema.statics.getOrg = async function(models, me) {
return await models.Organization.findOne({ orgKeys: me.orgKey }).lean();
return await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true });
};

UserDefaultSchema.statics.getBasicUsersByIds = async function(ids){
Expand All @@ -180,15 +180,15 @@ UserDefaultSchema.statics.getBasicUsersByIds = async function(ids){
}
var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 });
users = users.map((user)=>{
var _id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'service.default.username') || _id;
var id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'service.default.username') || id;
return {
_id,
id,
name,
};
});
users = _.keyBy(users, '_id');
users['undefined'] = {_id: 'undefined', name: 'undefined'};
users = _.keyBy(users, 'id');
users['undefined'] = {id: 'undefined', name: 'undefined'};
return users;
};

Expand Down
22 changes: 13 additions & 9 deletions app/apollo/models/user.local.schema.js
Expand Up @@ -84,7 +84,7 @@ const UserLocalSchema = new mongoose.Schema({
});

async function getOrCreateOrganization(models, args) {
const orgName = args.org_name || 'default_local_org';
const orgName = args.orgName || 'default_local_org';
const org = await models.Organization.findOne({ name: orgName });
if (org) return org;
if (models.OrganizationDistributed) {
Expand Down Expand Up @@ -160,13 +160,17 @@ UserLocalSchema.statics.createToken = async (user, secret, expiresIn) => {

UserLocalSchema.statics.getCurrentUser = ({me , req_id, logger}) => {
let result = me;
let data = me.meta.orgs[0];
data.id = data._id;
delete(data._id);

if (result != null) {
result = {
type: me.type,
id: me._id,
email: me.email,
identifier: me.identifier,
org_id: me.org_id,
orgId: me.org_id,
role: me.role,
meta: me.meta,
};
Expand Down Expand Up @@ -319,7 +323,7 @@ UserLocalSchema.statics.isAuthorized = async function(me, orgId, action, type, a

UserLocalSchema.statics.getOrg = async function(models, me) {
let org;
org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean();
org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true });
return org;
};

Expand All @@ -333,7 +337,7 @@ UserLocalSchema.statics.getOrgs = async function(context) {
// eslint-disable-next-line no-await-in-loop
const orgFromDB = await models.Organization.findOne({ _id: org._id });
if (orgFromDB) {
results.push({ name: orgFromDB.name, _id: org._id });
results.push({ name: orgFromDB.name, id: org._id });
}
}
}
Expand All @@ -346,15 +350,15 @@ UserLocalSchema.statics.getBasicUsersByIds = async function(ids){
}
var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 });
users = users.map((user)=>{
var _id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'services.local.username') || _id;
var id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'services.local.username') || id;
return {
_id,
id,
name,
};
});
users = _.keyBy(users, '_id');
users['undefined'] = {_id: 'undefined', name: 'undefined'};
users = _.keyBy(users, 'id');
users['undefined'] = {id: 'undefined', name: 'undefined'};
return users;
};

Expand Down
22 changes: 13 additions & 9 deletions app/apollo/models/user.passport.local.schema.js
Expand Up @@ -85,7 +85,7 @@ const UserPassportLocalSchema = new mongoose.Schema({
});

async function getOrCreateOrganization(models, args) {
const orgName = args.org_name || 'default_local_org';
const orgName = args.orgName || 'default_local_org';
const org = await models.Organization.findOne({ name: orgName });
if (org) return org;
if (models.OrganizationDistributed) {
Expand Down Expand Up @@ -165,13 +165,17 @@ UserPassportLocalSchema.statics.createToken = async (

UserPassportLocalSchema.statics.getCurrentUser = ({me , req_id, logger}) => {
let result = me;
let data = me.meta.orgs[0];
data.id = data._id;
delete(data._id);

if (result != null) {
result = {
type: me.type,
id: me._id,
email: me.email,
identifier: me.identifier,
org_id: me.org_id,
orgId: me.org_id,
role: me.role,
meta: me.meta,
};
Expand Down Expand Up @@ -325,7 +329,7 @@ UserPassportLocalSchema.statics.isAuthorized = async function(me, orgId, action,

UserPassportLocalSchema.statics.getOrg = async function(models, me) {
let org;
org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean();
org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true });
return org;
};

Expand All @@ -339,7 +343,7 @@ UserPassportLocalSchema.statics.getOrgs = async function(context) {
// eslint-disable-next-line no-await-in-loop
const orgFromDB = await models.Organization.findOne({ _id: org._id });
if (orgFromDB) {
results.push({ name: orgFromDB.name, _id: org._id });
results.push({ name: orgFromDB.name, id: org._id });
}
}
}
Expand All @@ -352,15 +356,15 @@ UserPassportLocalSchema.statics.getBasicUsersByIds = async function(ids){
}
var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 });
users = users.map((user)=>{
var _id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'services.passportlocal.username') || _id;
var id = user._id;
var name = _.get(user, 'profile.name') || _.get(user, 'services.passportlocal.username') || id;
return {
_id,
id,
name,
};
});
users = _.keyBy(users, '_id');
users['undefined'] = {_id: 'undefined', name: 'undefined'};
users = _.keyBy(users, 'id');
users['undefined'] = {id: 'undefined', name: 'undefined'};
return users;
};

Expand Down

0 comments on commit d358863

Please sign in to comment.