Skip to content

Commit

Permalink
r55 polish, fixed MongoDB ecms
Browse files Browse the repository at this point in the history
- through thoughtful development and continuous discussion, I suggested fixing the design of those calibration app relational tables as the initial design I received has flaws and I convey discussion with points to show the flaws my colleague made in the designing and provide adjustments to resolute.
- From the aspect of database design done right with foreignKey and targetKey, regardless of assistance from ORM: Sequelize, Entity, DAO vs Repository, Hibernate, SQLAlchemy,..., having the tables tightly associated is extremely important for data astraction and encapsulation, as the data is the entry point for the building of our app business logic and there comes inheritance and polymorphism in my development. That can be verified with SQL, MySQL clients like WorkBench, DB Navigator, PHPMyAdmin. Clicking a foreignKey data should navigate us automatically to the view of a data record in the associated table. The tables if not well-associated are often loose, sparse and writing into the tables though might still be proceeded with some hacks like getting the highest index of location table to determine the next location_id for the equipment table but that often results in extra work, querying location table to find that highest index and soon to be chaotic.
- Despite knowhow and knowledge distribution I have been giving, It takes time for peers to have a strong grab of it and be able to come up with a good database design and data structure.
- Only provides more focus to business logic better development and less hassle of building and debugging PHP application
  • Loading branch information
zenithtekla committed Sep 29, 2016
1 parent 26c200c commit 518b28f
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 51 deletions.
108 changes: 98 additions & 10 deletions _vault/design_aspects/ecms.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,109 @@ var mongoose = require('mongoose'),
*/

var Schema1 = new Schema({
equipment_model: String,
asset_number: String,
last_cal: Date,
schedule: Number,
next_cal: Date,
files: [{
id: Number,
name: String,
data: Buffer,
contentType: String
location_id: Number,
equipment_attributes: [{
last_cal: Date ,
schedule: Number ,
next_cal: Date ,
files: {
name: String ,
data: Buffer ,
contentType: String
}
}],
model: String,
location: {
id: Number,
desc: String
}
});

mongoose.model('User', Schema1);
mongoose.model('User', Schema1);

/*
An equipment has a model.
Each model has its own attributes.
equipment_model is a parent to equipment_attributes (children).
The collection above resembles the following:
[
{
"model": "brts32",
"asset_number": "2",
"location_id": 2,
"ECMS_Attributes": [
{
"last_cal": "2012-08-22T07:00:00.000Z",
"schedule": 3,
"next_cal": "2013-08-22T07:00:00.000Z",
"file": {
"type": "Buffer",
"data": [
102,
105,
108,
101,
95,
112,
108,
97,
99,
101,
104,
111,
108,
100,
101,
114
]
}
}
],
"ECMS_Location": {
"desc": "production"
}
},
{
"model": "brts32",
"asset_number": "5",
"location_id": 4,
"ECMS_Attributes": [
{
"last_cal": "2012-08-22T07:00:00.000Z",
"schedule": 3,
"next_cal": "2013-08-22T07:00:00.000Z",
"file": {
"type": "Buffer",
"data": [
102,
105,
108,
101,
95,
112,
108,
97,
99,
101,
104,
111,
108,
100,
101,
114
]
}
}
],
"ECMS_Location": {
"desc": "labroom"
}
}
]
*/
4 changes: 1 addition & 3 deletions modules/calibrates/client/views/equipment.pug
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ block content
table.table.table-striped
thead.thead-inverse
tr
th id
th asset_number
th location_id
th model
th status
tbody
each equipment in equipments
tr
th(scope="row")= equipment.id
td= equipment.asset_number
th(scope="row")= equipment.asset_number
td= equipment.location_id
td= equipment.model
td= equipment.status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,6 @@ exports.createEquipment = function(req,res,next){
};

exports.updateEquipment = function(req,res,next){
// ECMS_Equipment.findOne where: req.params (model:req.params.model, asset_number:req.params.asset_number)
// perform update on Promise
/*utils.findOneMethod(req, res, next, callback);
function callback(result){
console.log(chalk.red('My RESULT '));
console.log(result.dataValues);
req.body.model = req.params.model;
req.body.asset_number = req.params.asset_number;
// SHOULD the location remain unchanged and unchangeable, give it req.body.desc = result.desc;
if (req.body.desc)
ECMS_Location.update(req.body, { where: {id: result.dataValues.location_id}});
if (req.body.file || req.body.schedule)
ECMS_Attribute.update(req.body, { where: { asset_number: result.dataValues.asset_number}});
utils.findOneMethod(req, res, next, function(result){
res.json(result);
});
}*/
utils.updateMethod(req, res, next);
};

Expand Down
45 changes: 25 additions & 20 deletions modules/calibrates/server/routes/calibrates.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,50 @@ module.exports = function(app){
var module_name = app.get('module_name');
var controller = require('../controllers/' + module_name + '.server.controllers');


app.get('/table_equipment', controller.equipment)
.get('/table_main', controller.main)
.get('/table_location', controller.location);

app.route('/equipment')
.get( controller.getEquipment)
// create the entire new model of equipments.
.post( controller.createModel);
app.route('/equipment/:model/:asset_number')
.get(controller.getEquipmentBy)

// UPDATE: update an Equipment by its model & specific asset_number
// allow update of the following fiels: file, schedule for next_cal, location (if necessary,
// for example from stockroom, production to shipping dept SHOULD the requirement-scheduled date be met)
.put(controller.updateEquipment)

// DELETE an Equipment based on model & asset_number, must delete its location
.delete(controller.deleteEquipment)
;
.post( controller.createModel);

app.route('/equipment/:model')
.get(controller.getEquipmentBy)

// CREATE an Equipment based on model, literally adds another asset_number to that existing model
// and also add file, location, last_cal, schedule, ...)

.post(controller.createEquipment)
.post(controller.createEquipment)

// UPDATE model name, only to update model field literally
// .put(controller.updateModel)

// DELETE the entire model
.delete(controller.deleteModel)
.delete(controller.deleteModel)
;
app.route('/asset_number/:asset_number')
.get(controller.getEquipmentBy);
.get(controller.getEquipmentBy)

app.route('/location/:location_id')
// UPDATE: update an Equipment by its specific asset_number
// allow update of the following fiels: file, schedule for next_cal, location (if necessary,
// for example from stockroom, production to shipping dept SHOULD the requirement-scheduled date be met)
.put(controller.updateEquipment)

// DELETE an Equipment based on model & asset_number, must delete its location
.delete(controller.deleteEquipment);

/*
Additional RESTful end-points
*/
app.get('/table_equipment', controller.equipment)
.get('/table_main', controller.main)
.get('/table_location', controller.location);

app.route('/equipment/:model/:asset_number')
.get(controller.getEquipmentBy);

app.route('/location/:location_id')
.get(controller.getEquipmentBy);

/*app.route('/tasks').all(/!* taskPolicy.isAllowed *!/)
.get(controller.list)
Expand Down

0 comments on commit 518b28f

Please sign in to comment.