Skip to content

Commit

Permalink
fix: simulator in yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Apr 26, 2022
1 parent 5d93fd6 commit bd3490e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/config/config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const persistanceFolder = `${homeDir}/.chia/climate-warehouse`;

// Adding this duplicate function here because im having trouble
// importing it in from utils folder
const getConfig = () => {
const getConfig = _.memoize(() => {
const configFile = path.resolve(
`${homeDir}/.chia/climate-warehouse/config.yaml`,
);
Expand All @@ -25,7 +25,7 @@ const getConfig = () => {
// if it still doesnt exist that means we are in an env without write permissions
// so just load the default en
if (typeof process.env.USE_SIMULATOR === 'string') {
defaultConfig.APP.USE_SIMULATOR = process.env.USE_SIMULATOR === 'true';
defaultConfig.APP.USE_SIMULATOR = true;
}

console.log('Cant write config file, falling back to defaults');
Expand All @@ -37,14 +37,14 @@ const getConfig = () => {
const yml = yaml.load(fs.readFileSync(configFile, 'utf8'));

if (typeof process.env.USE_SIMULATOR === 'string') {
yml.APP.USE_SIMULATOR = process.env.USE_SIMULATOR === 'true';
yml.APP.USE_SIMULATOR = true;
}

return yml;
} catch (e) {
console.log(e, `Config file not found at ${configFile}`);
}
};
});

module.exports = {
local: {
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createV2 = async (req, res) => {

const { name } = req.body;
const buffer = req.files.file.data;
const icon = buffer.toString('base64');
const icon = `data:image/png;base64, ${buffer.toString('base64')}`;

return res.json({
message: 'New organization created successfully.',
Expand Down
9 changes: 9 additions & 0 deletions src/routes/v1/resources/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import joiExpress from 'express-joi-validation';

import { OrganizationController } from '../../../controllers';
import {
newOrganizationSchema,
unsubscribeOrganizationSchema,
subscribeOrganizationSchema,
importOrganizationSchema,
Expand All @@ -21,6 +22,14 @@ OrganizationRouter.delete('/', (req, res) => {
return OrganizationController.resetHomeOrg(req, res);
});

OrganizationRouter.post(
'/',
validator.body(newOrganizationSchema),
(req, res) => {
return OrganizationController.create(req, res);
},
);

OrganizationRouter.post('/create', (req, res) => {
return OrganizationController.createV2(req, res);
});
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-audit-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const task = new Task('sync-audit', async () => {
await assertWalletIsSynced();

log('Syncing Audit Information');
if (process.env.USE_SIMULATOR === 'false') {
if (!USE_SIMULATOR) {
const organizations = await Organization.findAll({
where: { subscribed: true },
raw: true,
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-default-organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const task = new Task('sync-default-organizations', async () => {
try {
await assertDataLayerAvailable();
await assertWalletIsSynced();
if (USE_SIMULATOR === 'false') {
if (!USE_SIMULATOR) {
Organization.subscribeToDefaultOrganizations();
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/tasks/sync-organization-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const task = new Task('sync-organization-meta', async () => {
await assertDataLayerAvailable();
await assertWalletIsSynced();
log('Syncing subscribed organizations');
if (USE_SIMULATOR === 'false') {
if (!USE_SIMULATOR) {
Organization.syncOrganizationMeta();
}
} catch (error) {
Expand Down
20 changes: 15 additions & 5 deletions src/utils/config-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,27 @@ export const getConfig = _.memoize(() => {
} catch (err) {
// if it still doesnt exist that means we are in an env without write permissions
// so just load the default env
if (typeof process.env.USE_SIMULATOR === 'string') {
defaultConfig.APP.USE_SIMULATOR =
_.get(process, 'env.USE_SIMULATOR', 'false') === 'true';
if (process.env.USE_SIMULATOR) {
defaultConfig.APP.USE_SIMULATOR = true;
defaultConfig.APP.CHIA_NETWORK = 'testnet';
}

return yaml.load(yaml.dump(defaultConfig));
}
}

return yaml.load(fs.readFileSync(configFile, 'utf8'));
try {
const yml = yaml.load(fs.readFileSync(configFile, 'utf8'));

if (typeof process.env.USE_SIMULATOR === 'string') {
yml.APP.USE_SIMULATOR = true;
}

return yml;
} catch (e) {
console.log(e, `Config file not found at ${configFile}`);
}
} catch (e) {
console.log(`Config file not found at ${configFile}`.e);
console.log(`Config file not found at ${configFile}`);
}
});
2 changes: 1 addition & 1 deletion src/validations/organizations.validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Joi from 'joi';

export const newOrganizationSchema = Joi.object({
name: Joi.string().required(),
icon: Joi.string().required(),
file: Joi.string().required(),
});

export const importOrganizationSchema = Joi.object({
Expand Down

0 comments on commit bd3490e

Please sign in to comment.