Skip to content

Commit df644bd

Browse files
committed
Update packages, add types, remove unused packages, add new helpers, Migrate Eslint v8-->v9
1 parent d925e72 commit df644bd

38 files changed

+1782
-2490
lines changed

.eslintignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.eslintrc

Lines changed: 0 additions & 162 deletions
This file was deleted.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ envs/.env.prod.local
6464

6565
# intelij .idea folder
6666
.idea/
67+
# visual studio code .vscode folder
68+
.vscode/
6769

6870
# mac stupid files
6971
.DS_Store

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [Architecture guide](#architecture-guide)
99

1010
### General info
11+
10.02.25. Updates. Migrate to Eslint v9
1112
25.09.22. Updates. We create a new version of the template. It is already written in Typescript !
1213
12.03.21 Updates. Great news ! :fire: :heart: \
1314
In this template every time we manually create 7 files for one CRUD logic. Now you can create your CRUD new files at once just using `rest-resource-file-generator` npm module made by me :tophat: \
@@ -22,14 +23,14 @@ If you haven't, these are their links for installing.
2223

2324
### Technologies
2425
Program/lib | version | command for checking\
25-
Git | 2.39.3 | `git --version`\
26-
Node.js | v20.8.0 | `node -v` \
27-
Express | ^4.19.2 | see in app package.json\
28-
MongoDB | v7.0.2 | `mongosh` (on MacOS)\
29-
Mongoose | ^8.2.4 | see in this app package.json\
30-
Mocha | ^10.4.0 | see in this app package.json\
31-
Eslint | ^8.57.0 | see in this app package.json\
32-
Yarn | 1.22.19 | `yarn -v`
26+
Git | 2.39.5 | `git --version`\
27+
Node.js | v20.18.1 | `node -v` \
28+
Express | ^4.21.2 | see in app package.json\
29+
MongoDB | v7.0.2 | `mongosh`, then `db.version()` (on MacOS)\
30+
Mongoose | ^8.10.0 | see in this app package.json\
31+
Mocha | ^11.1.0 | see in this app package.json\
32+
Eslint | ^9.20.0 | see in this app package.json\
33+
Yarn | 1.22.22 | `yarn -v`
3334

3435
### Setup
3536
1. Clone this repository\

SECURITY.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Use this section to tell people about which versions of your project are
6+
currently being supported with security updates.
7+
8+
| Version | Supported |
9+
| ------- | ------------------ |
10+
| 5.1.x | :white_check_mark: |
11+
| 5.0.x | :x: |
12+
| 4.0.x | :white_check_mark: |
13+
| < 4.0 | :x: |
14+
15+
## Reporting a Vulnerability
16+
17+
Use this section to tell people how to report a vulnerability.
18+
19+
Tell them where to go, how often they can expect to get an update on a
20+
reported vulnerability, what to expect if the vulnerability is accepted or
21+
declined, etc.

configs/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ import SMTPTransport from 'nodemailer/lib/smtp-transport';
44

55
const rootPath = process.cwd();
66
dotEnvFlow.config({ path: `${rootPath}/envs` });
7+
export const port: number = +process.env.PORT;
8+
9+
if (Number.isNaN(port)) {
10+
throw new Error('The port is NaN');
11+
}
712

813
export const db = {
914
uri: process.env.MONGO_URL,
1015
};
11-
export const port: string = process.env.PORT;
16+
17+
export const nodeEnv = process.env.NODE_ENV;
18+
export const isProd = nodeEnv === 'prod';
19+
export const isStage = nodeEnv === 'stage';
20+
export const isLocal = nodeEnv === 'local';
1221
export const jwtSecret = `${process.env.JWT_SECRET}`;
1322
export const files = `${rootPath}/files`;
1423
export const uploads = `${rootPath}/uploads`;
24+
1525
export const mailOptions: SMTPTransport.Options = {
1626
host: process.env.SMTP_HOST,
1727
port: +process.env.SMTP_PORT,

constants/general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as httpStatus from 'http-status';
1+
import httpStatus from 'http-status';
22

33
const oftenUseCodes = {
44
ok: httpStatus.OK,

controllers/root-ctrl.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import { CustomResponse } from '../middlewares/respond';
44

55
export class RootCtrl {
66
static async getMany(req: Request, res: CustomResponse) {
7-
return res.send({ message: 'get all data' });
7+
res.send({ message: 'get all data' });
8+
9+
return;
810
}
911
static async post(req: Request, res: CustomResponse) {
10-
return res.created({ message: 'create new data' });
12+
res.created({ message: 'create new data' });
13+
14+
return;
1115
}
1216
static async showEjs(req: Request, res: CustomResponse) {
1317
globalThis.io.on('connection', socket => {
@@ -25,5 +29,7 @@ export class RootCtrl {
2529
origin: `${req.protocol}://${req.get('host')}`,
2630
name: req.query.name || 'Eva',
2731
});
32+
33+
return;
2834
}
2935
}

controllers/user-ctrl.ts

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,80 @@ export class UserCtrl {
1212

1313
const users = await UserSrv.readMany(findCriteria, options);
1414

15-
return res.send({
15+
res.send({
1616
data: users,
1717
limit: users.length,
1818
});
19+
20+
return;
1921
}
2022
static async getOne(req: Request, res: CustomResponse) {
2123
const user = await UserSrv.readOne({ _id: req.params._id });
2224

23-
return res.send({
25+
res.send({
2426
data: user,
2527
});
28+
29+
return;
2630
}
2731
static async post(req: Request, res: CustomResponse) {
2832
const { body } = req;
2933
const create = Array.isArray(body) ? UserSrv.createMany : UserSrv.createOne;
3034

3135
const data = await create(body);
3236

33-
return res.created({
37+
res.created({
3438
data,
3539
});
40+
41+
return;
3642
}
3743
static async putOne(req: Request, res: CustomResponse) {
3844
const user = await UserSrv.updateOne(req.params._id, req.body); // change data
3945

40-
return user
41-
? res.accepted({ data: user })
42-
: res.notFound({ errors: [{ message: 'resource not found' }] });
46+
if (user) {
47+
res.accepted({ data: user });
48+
} else {
49+
res.notFound({ errors: [{ message: 'resource not found' }] });
50+
}
4351
}
52+
4453
static async putMany(req: Request, res: CustomResponse) {
4554
const isModified = await UserSrv.updateMany(req.body);
4655

47-
return isModified
48-
? res.accepted({ data: { message: 'updated user by id' } })
49-
: res.notFound({ errors: [{ message: 'resource not found' }] });
56+
if (isModified) {
57+
res.accepted({ data: { message: 'updated user by id' } });
58+
} else {
59+
res.notFound({ errors: [{ message: 'resource not found' }] });
60+
}
5061
}
62+
5163
static async removeOne(req: Request, res: CustomResponse) {
52-
const isDeleted = await UserSrv.deleteOne({ _id: req.params._id });
64+
const isDeleted = await UserSrv.deleteOne({ _id: req.params._id });
5365

54-
return isDeleted ? res.noContent() : res.notFound({ errors: [{ message: 'resource not found' }] });
66+
if (isDeleted) {
67+
res.noContent();
68+
} else {
69+
res.notFound({ errors: [{ message: 'resource not found' }] });
70+
}
5571
}
72+
5673
static async removeMany(req: Request, res: CustomResponse) {
5774
const isDeleted = await UserSrv.deleteMany(req.body.ids);
5875

59-
return isDeleted ? res.noContent() : res.notFound({ errors: [{ message: 'resource not found' }] });
76+
if (isDeleted) {
77+
res.noContent();
78+
} else {
79+
res.notFound({ errors: [{ message: 'resource not found' }] });
80+
}
6081
}
82+
6183
static async showEjs(req: Request, res: CustomResponse) {
6284
res.render('users-page', {
6385
origin: `${req.protocol}://${req.get('host')}`,
6486
name: 'Users',
6587
});
88+
89+
return;
6690
}
6791
}

0 commit comments

Comments
 (0)