Skip to content

Commit

Permalink
feat: encode data for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael.Taylor committed Jan 3, 2022
1 parent d575a01 commit bc4a1a1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"scripts": {
"requirements-check": "node --experimental-json-modules check_node_version.js",
"start": "node --experimental-specifier-resolution=node ./src/server.js",
"start": "node --experimental-specifier-resolution=node --no-warnings ./src/server.js",
"test": "mocha tests/**/*.spec.js --reporter spec --exit",
"release": "./node_modules/.bin/standard-version && git push --tags",
"postinstall": "npm run requirements-check",
Expand Down
12 changes: 8 additions & 4 deletions src/fullnode/fullnode.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import * as simulator from './simulator';

export const updateProjectRecord = async (uuid, record, stagingRecordId) => {
await simulator.updateProjectRecord(uuid, record, stagingRecordId);
const encoded = btoa(JSON.stringify(record));
await simulator.updateProjectRecord(uuid, encoded, stagingRecordId);
};

export const createProjectRecord = async (uuid, record, stagingRecordId) => {
await simulator.createProjectRecord(uuid, record, stagingRecordId);
const encoded = btoa(JSON.stringify(record));
await simulator.createProjectRecord(uuid, encoded, stagingRecordId);
};

export const deleteProjectRecord = async (uuid, stagingRecordId) => {
await simulator.deleteProjectRecord(uuid, stagingRecordId);
};

export const updateUnitRecord = async (uuid, record, stagingRecordId) => {
await simulator.updateUnitRecord(uuid, record, stagingRecordId);
const encoded = btoa(JSON.stringify(record));
await simulator.updateUnitRecord(uuid, encoded, stagingRecordId);
};

export const createUnitRecord = async (uuid, record, stagingRecordId) => {
await simulator.createUnitRecord(uuid, record, stagingRecordId);
const encoded = btoa(JSON.stringify(record));
await simulator.createUnitRecord(uuid, encoded, stagingRecordId);
};

export const deleteUnitRecord = async (uuid, stagingRecordId) => {
Expand Down
23 changes: 19 additions & 4 deletions src/fullnode/simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ const THIRTY_SEC = 30000;

// Simulate 30 seconds passing before commited to node

export const updateProjectRecord = async (uuid, record, stagingRecordId) => {
export const updateProjectRecord = async (
uuid,
encodedRecord,
stagingRecordId,
) => {
const record = JSON.parse(encodedRecord.toString('utf8'));
return new Promise((resolve) => {
setTimeout(async () => {
if (stagingRecordId) {
Expand All @@ -26,7 +31,10 @@ export const updateProjectRecord = async (uuid, record, stagingRecordId) => {
});
};

export const createProjectRecord = (uuid, record, stagingRecordId) => {
export const createProjectRecord = (uuid, encodedRecord, stagingRecordId) => {
const record = JSON.parse(atob(encodedRecord));

console.log(record);
return new Promise((resolve) => {
setTimeout(async () => {
await Project.create({
Expand Down Expand Up @@ -69,7 +77,13 @@ export const deleteProjectRecord = (uuid, stagingRecordId) => {
});
};

export const updateUnitRecord = async (uuid, record, stagingRecordId) => {
export const updateUnitRecord = async (
uuid,
encodedRecord,
stagingRecordId,
) => {
const record = JSON.parse(encodedRecord.toString('utf8'));

await deleteUnitRecord(uuid);
await createUnitRecord(uuid, record);

Expand All @@ -82,7 +96,8 @@ export const updateUnitRecord = async (uuid, record, stagingRecordId) => {
}
};

export const createUnitRecord = (uuid, record, stagingRecordId) => {
export const createUnitRecord = (uuid, encodedRecord, stagingRecordId) => {
const record = JSON.parse(encodedRecord.toString('utf8'));
return new Promise((resolve) => {
setTimeout(async () => {
await Unit.create({
Expand Down

0 comments on commit bc4a1a1

Please sign in to comment.