Skip to content

Commit 2f78fcf

Browse files
authored
more meaningful names (#65)
* improve variables and functions names
1 parent a631e1c commit 2f78fcf

File tree

9 files changed

+78
-63
lines changed

9 files changed

+78
-63
lines changed

RELEASE_NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- Using prestart we re-generate the env.js file,
1515
but the generator does not comply with our
1616
prettier rules, so we have to enforce prettier during prestart.
17+
- Changed some names on varibles in order to be more clear
1718
- Minor issues (animation/colors)
1819
- No Graphql dependencies for the app to work
1920
- Tenant name on path creation

configuration-api/main/advancedAuth.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const logContext = { op: 'configuration-api.advancedAuth' };
1313
config.loadConfig();
1414

1515
const { get, update, add, deleteTenant } = require('./mongo/tenantsQueries');
16-
const { getUserPref, updateUserPref } = require('./mongo/usrSettings');
16+
const { getUserPref, updateUserPref } = require('./mongo/userSettings');
1717
const typeDefs = gql`
1818
type TenantConfiguration {
1919
name: String!
@@ -22,18 +22,23 @@ const typeDefs = gql`
2222
secondaryColor: String!
2323
}
2424
type UserPreferencies {
25-
usrName: String!
25+
userName: String!
2626
language: String!
2727
}
2828
type Query {
2929
listTenants(tenantNames: [String]!): [TenantConfiguration]
30-
getUserPreferences(usrName: String!): [UserPreferencies]
30+
getUserPreferences(userName: String!): [UserPreferencies]
3131
}
3232
type Mutation {
33-
modifyUserPreferences(usrName: String!, language: String!): [UserPreferencies]
34-
publishTenants(name: String!, icon: String!, primaryColor: String!, secondaryColor: String!): [TenantConfiguration]
35-
removeTenants(tenantNames: [String]!): Boolean!
36-
modifyTenants(name: String!, icon: String!, primaryColor: String!, secondaryColor: String!): [TenantConfiguration]
33+
modifyUserPreferences(userName: String!, language: String!): [UserPreferencies]
34+
getTenantConfig(name: String!, icon: String!, primaryColor: String!, secondaryColor: String!): [TenantConfiguration]
35+
removeTenantConfig(tenantNames: [String]!): Boolean!
36+
modifyTenantConfig(
37+
name: String!
38+
icon: String!
39+
primaryColor: String!
40+
secondaryColor: String!
41+
): [TenantConfiguration]
3742
}
3843
`;
3944

@@ -50,8 +55,8 @@ const resolvers = {
5055
},
5156
getUserPreferences: async (object, args, context, info) => {
5257
try {
53-
config.getLogger().info(logContext, 'getUserPreferences: %s', args.usrName);
54-
return await getUserPref(args.usrName);
58+
config.getLogger().info(logContext, 'getUserPreferences: %s', args.userName);
59+
return await getUserPref(args.userName);
5560
} catch (err) {
5661
config.getLogger().error(logContext, err);
5762
throw new ApolloError({ data: { reason: err.message } });
@@ -68,27 +73,27 @@ const resolvers = {
6873
throw new ApolloError({ data: { reason: err.message } });
6974
}
7075
},
71-
publishTenants: async (object, args, context, info) => {
76+
getTenantConfig: async (object, args, context, info) => {
7277
try {
73-
config.getLogger().info(logContext, 'publishTenants: %s', JSON.stringify(args));
78+
config.getLogger().info(logContext, 'getTenantConfig: %s', JSON.stringify(args));
7479
return await [add(args)];
7580
} catch (err) {
7681
config.getLogger().error(logContext, err);
7782
throw new ApolloError({ data: { reason: err.message } });
7883
}
7984
},
80-
modifyTenants: async (object, args, context, info) => {
85+
modifyTenantConfig: async (object, args, context, info) => {
8186
try {
82-
config.getLogger().info(logContext, 'modifyTenants: %s', JSON.stringify(args));
87+
config.getLogger().info(logContext, 'modifyTenantConfig: %s', JSON.stringify(args));
8388
return await [update(args)];
8489
} catch (err) {
8590
config.getLogger().error(logContext, err);
8691
throw new ApolloError({ data: { reason: err.message } });
8792
}
8893
},
89-
removeTenants: async (object, args, context, info) => {
94+
removeTenantConfig: async (object, args, context, info) => {
9095
try {
91-
config.getLogger().info(logContext, 'removeTenants: %s', JSON.stringify(args));
96+
config.getLogger().info(logContext, 'removeTenantConfig: %s', JSON.stringify(args));
9297
return await deleteTenant(args);
9398
} catch (err) {
9499
config.getLogger().error(logContext, err);

configuration-api/main/mongo/populateDB.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ const mongoose = require('mongoose');
44

55
const connection = mongoose.createConnection(process.env.MONGO_DB || 'mongodb://localhost:27017/graphql');
66

7-
const usrPreference = new mongoose.Schema({
7+
const TenantConfig = new mongoose.Schema({
88
name: String,
99
icon: String,
1010
primaryColor: String,
1111
secondaryColor: String
1212
});
1313

14-
const Preferences = connection.model('UsrPreferences', usrPreference);
14+
const Config = connection.model('TenantConfig', TenantConfig);
1515

16-
Preferences.deleteMany({}, function (err) {
16+
Config.deleteMany({}, function (err) {
1717
console.log('PopulateDB: clear old data...');
1818
if (err) {
1919
console.log(err);
2020
} else {
21-
Preferences.create(
21+
Config.create(
2222
{
2323
name: 'Tenant1',
2424
icon: 'none',
@@ -30,7 +30,7 @@ Preferences.deleteMany({}, function (err) {
3030
console.log(err);
3131
} else {
3232
console.log('Tenant1 created!');
33-
Preferences.create(
33+
Config.create(
3434
{
3535
name: 'Tenant2',
3636
icon: 'none',

configuration-api/main/mongo/tenantsQueries.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ const config = require('../config');
33
const connection = mongoose.createConnection(config.getConfig().mongo_db);
44
const logContext = { op: 'configuration-api.advancedAuth' };
55

6-
const usrPreference = new mongoose.Schema({
6+
const TenantConfig = new mongoose.Schema({
77
name: String,
88
icon: String,
99
primaryColor: String,
1010
secondaryColor: String
1111
});
1212

13-
const Preferences = connection.model('UsrPreferences', usrPreference);
13+
const Config = connection.model('TenantConfig', TenantConfig);
1414

1515
async function get(data) {
16-
const thisUser = await Preferences.find({ name: { $in: data } });
17-
if (thisUser.length === data.length) {
18-
return await thisUser;
16+
const tenants = await Config.find({ name: { $in: data } });
17+
if (tenants.length === data.length) {
18+
return await tenants;
1919
} else {
2020
fromScratch(data);
2121
}
@@ -30,7 +30,7 @@ async function update(data) {
3030
secondaryColor: data.secondaryColor
3131
};
3232

33-
const thisTenant = await Preferences.findOneAndUpdate(filter, update);
33+
const thisTenant = await Config.findOneAndUpdate(filter, update);
3434
return await thisTenant;
3535
}
3636

@@ -50,29 +50,27 @@ async function add(data) {
5050

5151
async function fromScratch(data) {
5252
for (let thisTenant of data) {
53-
const thisUser = await Preferences.find({ name: thisTenant });
54-
if (thisUser.length === 0) {
53+
const tenants = await Config.find({ name: thisTenant });
54+
if (tenants.length === 0) {
5555
const arrayOfData = {
5656
name: thisTenant,
5757
icon: 'none',
5858
primaryColor: '#8086ba',
5959
secondaryColor: '#8086ba'
6060
};
61-
await arrayOfData.save(function (err) {
62-
if (err) return config.getLogger().error(logContext, err);
63-
});
61+
Config.create(arrayOfData);
6462
}
6563
}
6664
get(data);
6765
}
6866

6967
async function deleteTenant(data) {
70-
const thisUser = await Preferences.find({ name: { $in: data } });
71-
let deletedOwner = {};
72-
for (const e of thisUser) {
73-
deletedOwner = await Preferences.findByIdAndRemove(e._id);
68+
const tenants = await Config.find({ name: { $in: data } });
69+
let deletedTenants = {};
70+
for (const e of tenants) {
71+
deletedTenants = await Config.findByIdAndRemove(e._id);
7472
}
75-
return !!(await (typeof deletedOwner === 'object'));
73+
return !!(await (typeof deletedTenants === 'object'));
7674
}
7775

7876
module.exports = {

configuration-api/main/mongo/usrSettings.js configuration-api/main/mongo/userSettings.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const mongoose = require('mongoose');
33
const config = require('../config');
44
const connection = mongoose.createConnection(config.getConfig().mongo_db);
55
const logContext = { op: 'configuration-api.advancedAuth' };
6-
const usrSettings = new mongoose.Schema({
7-
usrName: String,
6+
const userSettings = new mongoose.Schema({
7+
userName: String,
88
language: String
99
});
1010

11-
const Settings = connection.model('UsrSettings', usrSettings);
11+
const Settings = connection.model('userSettings', userSettings);
1212

1313
async function getUserPref(data) {
14-
const thisUser = await Settings.find({ usrName: data });
14+
const thisUser = await Settings.find({ userName: data });
1515
if (thisUser.length > 0) {
1616
return await thisUser;
1717
} else {
@@ -20,9 +20,9 @@ async function getUserPref(data) {
2020
}
2121

2222
async function updateUserPref(data) {
23-
const filter = { usrName: data.usrName };
23+
const filter = { userName: data.userName };
2424
const update = {
25-
usrName: data.usrName,
25+
userName: data.userName,
2626
language: data.language
2727
};
2828

@@ -32,7 +32,7 @@ async function updateUserPref(data) {
3232

3333
async function addUserPref(data) {
3434
const arrayOfData = {
35-
usrName: data,
35+
userName: data,
3636
language: 'defaultBrowser'
3737
};
3838

src/App.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ const DrawerHeader = styled('div')(({ theme }) => ({
8787

8888
export default class App extends Component {
8989
state = {
90-
open: false,
91-
setOpen: (newValue) => {
92-
this.setState({ open: newValue, direction: newValue ? 'ltr' : '' });
90+
openLateralMenu: false,
91+
setOpenLateralMenu: (newValue) => {
92+
this.setState({ openLateralMenu: newValue, direction: newValue ? 'ltr' : '' });
9393
},
9494
direction: 'ltr',
9595
tokenData: [],
@@ -273,15 +273,15 @@ export default class App extends Component {
273273
client
274274
.query({
275275
query: gql`
276-
query getUserPreferences($usrName: String!) {
277-
getUserPreferences(usrName: $usrName) {
278-
usrName
276+
query getUserPreferences($userName: String!) {
277+
getUserPreferences(userName: $userName) {
278+
userName
279279
language
280280
}
281281
}
282282
`,
283283
variables: {
284-
usrName: this.props.idTokenPayload.sub,
284+
userName: this.props.idTokenPayload.sub,
285285
state: this.state
286286
}
287287
})
@@ -326,11 +326,11 @@ export default class App extends Component {
326326
}
327327

328328
handleDrawerOpen = () => {
329-
this.state.setOpen(true);
329+
this.state.setOpenLateralMenu(true);
330330
};
331331

332332
handleDrawerClose = () => {
333-
this.state.setOpen(false);
333+
this.state.setOpenLateralMenu(false);
334334
};
335335

336336
toggleDrawer = (open) => (event) => {
@@ -348,14 +348,14 @@ export default class App extends Component {
348348
<Box sx={{ display: 'flex' }}>
349349
<BrowserRouter>
350350
<CssBaseline />
351-
<AppBar position="fixed" open={this.state.open}>
351+
<AppBar position="fixed" open={this.state.openLateralMenu}>
352352
<CustomToolbar color="primary">
353353
<IconButton
354354
color="inherit"
355355
aria-label="open drawer"
356356
onClick={this.handleDrawerOpen}
357357
edge="start"
358-
sx={{ mr: 2, ...(this.state.open && { display: 'none' }) }}
358+
sx={{ mr: 2, ...(this.state.openLateralMenu && { display: 'none' }) }}
359359
>
360360
<MenuIcon />
361361
</IconButton>
@@ -388,9 +388,10 @@ export default class App extends Component {
388388
boxSizing: 'border-box'
389389
}
390390
}}
391+
variant="persistent"
392+
open={this.state.openLateralMenu}
391393
onClose={this.toggleDrawer(false)}
392394
anchor={'left'}
393-
open={this.state.open}
394395
onOpen={this.toggleDrawer(true)}
395396
>
396397
<DrawerHeader>
@@ -456,7 +457,7 @@ export default class App extends Component {
456457
</Container>
457458
</Main>
458459
) : (
459-
<Main open={this.state.open} />
460+
<Main open={this.state.openLateralMenu} />
460461
)}
461462
<DrawerHeader />
462463
</BrowserRouter>

src/components/shared/userMenu.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ export default function UserMenu({ language, userData, token }) {
104104
client
105105
.mutate({
106106
mutation: gql`
107-
mutation modifyUserPreferences($usrName: String!, $language: String!) {
108-
modifyUserPreferences(usrName: $usrName, language: $language) {
109-
usrName
107+
mutation modifyUserPreferences($userName: String!, $language: String!) {
108+
modifyUserPreferences(userName: $userName, language: $language) {
109+
userName
110110
language
111111
}
112112
}
113113
`,
114114
variables: {
115-
usrName: userData.sub,
115+
userName: userData.sub,
116116
language: newValue
117117
}
118118
})

src/components/tenant/iconPicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function IconPicker({ previusValue, setValue, mode }) {
1212
const handleChange = (event) => {
1313
setValue(event.target.value);
1414
};
15-
console.log(IconList());
15+
1616
return (
1717
<Box
1818
sx={{

src/components/tenant/tenantForm.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,18 @@ export default function TenantForm({ title, close, action, tenant, getTenants, t
8888
client
8989
.mutate({
9090
mutation: gql`
91-
mutation modifyTenants($name: String!, $icon: String!, $primaryColor: String!, $secondaryColor: String!) {
92-
modifyTenants(name: $name, icon: $icon, primaryColor: $primaryColor, secondaryColor: $secondaryColor) {
91+
mutation modifyTenantConfig(
92+
$name: String!
93+
$icon: String!
94+
$primaryColor: String!
95+
$secondaryColor: String!
96+
) {
97+
modifyTenantConfig(
98+
name: $name
99+
icon: $icon
100+
primaryColor: $primaryColor
101+
secondaryColor: $secondaryColor
102+
) {
93103
name
94104
icon
95105
primaryColor

0 commit comments

Comments
 (0)