Skip to content

Commit

Permalink
fix: use get_value instead of get_keys_value in author comment change…
Browse files Browse the repository at this point in the history
…list
  • Loading branch information
MichaelTaylor3D committed Dec 7, 2023
1 parent 59be263 commit 8f8b055
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt",
"version": "1.7.4",
"version": "1.7.5",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down
26 changes: 26 additions & 0 deletions src/datalayer/persistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ const getBaseOptions = () => {
return baseOptions;
};

const getValue = async (storeId, storeKey) => {
const url = `${CONFIG.DATALAYER_URL}/get_value`;
const { cert, key, timeout } = getBaseOptions();

try {
const response = await superagent
.post(url)
.key(key)
.cert(cert)
.timeout(timeout)
.send({ id: storeId, key: storeKey });

const data = response.body;

if (data.success) {
return data.value;
}

return false;
} catch (error) {
logger.error(error);
return false;
}
};

const getMirrors = async (storeId) => {
const url = `${CONFIG.DATALAYER_URL}/get_mirrors`;
const { cert, key, timeout } = getBaseOptions();
Expand Down Expand Up @@ -663,4 +688,5 @@ export {
cancelOffer,
verifyOffer,
takeOffer,
getValue,
};
9 changes: 9 additions & 0 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ const removeMirror = (storeId, coinId) => {
return dataLayer.removeMirror(storeId, coinId);
};

const getValue = async (storeId, key) => {
if (USE_SIMULATOR) {
return '7b22636f6d6d656e74223a2022227d';
} else {
return dataLayer.getValue(storeId, key);
}
};

export default {
addMirror,
createDataLayerStore,
Expand All @@ -185,4 +193,5 @@ export default {
syncDataLayer,
upsertDataLayer,
removeMirror,
getValue,
};
24 changes: 17 additions & 7 deletions src/models/projects/projects.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
formatModelAssociationName,
getDeletedItems,
} from '../../utils/model-utils.js';
import { keyValueToChangeList } from '../../utils/datalayer-utils';
import { encodeHex, keyValueToChangeList } from '../../utils/datalayer-utils';
import dataLayer from '../../datalayer';

class Project extends Model {
Expand Down Expand Up @@ -384,19 +384,29 @@ class Project extends Model {
);

const { registryId } = await Organization.getHomeOrg();
const currentDataLayer = await dataLayer.getCurrentStoreData(registryId);
const currentComment = currentDataLayer.filter(
(kv) => kv.key === 'comment',

const commentValueInStore = await dataLayer.getValue(
registryId,
encodeHex('comment'),
);
const isUpdateComment = currentComment.length > 0;

const isUpdateComment =
!_.isNil(commentValueInStore) && commentValueInStore !== false;

const commentChangeList = keyValueToChangeList(
'comment',
`{"comment": "${comment}"}`,
isUpdateComment,
);

const currentAuthor = currentDataLayer.filter((kv) => kv.key === 'author');
const isUpdateAuthor = currentAuthor.length > 0;
const authorValueInStore = await dataLayer.getValue(
registryId,
encodeHex('author'),
);

const isUpdateAuthor =
!_.isNil(authorValueInStore) && authorValueInStore !== false;

const authorChangeList = keyValueToChangeList(
'author',
`{"author": "${author}"}`,
Expand Down
23 changes: 16 additions & 7 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
createXlsFromSequelizeResults,
transformFullXslsToChangeList,
} from '../../utils/xls';
import { keyValueToChangeList } from '../../utils/datalayer-utils';
import { encodeHex, keyValueToChangeList } from '../../utils/datalayer-utils';
import { unitsUpdateSchema } from '../../validations/index.js';
import { getDeletedItems } from '../../utils/model-utils.js';
import dataLayer from '../../datalayer';
Expand Down Expand Up @@ -390,19 +390,28 @@ class Unit extends Model {
);

const { registryId } = await Organization.getHomeOrg();
const currentDataLayer = await dataLayer.getCurrentStoreData(registryId);
const currentComment = currentDataLayer.filter(
(kv) => kv.key === 'comment',

const commentValueInStore = await dataLayer.getValue(
registryId,
encodeHex('comment'),
);
const isUpdateComment = currentComment.length > 0;
const isUpdateComment =
!_.isNil(commentValueInStore) && commentValueInStore !== false;

const commentChangeList = keyValueToChangeList(
'comment',
`{"comment": "${comment}"}`,
isUpdateComment,
);

const currentAuthor = currentDataLayer.filter((kv) => kv.key === 'author');
const isUpdateAuthor = currentAuthor.length > 0;
const authorValueInStore = await dataLayer.getValue(
registryId,
encodeHex('author'),
);

const isUpdateAuthor =
!_.isNil(authorValueInStore) && authorValueInStore !== false;

const authorChangeList = keyValueToChangeList(
'author',
`{"author": "${author}"}`,
Expand Down

0 comments on commit 8f8b055

Please sign in to comment.