Skip to content

Commit

Permalink
fix: some id bugs, lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Dec 13, 2021
1 parent 7e94e3c commit 32130fd
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 150 deletions.
2 changes: 1 addition & 1 deletion __tests__/api-tests/seed-data-creation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { v4: uuid } = require('uuid');
const knex = require('../../server/database/knex');
const knex = require('../../database/connection');

const stakeholderOne = Object.freeze({
id: 5000000,
Expand Down
25 changes: 12 additions & 13 deletions __tests__/seed-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const capture = {
id: 999999,
};

const captureB = {
id: 999998,
};
// const captureB = {
// id: 999998,
// };

const token = {
id: 9,
Expand All @@ -36,20 +36,19 @@ const wallet = {
type: 'p',
};

const storyOfThisSeed = `
a capture: #${capture.id}
a token: #${token.id}
capture: #${capture.id}
wallet: #${wallet.id}
uuid: ${token.uuid}
// const storyOfThisSeed = `
// a capture: #${capture.id}

wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id}
// a token: #${token.id}
// capture: #${capture.id}
// wallet: #${wallet.id}
// uuid: ${token.uuid}

Another capture: #${captureB.id}
// wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id}

// Another capture: #${captureB.id}

`;
// `;
// console.debug(
// '--------------------------story of database ----------------------------------',
// storyOfThisSeed,
Expand Down
25 changes: 12 additions & 13 deletions __tests__/seed-spec-example.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const capture = {
id: 999999,
};

const captureB = {
id: 999998,
};
// const captureB = {
// id: 999998,
// };

const token = {
id: 9,
Expand All @@ -36,20 +36,19 @@ const wallet = {
type: 'p',
};

const storyOfThisSeed = `
a capture: #${capture.id}
a token: #${token.id}
capture: #${capture.id}
wallet: #${wallet.id}
uuid: ${token.uuid}
// const storyOfThisSeed = `
// a capture: #${capture.id}

wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id}
// a token: #${token.id}
// capture: #${capture.id}
// wallet: #${wallet.id}
// uuid: ${token.uuid}

Another capture: #${captureB.id}
// wallet #${wallet.id} connected to capture #${capture.id}, get a token #${token.id}

// Another capture: #${captureB.id}

`;
// `;
// console.debug(
// '--------------------------story of database ----------------------------------',
// storyOfThisSeed,
Expand Down
1 change: 1 addition & 0 deletions database/connection.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/order */
const environment = process.env.NODE_ENV || 'development';
const config = require('../knexfile')[environment];
const knex = require('knex')(config);
Expand Down
8 changes: 3 additions & 5 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const path = require('path');
const connection = require('./config/config').connectionString;

console.log('connection', connection);

module.exports = {
development: {
client: 'postgresql',
connection,
searchPath: [process.env.DATABASE_SCHEMA],
searchPath: [process.env.DATABASE_SCHEMA, 'public'],
pool: {
min: 1,
max: 10,
Expand All @@ -23,7 +21,7 @@ module.exports = {
staging: {
client: 'postgresql',
connection,
searchPath: [process.env.DATABASE_SCHEMA],
searchPath: [process.env.DATABASE_SCHEMA, 'public'],
pool: {
min: 1,
max: 10,
Expand All @@ -39,7 +37,7 @@ module.exports = {
production: {
client: 'postgresql',
connection,
searchPath: [process.env.DATABASE_SCHEMA],
searchPath: [process.env.DATABASE_SCHEMA, 'public'],
pool: {
min: 1,
max: 10,
Expand Down
26 changes: 0 additions & 26 deletions server/database/knex.js

This file was deleted.

27 changes: 11 additions & 16 deletions server/handlers/stakeholderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ const stakeholderGetUnlinked = async function (req, res) {
Number(stakeholder_id),
);
const result = await executeGetStakeholder();
console.log('result', result.stakeholders.length);
res.send(result);
res.end();
};
Expand All @@ -97,21 +96,18 @@ const stakeholderUpdateLink = async function (req, res, next) {

// only fields that are required to have a value
const updateStakeholderSchema = Joi.object({
id: Joi.number().required(),
type: Joi.string().required(),
linked: Joi.boolean().required(),
});

console.log('req.body', req.body);

try {
// const value = await updateStakeholderSchema
// .unknown(true)
// .validateAsync(req.body, {
// abortEarly: false,
// });
const value = await updateStakeholderSchema
.unknown(true)
.validateAsync(req.body, {
abortEarly: false,
});

const result = await executeUpdateLink(req.body);
const result = await executeUpdateLink(value);

res.send(result);
res.end();
Expand All @@ -123,7 +119,7 @@ const stakeholderUpdateLink = async function (req, res, next) {
}
};

const stakeholderPost = async function (req, res, next) {
const stakeholderPost = async function (req, res) {
const { stakeholder_id } = req.params;
const session = new Session();
const stakeholderRepo = new StakeholderRepository(session);
Expand All @@ -149,11 +145,10 @@ const stakeholderPost = async function (req, res, next) {
});

// await session.beginTransaction();
const { newStakeholder /*raisedEvents*/ } = await executeCreateStakeholder({
...value,
});

console.log('STAKEHOLDER ROUTER newStakeholder', value, newStakeholder);
const { newStakeholder /* raisedEvents */ } =
await executeCreateStakeholder({
...value,
});

// await session.commitTransaction();
// raisedEvents.forEach((domainEvent) =>
Expand Down
2 changes: 1 addition & 1 deletion server/models/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

const knex = require('../database/knex');
const knex = require('../../database/connection');

class Session {
constructor() {
Expand Down
14 changes: 2 additions & 12 deletions server/models/Stakeholder.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const getAllStakeholders =
async ({ filter: { where, order }, ...idFilters } = undefined, url) => {
let filter = {};
filter = FilterCriteria({ ...idFilters, ...where });
console.log('getAllStakeholders --> WHERE, FILTER ------> ', where, filter);
// use default limit and offset values until there is more info on whether used & how updated
let options = { limit: 100, offset: 0 };
options = {
Expand Down Expand Up @@ -238,7 +237,6 @@ const getStakeholders =
async ({ filter: { where, order }, ...idFilters } = undefined, url) => {
let filter = {};
filter = FilterCriteria({ ...idFilters, ...where });
console.log('getStakeholders --> WHERE, FILTER ------> ', where, filter);
// use default limit and offset values until there is more info on whether used & how updated
let options = { limit: 100, offset: 0 };
options = {
Expand Down Expand Up @@ -314,18 +312,16 @@ const updateLinkStakeholder =
);

const foundStakeholder = await stakeholderRepo.getStakeholderById(
object.id,
object.data.id,
);

// confirm stakeholder is related (it is allowed to edit) OR just that it exists (if no id provided) before updating
// confirm stakeholder exists before updating
if (foundStakeholder.stakeholder.email) {
const stakeholderRelation = await stakeholderRepo.updateLinkStakeholder(
acctStakeholder.stakeholder.stakeholder_uuid,
object,
);

console.log('updated link -------> ', stakeholderRelation);

return stakeholderRelation;
}

Expand Down Expand Up @@ -357,8 +353,6 @@ const updateStakeholder =
updateObj,
);

// console.log('updated stakeholder -------> ', stakeholder);

return StakeholderTree({ ...stakeholder, children, parents });
}

Expand All @@ -371,15 +365,11 @@ const createStakeholder =
// const { relation = null, ...obj } = requestBody;
const stakeholderObj = StakeholderPostObject({ ...requestBody });

console.log('stakeholderObj ---->', stakeholderObj);

const stakeholder = await stakeholderRepo.createStakeholder(
acctStakeholder_id,
stakeholderObj,
);

console.log('created ---->', stakeholder);

// const linked = await stakeholderRepo.linkStakeholder(
// acctStakeholder_id,
// relation,
Expand Down
6 changes: 3 additions & 3 deletions server/repositories/BaseRepository.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { expect } = require('chai');
const mockKnex = require('mock-knex');
const BaseRepository = require('./BaseRepository');
const knex = require('../database/knex');
const knex = require('../../database/connection');

const tracker = mockKnex.getTracker();
const Session = require('../models/Session');
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('BaseRepository', () => {
tracker.uninstall();
tracker.install();
tracker.on('query', (query) => {
console.log('sql:', query.sql);
// console.log('sql:', query.sql);
expect(query.sql).match(
/select.*testTable.*where.*c1.*=.*or.*c2.*=.*or.*c3.*and.*c4.*/,
) || expect(query.sql).match(/select.*.count.*entity.*/);
Expand Down Expand Up @@ -239,7 +239,7 @@ describe('BaseRepository', () => {
tracker.uninstall();
tracker.install();
tracker.on('query', (query) => {
console.log('sql:', query.sql);
// console.log('sql:', query.sql);
expect(query.sql).match(
/select.*testTable.*where.*c3.*=.*and.*c4.*=.*or.*c3.*and.*c4.*/,
) || expect(query.sql).match(/select.*.count.*entity.*/);
Expand Down
Loading

0 comments on commit 32130fd

Please sign in to comment.