Skip to content

Commit cfb0b1c

Browse files
committed
[Fix] #36 PRQ Feedback
1 parent f84dde3 commit cfb0b1c

File tree

6 files changed

+26
-16
lines changed

6 files changed

+26
-16
lines changed

.eslintrc.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66
"sourceType": "module",
77
"project": "tsconfig.json"
88
},
9-
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:@typescript-eslint/recommended",
12+
"plugin:jest/recommended"
13+
],
1014
"env": {
1115
"node": true,
1216
"jest/globals": true
1317
},
18+
"plugins": ["jest", "@typescript-eslint"],
1419
"rules": {
15-
//'no-console': 'off',
16-
//'import/prefer-default-export': 'off',
17-
"@typescript-eslint/no-unused-vars": "warn"
20+
//"no-console": "off",
21+
//"import/prefer-default-export": "off",
22+
//"@typescript-eslint/no-unused-vars": "warn"
23+
"jest/no-conditional-expect": "off"
1824
},
1925
"ignorePatterns": ["dist"]
2026
}

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- run: npm ci
2020
- run: npm run build:prod --if-present
21-
- run: npm start
2221
- run: npm test

src/app.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import axios from 'axios';
22

33
describe('Server Status', () => {
44
it('The server is running', async () => {
5-
var serverStatus;
5+
let serverStatus;
66
try {
77
const response = await axios.get('http://localhost');
88
serverStatus = response.status;

src/controller/write.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function errorChecking (req:Request, res:Response, next:NextFunction) {
1010
const errorAsString = new Error(JSON.stringify(errorAsJson));
1111
const hasKeyErrors = errors.array().some(error => error.msg.includes("Key"));
1212

13-
res.status(hasKeyErrors ? 403 : 422); // send forbidden or
13+
res.status(hasKeyErrors ? 403 : 422); // send forbidden or unprocessable content
1414
return next(errorAsString);
1515
}
1616

@@ -23,7 +23,7 @@ function errorChecking (req:Request, res:Response, next:NextFunction) {
2323

2424
//entry.create(req, res);
2525
//const test = process.env.TEST;
26-
res.send(req.query);
26+
// res.send(req.query);
2727

2828
}
2929

src/error.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { Request, Response, NextFunction } from "express";
2-
import logger from '@src/scripts/logger';
3-
42

53
export function notFound(req: Request, res: Response, next: NextFunction) {
64
res.status(404);
@@ -11,11 +9,14 @@ export function notFound(req: Request, res: Response, next: NextFunction) {
119
export function handler(err: Error, req: Request, res: Response<Response.Error>, next: NextFunction) {
1210
const statusCode = res.statusCode !== 200 ? res.statusCode : 500;
1311
res.status(statusCode);
14-
let message = err.message;
12+
13+
let message;
1514
try {
16-
let jsonMessage = JSON.parse(message);
15+
const jsonMessage = JSON.parse(err.message);
1716
message = jsonMessage;
18-
} catch (e) {}
17+
} catch (e) {
18+
message = err.message;
19+
}
1920

2021
const responseBody = {
2122
status: statusCode,

src/scripts/crypt.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
const crypto = require('crypto');
1+
import * as crypto from 'crypto';
22

3-
export const crypt = function (value:string) {
4-
return crypto.createHmac('sha256', process.env.KEYA).update(value).digest("base64");
3+
export const crypt = function (value:string) {
4+
const key = process.env.KEYA;
5+
if (!key) {
6+
throw new Error('KEYA is not defined in the environment variables');
7+
}
8+
return crypto.createHmac('sha256', key).update(value).digest("base64");
59
};

0 commit comments

Comments
 (0)