Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tidy: invert negated calls to Option.isEmpty()/isDefined() #1289

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/http/preprocessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const emptyAuthInjector = ({ Auth }, context) => context.with({ auth: Auth.by(nu
const authHandler = ({ Sessions, Users, Auth }, context) => {
const authBySessionToken = (token, onFailure = noop) => Sessions.getByBearerToken(token)
.then((session) => {
if (!session.isDefined()) return onFailure();
if (session.isEmpty()) return onFailure();
return context.with({ auth: Auth.by(session.get()) });
});

Expand Down Expand Up @@ -120,7 +120,7 @@ const authHandler = ({ Sessions, Users, Auth }, context) => {
// if non-GET run authentication as usual but we'll have to check CSRF afterwards.
return maybeSession.then((cxt) => { // we have to use cxt rather than context for the linter
// if authentication failed anyway, just do nothing.
if ((cxt == null) || !cxt.auth.session.isDefined()) return;
if ((cxt == null) || cxt.auth.session.isEmpty()) return;

const csrf = urlDecode(cxt.body.__csrf);
if (csrf.isEmpty() || isBlank(csrf.get()) || (cxt.auth.session.get().csrf !== csrf.get())) {
Expand Down
10 changes: 5 additions & 5 deletions lib/model/query/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss

// Get version of entity on the server
let serverEntity = await Entities.getById(dataset.id, clientEntity.uuid, QueryOptions.forUpdate);
if (!serverEntity.isDefined()) {
if (serverEntity.isEmpty()) {
// We probably never get into this case because computeBaseVersion also checks for the existence of the entity
// and returns an entity def associated with a top level entity.
throw Problem.user.entityNotFound({ entityUuid: clientEntity.uuid, datasetName: dataset.name });
Expand Down Expand Up @@ -363,7 +363,7 @@ const _computeBaseVersion = (eventId, dataset, clientEntity, submissionDef, forc
const condition = { version: clientEntity.def.baseVersion };
const maybeDef = await Entities.getDef(dataset.id, clientEntity.uuid, new QueryOptions({ condition }));

if (!maybeDef.isDefined()) {
if (maybeDef.isEmpty()) {
// If the def doesn't exist, check if the version doesnt exist or the whole entity doesnt exist
// There are different problems for each case
const maybeEntity = await Entities.getById(dataset.id, clientEntity.uuid);
Expand All @@ -388,7 +388,7 @@ const _computeBaseVersion = (eventId, dataset, clientEntity, submissionDef, forc

const baseEntityVersion = await Entities.getDef(dataset.id, clientEntity.uuid, new QueryOptions({ condition }));

if (!baseEntityVersion.isDefined()) {
if (baseEntityVersion.isEmpty()) {
if (forceOutOfOrderProcessing) {
// If the base version doesn't exist but we forcing the update anyway, use the latest version on the server as the base.
// If that can't be found, throw an error for _processSubmissionEvent to catch so it can try create instead of update.
Expand Down Expand Up @@ -424,7 +424,7 @@ const _processSubmissionEvent = (event, parentEvent) => async ({ Audits, Dataset

const form = await Forms.getByActeeId(event.acteeId);
// If form is deleted/purged then submission won't be there either.
if (!form.isDefined())
if (form.isEmpty())
return null;

const existingEntity = await Entities.getDefBySubmissionId(submissionId);
Expand All @@ -442,7 +442,7 @@ const _processSubmissionEvent = (event, parentEvent) => async ({ Audits, Dataset
const submission = await Submissions.getSubAndDefById(submissionDefId);

// If Submission is deleted/purged - Safety check, will not be true at this line
if (!submission.isDefined())
if (submission.isEmpty())
return null;

// Don't process draft submissions
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function errorToFrontend(req, res, errorCode) {

async function getUserByEmail({ Users }, email) {
const userOption = await Users.getByEmail(email);
if (!userOption.isDefined()) return;
if (userOption.isEmpty()) return;

const user = userOption.get();

Expand Down
3 changes: 1 addition & 2 deletions lib/task/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// except according to the terms contained in the LICENSE file.

const config = require('config');
const { isEmpty } = require('ramda');

const { task } = require('./task');
const { buildSubmission } = require('../data/analytics');
Expand All @@ -25,7 +24,7 @@ const runAnalytics = task.withContainer(({ Analytics, Audits, odkAnalytics }) =>
.then((configuration) => ((configuration.value.enabled === false)
? { sent: false, message: 'Analytics disabled in config' }
: Analytics.getLatestAudit()
.then((au) => ((!isEmpty(au) && au.value.details.success === true && !force)
.then((au) => ((au.isDefined() && au.value.details.success === true && !force)
? { sent: false, message: `Analytics sent recently: ${au.value.loggedAt}` }
: Analytics.previewMetrics()
.then((data) => {
Expand Down