Json data structure

by amindunited

HTML

<input id="userIdInput" type="text" placeholder='user id'/>
<button id='searchBtn'>
  Search
</button>

JavaScript

/**
 
 // All of the actions below require that the current user
 // has permission to edit that table or record
 
 // Creates a table, and a table model from given object
 createTable(model);
 
 // update a table with given table name, and data that matches the model
 // When a record is created all of it's refs will be updated with it's id
 addRecord(table, data);
 
 // update a table's data with given table name,
 //	entry id and data that matches the model
 updateRecord(table, id, data);
 
 // When a record is created all of it's refs will be updated with it's id
 // Removes record of id from tableName
 deleteRecord(table, id);
 
 // 
 // Copies record to archives[tableName] and Removes record of id from tableName
 archiveRecord(table, id);
 
 
 // In order to accomplish this,
 // All records have a permissions object.
 
 const permissionsModel = {
 		owners:  [{table: users, ids: []}, {table: groups, ids:[]}],
    authors: [{table: users, ids: []}, {table: groups, ids:[]}],
    editors: [{table: users, ids: []}, {table: groups, ids:[]}],
    readers: [{table: users, ids: []}, {table: groups, ids:[]}]
 }
 
 */

const tableModel = () => {
	'users': {
  	'name': '',
    'refs': {
    	'posts': []
    }
  }	
}

const usersTable = {
	'0': { 
  	id: '0',
    name: 'user 0', 
  	refs: {
    	posts: ['0', '2']
    }
  },
  '1': {
  	id: '1',
    name: 'user 1',
    refs: {
    	posts: ['1', '3']
    }
  },
  '2': { id: '2', name: 'user 2' },
  '3': { id: '3', name: 'user 3' }
};

const postsTable = {
	'0': {
  	authors: ['0'],
    content: 'Lroem Ipsum',
  },
	'1': {
  	authors: ['1'],
    content: 'My First pOst',
  },
	'2': {
  	authors: ['0'],
    content: 'Testing',
  },
	'3': {
  	authors: ['2'],
    content: 'My second Post',
  }
};

const tables = {
	'users': usersTable,
  'posts': postsTable
};

const get = (table, id) => {
  return tables[table][id];
}

const add = (table) => {}

const handleBtnClick = () => {
	const input =...