Skip to content

Commit

Permalink
refactor(lodash): Replace uses of _assignIn/extend with native util f… (
Browse files Browse the repository at this point in the history
#883)

* refactor(lodash): Replace uses of _assignIn/extend with native util function

* docs: Add docs for attachment and infoitem

* style: format code with clang-format

* style: format code with prettier


Signed-off-by: Ciarán <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
bubonicfred and restyled-commits authored Jul 10, 2024
1 parent b0ea18d commit bc9fa05
Show file tree
Hide file tree
Showing 18 changed files with 376 additions and 235 deletions.
3 changes: 2 additions & 1 deletion client/helpers/confirmationDialog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { _ } from "lodash";
import { Blaze } from "meteor/blaze";
import { Template } from "meteor/templating";
import { i18n } from "meteor/universe:i18n";

import { Util as _ } from "./utils";

const DIALOG_TEMPLATE = Template.confirmationDialog;

export class ConfirmationDialog {
Expand Down
4 changes: 2 additions & 2 deletions client/templates/topic/topicEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { configureSelect2Responsibles } from "/imports/client/ResponsibleSearch"
import { MeetingSeries } from "/imports/meetingseries";
import { Minutes } from "/imports/minutes";
import { Topic } from "/imports/topic";
import { _ } from "lodash";
import { $ } from "meteor/jquery";
import { Meteor } from "meteor/meteor";
import { Session } from "meteor/session";
import { Template } from "meteor/templating";

import { Util as _ } from "../../../imports/helpers/utils";
import { IsEditedService } from "../../../imports/services/isEditedService";
import { isEditedHandling } from "../../helpers/isEditedHelpers";

Expand Down Expand Up @@ -66,7 +66,7 @@ Template.topicEdit.events({
const editTopic = getEditTopic();
const topicDoc = {};
if (editTopic) {
_.extend(topicDoc, editTopic._topicDoc);
_.assignIn(topicDoc, editTopic._topicDoc);
}

let labels = tmpl.$("#id_item_selLabels").val();
Expand Down
2 changes: 1 addition & 1 deletion client/templates/topic/topicInfoItemEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Minutes } from "/imports/minutes";
import { Priority } from "/imports/priority";
import { Topic } from "/imports/topic";
import { User, userSettings } from "/imports/user";
import { _ } from "lodash";
import { Meteor } from "meteor/meteor";
import { ReactiveDict } from "meteor/reactive-dict";
import { ReactiveVar } from "meteor/reactive-var";
Expand All @@ -16,6 +15,7 @@ import { i18n } from "meteor/universe:i18n";
import moment from "moment/moment";
import isEmail from "validator/lib/isEmail";

import { _ } from "../../../imports/helpers/utls";
import { IsEditedService } from "../../../imports/services/isEditedService";
import { ConfirmationDialogFactory } from "../../helpers/confirmationDialogFactory";
import { isEditedHandling } from "../../helpers/isEditedHelpers";
Expand Down
58 changes: 54 additions & 4 deletions imports/attachment.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { _ } from "lodash";

import { AttachmentsCollection } from "./collections/attachments_private";
import { Util as _ } from "./helpers/utils";
import { Minutes } from "./minutes";
import { UserRoles } from "./userroles";

/**
* Represents an attachment in the system.
*/
export class Attachment {
/**
* Represents an Attachment object.
*
* @param {string} attachmentID - The ID of the attachment.
*/
constructor(attachmentID) {
this._roles = new UserRoles(this.userId);
if (!this._roles) {
Expand All @@ -18,19 +25,39 @@ export class Attachment {
}
}

// ********** static methods ****************
/**
* Finds attachments for a given meeting minutes ID.
*
* @param {string} minID - The ID of the meeting minutes.
* @returns {Mongo.Cursor} - A cursor pointing to the attachments found.
*/
static findForMinutes(minID) {
return AttachmentsCollection.find({ "meta.meetingminutes_id": minID });
}

/**
* Returns the total count of all attachments in the collection.
*
* @returns {number} The count of attachments.
*/
static countAll() {
return AttachmentsCollection.find().count();
}

/**
* Returns the count of attachments associated with a given minute ID.
*
* @param {string} minID - The ID of the minute.
* @returns {number} The count of attachments.
*/
static countForMinutes(minID) {
return Attachment.findForMinutes(minID).count();
}

/**
* Calculates the total size of all attachments in the collection.
* @returns {number} The total size of all attachments in bytes.
*/
static countAllBytes() {
const atts = AttachmentsCollection.find({}, { size: 1 });
let sumBytes = 0;
Expand All @@ -40,6 +67,20 @@ export class Attachment {
return sumBytes;
}

/**
* Uploads a file to the AttachmentsCollection.
*
* @param {string} uploadFilename - The name of the file to be uploaded.
* @param {object} minutesObj - The minutes object to which the file is
* associated.
* @param {object} callbacks - Optional callbacks for different upload events.
* @param {function} callbacks.onStart - Callback function to be called when
* the upload starts.
* @param {function} callbacks.onEnd - Callback function to be called when the
* upload ends.
* @param {function} callbacks.onAbort - Callback function to be called when
* the upload is aborted.
*/
static uploadFile(uploadFilename, minutesObj, callbacks = {}) {
const doNothing = () => {};
callbacks = _.assignIn(
Expand Down Expand Up @@ -77,14 +118,23 @@ export class Attachment {
upload.start();
}

// ********** object methods ****************
/**
* Checks if the current user is the uploader and the owner of the file.
* @returns {boolean} Returns true if the current user is the uploader and the
* owner of the file, otherwise returns false.
*/
isUploaderAndFileOwner() {
return (
this._roles.isUploaderFor(this._file.meta.parentseries_id) &&
this._roles.getUserID() === this._file.userId
);
}

/**
* Checks if the current user is a moderator.
* @returns {boolean} Returns true if the current user is a moderator,
* otherwise false.
*/
isModerator() {
return this._roles.isModeratorOf(this._file.meta.parentseries_id);
}
Expand Down
8 changes: 3 additions & 5 deletions imports/collections/idValidator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from "lodash";
import { Validator } from "meteor/jagi:astronomy";

/**
Expand Down Expand Up @@ -27,10 +26,9 @@ Validator.create({
*/
isValid({ value }) {
if (Array.isArray(value)) {
return _.map(value, (a) => regExId.test(a)).reduce(
(previous, current) => previous && current,
true,
);
return value
.map((a) => regExId.test(a))
.reduce((previous, current) => previous && current, true);
}
return regExId.test(value);
},
Expand Down
Loading

0 comments on commit bc9fa05

Please sign in to comment.