Skip to content

Commit

Permalink
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
"eslint:fix": "npm run eslint -- --fix",
"test": "npm run test-unit && npm run test-integration && npm run test-repository",
"test-unit": "NODE_ENV=test mocha -r dotenv/config --env dotenv_config_path=.env.test --exit ./server/models/**/*.spec.js ./server/routes/**/*.spec.js",
"test-repository": "NODE_ENV=test mocha -r dotenv/config --exit ./server/infra/repositories/**/*.spec.js",
"test-repository": "NODE_ENV=test mocha -r dotenv/config --env dotenv_config_path=.env.test --exit ./server/infra/repositories/**/*.spec.js",
"server": "nodemon server/server.js",
"test-seedDB": "NODE_ENV=test mocha -r dotenv/config --env dotenv_config_path=.env.test --timeout 10000 './**/*.spec.js'",
"test-integration": "NODE_ENV=test mocha -r dotenv/config --env dotenv_config_path=.env.test --exit --timeout 20000 --recursive './server/__tests__/'",
11 changes: 1 addition & 10 deletions server/handlers/captureHandler.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ const capturePostSchema = Joi.object({
const captureGetQuerySchema = Joi.object({
tree_id: Joi.string().uuid(),
tree_associated: Joi.boolean(),
planting_organization_id: Joi.string().uuid(),
organization_ids: Joi.array().items(Joi.string().uuid()),
captured_at_start_date: Joi.date().iso(),
captured_at_end_date: Joi.date().iso(),
grower_account_id: Joi.string().uuid(),
@@ -178,15 +178,6 @@ const captureHandlerSingleGet = async function (req, res) {
id: req.params.capture_id,
},
});
const result = await captureRepo.getByFilter({
parameters: {
id: req.params.capture_id,
},
});

console.log('=======================\n\n\n\n\n');
console.log(result);
console.log('\n\n\n\n\n\n=========================');

res.send(Capture(capture));
};
11 changes: 10 additions & 1 deletion server/infra/repositories/CaptureRepository.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,12 @@ class CaptureRepository extends BaseRepository {
async getByFilter(filterCriteria, options = {}) {
const whereBuilder = function (object, builder) {
const result = builder;
const { parameters, whereNulls = [], whereNotNulls = [] } = { ...object };
const {
parameters,
whereNulls = [],
whereNotNulls = [],
whereIns = [],
} = { ...object };
result.whereNot({ status: 'deleted' });
for (const whereNot of whereNotNulls) {
result.whereNotNull(whereNot);
@@ -20,6 +25,10 @@ class CaptureRepository extends BaseRepository {
result.whereNull(whereNull);
}

for (const whereIn of whereIns) {
result.whereIn(whereIn.field, whereIn.values);
}

const filterObject = { ...parameters };

if (filterObject.captured_at_start_date) {
15 changes: 11 additions & 4 deletions server/models/Capture.js
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ const Capture = ({
...(tree_id !== undefined && { tree_associated: !!tree_id }),
tree_id,
status,
tags: tag_array || [],
tags: tag_array || undefined,
captured_at,
});

@@ -110,15 +110,14 @@ const createCapture = (captureRepositoryImpl, eventRepositoryImpl) => async (
const FilterCriteria = ({
tree_id = undefined,
tree_associated = undefined,
planting_organization_id = undefined,
captured_at_start_date = undefined,
captured_at_end_date = undefined,
grower_account_id = undefined,
species_id = undefined,
organization_ids = [],
}) => {
const parameters = Object.entries({
tree_id,
planting_organization_id,
captured_at_start_date,
captured_at_end_date,
grower_account_id,
@@ -132,13 +131,21 @@ const FilterCriteria = ({

const whereNulls = [];
const whereNotNulls = [];
const whereIns = [];

if (organization_ids.length) {
whereIns.push({
field: 'planting_organization_id',
values: [...organization_ids],
});
}

if (tree_associated === 'true') {
whereNotNulls.push('tree_id');
} else if (tree_associated === 'false') {
whereNulls.push('tree_id');
}
return { parameters, whereNulls, whereNotNulls };
return { parameters, whereNulls, whereNotNulls, whereIns };
};

const getCaptures = (captureRepositoryImpl) => async (

0 comments on commit d8a04ea

Please sign in to comment.