Skip to content

Commit

Permalink
refactor: fixing code climate major issues, step 8
Browse files Browse the repository at this point in the history
  • Loading branch information
brecke committed Dec 9, 2021
1 parent cc02d52 commit 2e2d90a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
51 changes: 29 additions & 22 deletions packages/oae-discussions/lib/internal/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

import { promisify, callbackify, format } from 'node:util';
import _ from 'underscore';
import { map, forEach, isEmpty, when, toString, pipe, prop, defaultTo, mergeAll, of } from 'ramda';
import { map, forEach, isEmpty, when, toString, pipe, prop, defaultTo, mergeAll, of, mergeRight } from 'ramda';
import ShortId from 'shortid';

import * as AuthzUtil from 'oae-authz/lib/util.js';
import { runQuery, constructUpsertCQL, rowToHash, iterateAll as iterateResults } from 'oae-util/lib/cassandra.js';
import { logger } from 'oae-logger';
import * as OaeUtil from 'oae-util/lib/util.js';
import { getNumberParam } from 'oae-util/lib/util.js';
import * as TenantsAPI from 'oae-tenants';

import { Discussion } from 'oae-discussions/lib/model.js';
Expand Down Expand Up @@ -208,16 +208,19 @@ const iterateAll = function (properties, batchSize, onEach, callback) {
* @api private
*/
const _storageHashToDiscussion = function (discussionId, hash) {
return new Discussion(
TenantsAPI.getTenant(hash.tenantAlias),
discussionId,
hash.createdBy,
hash.displayName,
hash.description,
hash.visibility,
OaeUtil.getNumberParam(hash.created),
OaeUtil.getNumberParam(hash.lastModified)
);
let { tenantAlias, createdBy, displayName, description, visibility, created, lastModified } = hash;
created = getNumberParam(created);
lastModified = getNumberParam(lastModified);

return new Discussion(TenantsAPI.getTenant(tenantAlias), {
id: discussionId,
createdBy,
displayName,
description,
visibility,
created,
lastModified
});
};

/**
Expand All @@ -229,16 +232,20 @@ const _storageHashToDiscussion = function (discussionId, hash) {
* @api private
*/
const _createUpdatedDiscussionFromStorageHash = function (discussion, hash) {
return new Discussion(
discussion.tenant,
discussion.id,
discussion.createdBy,
hash.displayName || discussion.displayName,
hash.description || discussion.description,
hash.visibility || discussion.visibility,
OaeUtil.getNumberParam(discussion.created),
OaeUtil.getNumberParam(hash.lastModified || discussion.lastModified)
);
discussion = mergeRight(discussion, hash);
let { tenant, id, createdBy, displayName, description, visibility, created, lastModified } = discussion;
created = getNumberParam(created);
lastModified = getNumberParam(lastModified);

return new Discussion(tenant, {
id,
createdBy,
displayName,
description,
visibility,
created,
lastModified
});
};

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/oae-discussions/lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import * as AuthzUtil from 'oae-authz/lib/util.js';
* @param {Number} lastModified The timestamp (millis since epoch) at which the discussion was last modified (or received the last message)
* @return {Discussion} The discussion with the data provided
*/
const Discussion = function (tenant, id, createdBy, displayName, description, visibility, created, lastModified) {
const Discussion = function (tenant, discussionData) {
const { id, createdBy, displayName, description, visibility, created, lastModified } = discussionData;
const { resourceId } = AuthzUtil.getResourceFromId(id);
const that = {};
that.tenant = tenant;
Expand Down

0 comments on commit 2e2d90a

Please sign in to comment.