Skip to content
Draft
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
664 changes: 657 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions packages/remove-passwords/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"env": {
"es2020": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"plugin:jsdoc/recommended",
"plugin:import/recommended",
"plugin:import/typescript"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["@typescript-eslint", "jsdoc", "import"],
"rules": {
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double", { "allowTemplateLiterals": true }],
"semi": ["error", "always"],
"prefer-const": "error",
"eqeqeq": ["error", "always"],
"curly": ["error"],
"require-atomic-updates": ["error"],
"no-var": ["error"],
"camelcase": ["error"],
"init-declarations": ["error", "always"],
"require-await": ["error"],
"no-param-reassign": ["error"],
"jsdoc/require-jsdoc": [
"error",
{
"require": {
"ArrowFunctionExpression": true,
"ClassDeclaration": true,
"ClassExpression": true,
"FunctionDeclaration": true,
"FunctionExpression": true,
"MethodDefinition": true
},
"publicOnly": true
}
],
"jsdoc/require-description-complete-sentence": "error",
"import/first": "error",
"import/exports-last": "error",
"import/newline-after-import": "error",
"import/order": [
"error",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type",
"unknown"
],
"newlines-between": "always",
"alphabetize": {
"order": "asc",
"caseInsensitive": true
}
}
]
}
}
5 changes: 5 additions & 0 deletions packages/remove-passwords/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"endOfLine": "lf",
"useTabs": false,
"singleQuote": false
}
34 changes: 34 additions & 0 deletions packages/remove-passwords/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "remove-passwords",
"version": "1.0.0",
"description": "Script to remove the unused password field from user",
"main": "prod/index.js",
"scripts": {
"build": "tsc",
"lint": "eslint src --max-warnings 0",
"start": "node -r dotenv/config prod/index.js",
"test": "echo \"No tests yet\"",
"dev": "nodemon src/index.ts"
},
"devDependencies": {
"@types/inquirer": "^8.2.1",
"@typescript-eslint/eslint-plugin": "5.30.7",
"@typescript-eslint/parser": "5.30.7",
"eslint": "8.19.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-jsdoc": "38.1.6",
"eslint-plugin-prettier": "4.2.1",
"nodemon": "^2.0.19",
"prettier": "2.7.1",
"ts-node": "^10.9.1",
"typescript": "4.7.4"
},
"author": "Naomi Carrigan",
"license": "BSD-3-Clause",
"dependencies": {
"dotenv": "^16.0.1",
"inquirer": "^8.2.0",
"mongodb": "^4.8.1"
}
}
55 changes: 55 additions & 0 deletions packages/remove-passwords/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { MongoClient } from "mongodb";
import Spinnies from "spinnies";

import { userSchema } from "./schema";

const spinnies = new Spinnies({
spinner: {
interval: 80,
frames: [
"▰▱▱▱▱▱▱",
"▰▰▱▱▱▱▱",
"▰▰▰▱▱▱▱",
"▰▰▰▰▱▱▱",
"▰▰▰▰▰▱▱",
"▰▰▰▰▰▰▱",
"▰▰▰▰▰▰▰",
"▰▱▱▱▱▱▱",
],
},
});

(async () => {
const dbClient = await MongoClient.connect(process.env.MONGO_URI as string, {
replicaSet: "atlas-axsdig-shard-0",
maxPoolSize: 20,
});
console.log("Connected to MongoDB");

const db = dbClient.db("freecodecamp");
const users = db.collection("user");

const stream = users
.find({
password: { $exists: true },
})
.batchSize(50)
.stream();

spinnies.add("query", {
color: "magenta",
text: "Running database query...",
});

stream.on("data", (document: userSchema) => {
stream.pause();
spinnies.update("query", { text: `Processing user ${document._id}` });
users.updateOne({ _id: document._id }, { $unset: { password: true } });
stream.resume();
});

stream.on("end", () => {
dbClient.close();
spinnies.succeed("query", { text: "All done!" });
});
})();
37 changes: 37 additions & 0 deletions packages/remove-passwords/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Document } from "mongodb";

export interface userSchema extends Document {
password: string;
email: string;
emailVerified: boolean;
externalId: string;
unsubscribeId: string;
progressTimestamps: number[];
isBanned: boolean;
isCheater: boolean;
username: string;
acceptedPrivacyTerms: boolean;
currentChallengeId: string;
isHonest: boolean;
isFrontEndCert: boolean;
isDataVisCert: boolean;
isBackEndCert: boolean;
isFullStackCert: boolean;
isRespWebDesignCert: boolean;
is2018DataVisCert: boolean;
isFrontEndLibsCert: boolean;
isJsAlgoDataStructCert: boolean;
isApisMicroservicesCert: boolean;
isInfosecQaCert: boolean;
isQaCertV7: boolean;
isInfosecCertV7: boolean;
is2018FullStackCert: boolean;
isSciCompPyCertV7: boolean;
isDataAnalysisPyCertV7: boolean;
isMachineLearningPyCertV7: boolean;
completedChallenges: {
id: string;
completedDate: number;
solution: string;
}[];
}
1 change: 1 addition & 0 deletions packages/remove-passwords/src/spinnies.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module "spinnies";
13 changes: 13 additions & 0 deletions packages/remove-passwords/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES6",
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./prod",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true
}
}