Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
chore: Create .eslintrc.yml (#4)
Browse files Browse the repository at this point in the history
* chore: Create .eslintrc.yml

* style: Fix linter issues

* deps(Dev): Downgrade typescript version from 4.6.2 to 4.5.5
  • Loading branch information
ardalanamini authored Mar 6, 2022
1 parent 27c62de commit 79bcf4a
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 39 deletions.
28 changes: 28 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
env:
es2021: true
node: true
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
parser: '@typescript-eslint/parser'
parserOptions:
ecmaVersion: latest
sourceType: module
plugins:
- '@typescript-eslint'
rules:
indent:
- error
- 2
linebreak-style:
- error
- unix
quotes:
- error
- double
semi:
- error
- always
comma-dangle:
- error
- always-multiline
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ This section includes the issues, changes & improvements I've made, with the tho
- Outdated dependencies.
> Related dependencies: `body-parser`, `dotenv`, `express`, `mongoose`, `@types/cors`, `@types/express`,
> `@typescript-eslint/eslint-plugin`, `@typescript-eslint/parser`, `eslint`, `ts-node-dev`, `typescript`
>
> Note: As of this moment, the latest `typescript` version
> officially supported by the `@typescript-eslint/typescript-estree` is `4.5.5`
- Not using exact versions for dependencies.
> This issue has somewhat similar effects as the `package-lock.json` issue,
> as `^version` will allow any semver compatible version to be installed.
- Missing `eslint` config.
> The `eslint` config allows to enforce the desired code style among all the contributors.
- Issues in the `src` directory:
- Unused imports. (e.g. unused `lodash` import in the `src/scripts/seed.ts`)
- Using `var` to define variables.
> This way the variable would be defined/redefined globally which could cause problems.
> Instead of `var`, it's best to use `let` or `const`.
### Improvements

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
"seed": "ts-node-dev src/scripts/seed.ts",
"start": "node .build/api.js",
"build": "tsc",
"build:watch": "npm run build -- --watch"
"build:watch": "npm run build -- --watch",
"lint": "eslint src",
"lint:fix": "npm run lint -- --fix"
},
"dependencies": {
"body-parser": "1.19.2",
Expand All @@ -39,6 +41,6 @@
"@typescript-eslint/parser": "5.13.0",
"eslint": "8.10.0",
"ts-node-dev": "1.1.8",
"typescript": "4.6.2"
"typescript": "4.5.5"
}
}
2 changes: 1 addition & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ app.use(profileRouter);
app.use(simulatorRouter);

app.listen(PORT, () =>
console.log(`✅ Ready on port http://localhost:${PORT}`)
console.log(`✅ Ready on port http://localhost:${PORT}`),
);
2 changes: 1 addition & 1 deletion src/models/Favorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const schema = new Schema(
},
{
timestamps: true,
}
},
);

export const Favorite = mongoose.model("Favorite", schema);
2 changes: 1 addition & 1 deletion src/models/Simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const schema = new Schema(
},
{
timestamps: true,
}
},
);

export const Simulator = mongoose.model("Simulator", schema);
6 changes: 3 additions & 3 deletions src/routes/profile.router.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Profile } from "#src/models/Profile.js";
import express from "express";

export var router = express.Router();
export const router = express.Router();

router.get("/api/profile", async (req, res) => {
var profile = await Profile.find().lean();
const profile = await Profile.find().lean();
console.log(profile);
res.json({ profile });
});

router.post("/api/profile", async (req, res) => {
var { email, name, nickname } = req.body;
const { email, name, nickname } = req.body;

let profile = await Profile.findOne({
$or: [{ email }, { nickname }],
Expand Down
16 changes: 8 additions & 8 deletions src/routes/simulator.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ import { Simulator } from "#src/models/Simulator.js";
import cors from "cors";
import express from "express";

var app = express();
const app = express();
app.use(cors());

export var router = express.Router();
export const router = express.Router();

router.get("/api/simulator", async (req, res) => {
var simulator = await Simulator.find().lean();
const simulator = await Simulator.find().lean();
console.log(simulator);
res.json({ simulator });
});

router.get("/api/simulator/:profile_id", async (req, res) => {
console.log("========== ");
let query = {};
var { profile_id } = req.params;
const { profile_id } = req.params;
console.log({ profile_id });
query = { profile_id };
var data = await Simulator.find(query);
const data = await Simulator.find(query);
res.json(data);
});

router.post("/api/simulator/:profile_id", async (req, res) => {
var { profile_id } = req.params;
var newData = {
const { profile_id } = req.params;
const newData = {
...req.body,
profile_id,
};
console.log(newData);
var simulator = await Simulator.create(newData);
const simulator = await Simulator.create(newData);
res.json(simulator);
});
32 changes: 16 additions & 16 deletions src/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import mongoose from "mongoose";
mongoose.connect(DBURL);

const profile = new Profile({
name: `String`,
email: `String`,
capital: `123`,
divisa: `String`,
prefered_cryptocurrency: `String`,
name: "String",
email: "String",
capital: "123",
divisa: "String",
prefered_cryptocurrency: "String",
});
await profile.save();

Expand All @@ -24,22 +24,22 @@ import mongoose from "mongoose";

const simulator = new Simulator({
profile_id: idProfile,
name: `String`,
start_date: `01/05/2021`,
check_date: `01/05/2021`,
cryptocurrency: `String`,
divisa: `String`,
Crypto_price_start: `123`,
Crypto_price_check: `123`,
name: "String",
start_date: "01/05/2021",
check_date: "01/05/2021",
cryptocurrency: "String",
divisa: "String",
Crypto_price_start: "123",
Crypto_price_check: "123",
});
await simulator.save();

const favorite = new Favorite({
profile_id: idProfile,
name: `String`,
favorite1: `String`,
favorite2: `String`,
favorite3: `String`,
name: "String",
favorite1: "String",
favorite2: "String",
favorite3: "String",
});
await favorite.save();

Expand Down

0 comments on commit 79bcf4a

Please sign in to comment.