Skip to content

Commit

Permalink
fix(db): fix the triggers.sql, admin.sql, procedures.sql and correct …
Browse files Browse the repository at this point in the history
…the sql to load debtors and cre

this commit fix the problem of joinning in the entity_map table
  • Loading branch information
DedrickEnc committed Jun 3, 2017
1 parent 816ef56 commit d1b7e30
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion server/controllers/finance/creditors.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function list(req, res, next) {
FROM creditor AS c
JOIN creditor_group AS cg
JOIN account AS a ON c.group_uuid = cg.uuid AND cg.account_id = a.id
LEFT JOIN entity_map map ON map.uuid = c.uuid;
JOIN entity_map map ON map.uuid = c.uuid;
`;

db.exec(sql)
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/finance/debtors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function list(req, res, next) {
SELECT BUID(d.uuid) AS uuid, BUID(d.group_uuid) AS group_uuid,
d.text, map.text as hr_entity
FROM debtor d
LEFT JOIN entity_map map ON map.uuid = d.uuid;
JOIN entity_map map ON map.uuid = d.uuid;
`;

db.exec(sql)
Expand Down
6 changes: 1 addition & 5 deletions server/models/admin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ DELIMITER $$
CREATE PROCEDURE zRecomputeEntityMap()
BEGIN
DELETE FROM entity_map;

-- employee
INSERT INTO entity_map
SELECT employee.debtor_uuid, CONCAT_WS('.', 'EM', employee.id) FROM employee;


-- patient
INSERT INTO entity_map
SELECT patient.uuid, CONCAT_WS('.', 'PA', project.abbr, patient.reference)
Expand Down
2 changes: 0 additions & 2 deletions server/models/procedures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1218,8 +1218,6 @@ CREATE PROCEDURE MergeLocations(

UPDATE debtor_group SET location_id = afterUuid WHERE location_id = beforeUuid;

UPDATE employee SET location_id = afterUuid WHERE location_id = beforeUuid;

UPDATE enterprise SET location_id = afterUuid WHERE location_id = beforeUuid;

-- delete the beforeUuid village and leave the afterUuid village.
Expand Down
4 changes: 2 additions & 2 deletions server/models/triggers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ FOR EACH ROW BEGIN
INSERT INTO entity_map
SELECT new.uuid, CONCAT_WS('.', 'PA', project.abbr, new.reference) FROM project where project.id = new.project_id;

-- debtor entity reference removed to allow for reverse lookups - if debot
-- debtor entity reference removed to allow for reverse lookups - if debit
-- entity is refined this can point directly to the debtor

-- this writes a debtor entity into the entity_map table
Expand Down Expand Up @@ -80,7 +80,7 @@ FOR EACH ROW BEGIN

-- Since employees do not have UUIDs or project associations, we create their mapping by simply concatenating
-- the id with a prefix like this: E.{{employee.id}}.
INSERT INTO entity_map SELECT new.debtor_uuid, CONCAT_WS('.', 'EM', new.id);
INSERT INTO entity_map SELECT new.creditor_uuid, CONCAT_WS('.', 'EM', new.id);
END$$


Expand Down
2 changes: 1 addition & 1 deletion test/integration/debtors.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('(/debtors) The /debtors API', function () {
it('GET /debtors should return a list of all debtors', function () {
return agent.get('/debtors')
.then(function (res) {
helpers.api.listed(res, 3);
helpers.api.listed(res, 2);
})
.catch(helpers.handler);
});
Expand Down

0 comments on commit d1b7e30

Please sign in to comment.