Skip to content

Commit

Permalink
refactor: Convert more modules to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
bubonicfred committed Jun 18, 2024
1 parent 1e9d09a commit 668db57
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
import { Label } from "/imports/label";
import { Meteor } from "meteor/meteor";

module.exports = {
createLabelIdsReceiver(parentMeetingSeriesId) {
return function getLabelIdsByName(labelName, caseSensitive) {
const label = Label.findLabelsContainingSubstring(
parentMeetingSeriesId,
labelName,
caseSensitive,
);
if (label !== null) {
return label.map((label) => {
return label._id;
});
}
return null;
};
},

createUserIdsReceiver(userName) {
const users =
userName === "me"
? [Meteor.user()]
: Meteor.users.find({ username: { $regex: userName } }).fetch();
if (users) {
return users.map((user) => {
return user._id;
export function createLabelIdsReceiver(parentMeetingSeriesId) {
return function getLabelIdsByName(labelName, caseSensitive) {
const label = Label.findLabelsContainingSubstring(
parentMeetingSeriesId,
labelName,
caseSensitive
);
if (label !== null) {
return label.map((label) => {
return label._id;
});
}
return null;
};
}
export function createUserIdsReceiver(userName) {
const users = userName === "me"
? [Meteor.user()]
: Meteor.users.find({ username: { $regex: userName } }).fetch();
if (users) {
return users.map((user) => {
return user._id;
});
}

return [];
},
};
return [];
}
41 changes: 21 additions & 20 deletions private/exportMeetingSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@
mongodb://localhost:3101/meteor --id icwrCdJjqWpoH9ugQ
*/

const mongo = require("mongodb").MongoClient;
const ExpImpSchema = require("../imports/server/exportimport/expImpSchema");
const ExpImpMeetingSeries = require("../imports/server/exportimport/expImpMeetingseries");
const ExpImpMinutes = require("../imports/server/exportimport/expImpMinutes");
const ExpImpTopics = require("../imports/server/exportimport/expImpTopics");
const ExpImpFileAttachments = require("../imports/server/exportimport/expImpFilesAttachments");
const ExpImpFileDocuments = require("../imports/server/exportimport/expImpFilesDocuments");
const ExpImpUsers = require("../imports/server/exportimport/expImpUsers");
import { MongoClient as mongo } from "mongodb";
import { MADE_FOR_SCHEMA, exportCheck } from "../imports/server/exportimport/expImpSchema";
import { doExport } from "../imports/server/exportimport/expImpMeetingseries";
import { doExport as _doExport } from "../imports/server/exportimport/expImpMinutes";
import { doExport as __doExport } from "../imports/server/exportimport/expImpTopics";
import { doExport as ___doExport } from "../imports/server/exportimport/expImpFilesAttachments";
import { doExport as ____doExport } from "../imports/server/exportimport/expImpFilesDocuments";
import { doExport as _____doExport } from "../imports/server/exportimport/expImpUsers";

const optionParser = require("node-getopt").create([
import { create, bindHelp, showHelp } from "node-getopt";
create([
["i", "id=[ARG]", "ID of meeting series, e.g. icwrCdJjqWpoH9ugQ"],
["m", "mongourl=[ARG]", "Mongo DB url, e.g. mongodb://localhost:3101/meteor"],
["h", "help", "Display this help"],
]);
const arg = optionParser.bindHelp().parseSystem();
const arg = bindHelp().parseSystem();
const mongoUrl = arg.options.mongourl || process.env.MONGO_URL;
const meetingseriesID = arg.options.id;
if (!meetingseriesID) {
optionParser.showHelp();
showHelp();
throw new Error("No --id set for meeting series");
}
if (!mongoUrl) {
optionParser.showHelp();
showHelp();
throw new Error("No --mongourl parameter or MONGO_URL in env");
}
const _connectMongo = function (mongoUrl) {
Expand All @@ -42,29 +43,29 @@ const _connectMongo = function (mongoUrl) {

console.log("");
console.log(
`*** 4Minitz MeetingSeries Export Tool *** (made for schema version: ${ExpImpSchema.MADE_FOR_SCHEMA})`,
`*** 4Minitz MeetingSeries Export Tool *** (made for schema version: ${MADE_FOR_SCHEMA})`,
);
_connectMongo(mongoUrl)
.then((db) => {
return ExpImpSchema.exportCheck(db, meetingseriesID);
return exportCheck(db, meetingseriesID);
})
.then((db) => {
return ExpImpMeetingSeries.doExport(db, meetingseriesID);
return doExport(db, meetingseriesID);
})
.then(({ db, userIDs }) => {
return ExpImpMinutes.doExport(db, meetingseriesID, userIDs);
return _doExport(db, meetingseriesID, userIDs);
})
.then(({ db, userIDs }) => {
return ExpImpTopics.doExport(db, meetingseriesID, userIDs);
return __doExport(db, meetingseriesID, userIDs);
})
.then(({ db, userIDs }) => {
return ExpImpFileAttachments.doExport(db, meetingseriesID, userIDs);
return ___doExport(db, meetingseriesID, userIDs);
})
.then(({ db, userIDs }) => {
return ExpImpFileDocuments.doExport(db, meetingseriesID, userIDs);
return ____doExport(db, meetingseriesID, userIDs);
})
.then(({ db, userIDs }) => {
return ExpImpUsers.doExport(db, meetingseriesID, userIDs);
return _____doExport(db, meetingseriesID, userIDs);
})
.then((db) => db.close())
.catch((error) => {
Expand Down
36 changes: 19 additions & 17 deletions private/importMeetingSeries.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@
mongodb://localhost:3101/meteor --id icwrCdJjqWpoH9ugQ
*/

import { spawnSync } from "child_process";
import { MongoClient as mongo } from "mongodb";
import { bindHelp, create, showHelp } from "node-getopt";
import { ExpImpFileAttachments } from "../imports/server/exportimport/expImpFilesAttachments";
import { ExpImpFileDocuments } from "../imports/server/exportimport/expImpFilesDocuments";
import { ExpImpMeetingSeries } from "../imports/server/exportimport/expImpMeetingseries";
import { ExpImpMinutes } from "../imports/server/exportimport/expImpMinutes";
import { ExpImpSchema } from "../imports/server/exportimport/expImpSchema";
import { ExpImpTopics } from "../imports/server/exportimport/expImpTopics";
import { ExpImpUsers } from "../imports/server/exportimport/expImpUsers";

import ExpImpFileAttachments from "../imports/server/exportimport/expImpFilesAttachments";
import ExpImpFileDocuments from "../imports/server/exportimport/expImpFilesDocuments";
import ExpImpMeetingSeries from "../imports/server/exportimport/expImpMeetingseries";
import ExpImpMinutes from "../imports/server/exportimport/expImpMinutes";
import ExpImpSchema from "../imports/server/exportimport/expImpSchema";
import ExpImpTopics from "../imports/server/exportimport/expImpTopics";
import ExpImpUsers from "../imports/server/exportimport/expImpUsers";

const optionParser = require("node-getopt").create([
create([
["i", "id=[ARG]", "ID of meeting series, e.g. icwrCdJjqWpoH9ugQ"],
["m", "mongourl=[ARG]", "Mongo DB url, e.g. mongodb://localhost:3101/meteor"],
["f", "force", "Force import even if schema mismatch"],
["h", "help", "Display this help"],
]);
const arg = optionParser.bindHelp().parseSystem();
const arg = bindHelp().parseSystem();
const mongoUrl = arg.options.mongourl || process.env.MONGO_URL;
const meetingseriesID = arg.options.id;
if (!meetingseriesID) {
optionParser.showHelp();
showHelp();
throw new Error("No --id set for meeting series");
}
if (!mongoUrl) {
optionParser.showHelp();
showHelp();
throw new Error("No --mongourl parameter or MONGO_URL in env");
}
const _connectMongo = (mongoUrl) =>
Expand All @@ -44,17 +45,17 @@ const _connectMongo = (mongoUrl) =>

console.log("");
console.log(
`*** 4Minitz MeetingSeries Import Tool *** (made for schema version: ${ExpImpSchema.MADE_FOR_SCHEMA})`,
`*** 4Minitz MeetingSeries Import Tool *** (made for schema version: ${ExpImpSchema.MADE_FOR_SCHEMA})`
);
console.log("*** ATTENTION ***");
console.log(
"- This script will import a meeting series and all dependecies to your DB.",
"- This script will import a meeting series and all dependecies to your DB."
);
console.log(
"- This script has to change existing user roles, so users can access the new data.",
"- This script has to change existing user roles, so users can access the new data."
);
console.log(
"- This script may overwrite edited data if you import the same data multiple times.",
"- This script may overwrite edited data if you import the same data multiple times."
);
console.log("So, this script is DANGEROUS!!!");
console.log("Experts only!");
Expand All @@ -64,7 +65,8 @@ console.log("TL;DR - Make sure you have a backup!");
console.log(" e.g.: mongodump -h 127.0.0.1 --port 3101 -d meteor");
console.log("");
console.log("Press ENTER to continue - or Ctrl+C to quit...");
require("child_process").spawnSync("read _ ", {

spawnSync("read _ ", {
shell: true,
stdio: [0, 1, 2],
});
Expand Down
1 change: 0 additions & 1 deletion tests/unit/imports/Minutes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import _ from "lodash";
import proxyquire from "proxyquire";
import sinon from "sinon";

import * as Helpers from "../../../imports/helpers/date";
import * as EmailHelpers from "../../../imports/helpers/email";
import * as SubElements from "../../../imports/helpers/subElements";

Expand Down
4 changes: 0 additions & 4 deletions tests/unit/server/migrations/migrate_v1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { expect } from "chai";
import proxyquire from "proxyquire";
import sinon from "sinon";

import * as Helpers from "../../../../imports/helpers/date";

const MinutesSchema = {
minutes: [],
Expand Down Expand Up @@ -34,15 +33,12 @@ const MeetingSeriesSchema = {
};
MeetingSeriesSchema.getCollection = (_) => MeetingSeriesSchema;

Helpers["@noCallThru"] = true;

const { MigrateV1 } = proxyquire("../../../../server/migrations/migrate_v1", {
"/imports/collections/minutes.schema": { MinutesSchema, "@noCallThru": true },
"/imports/collections/meetingseries.schema": {
MeetingSeriesSchema,
"@noCallThru": true,
},
"/imports/helpers/date": Helpers,
});

/**
Expand Down

0 comments on commit 668db57

Please sign in to comment.