Skip to content

Commit

Permalink
[Fix] #36 PRQ Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Type-Style committed Jan 24, 2024
1 parent f84dde3 commit 4fe4c9d
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
17 changes: 12 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
"sourceType": "module",
"project": "tsconfig.json"
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended"
],
"env": {
"node": true,
"jest/globals": true
},
"plugins": ["jest", "@typescript-eslint"],
"rules": {
//'no-console': 'off',
//'import/prefer-default-export': 'off',
"@typescript-eslint/no-unused-vars": "warn"
//"no-console": "off",
//"import/prefer-default-export": "off",
//"@typescript-eslint/no-unused-vars": "warn"
"jest/no-conditional-expect": "off"
},
"ignorePatterns": ["dist"]
"ignorePatterns": ["dist", "jest.config.js"]

}
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ jobs:
- uses: actions/checkout@v3
- run: npm ci
- run: npm run build:prod --if-present
- run: npm start
- name: Start server
run: |
npm start &
sleep 5 # Give server some time to start
- run: npm test
2 changes: 1 addition & 1 deletion src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from 'axios';

describe('Server Status', () => {
it('The server is running', async () => {
var serverStatus;
let serverStatus;
try {
const response = await axios.get('http://localhost');
serverStatus = response.status;
Expand Down
4 changes: 2 additions & 2 deletions src/controller/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function errorChecking (req:Request, res:Response, next:NextFunction) {
const errorAsString = new Error(JSON.stringify(errorAsJson));
const hasKeyErrors = errors.array().some(error => error.msg.includes("Key"));

res.status(hasKeyErrors ? 403 : 422); // send forbidden or
res.status(hasKeyErrors ? 403 : 422); // send forbidden or unprocessable content
return next(errorAsString);
}

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

//entry.create(req, res);
//const test = process.env.TEST;
res.send(req.query);
// res.send(req.query);

}

Expand Down
11 changes: 6 additions & 5 deletions src/error.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Request, Response, NextFunction } from "express";
import logger from '@src/scripts/logger';


export function notFound(req: Request, res: Response, next: NextFunction) {
res.status(404);
Expand All @@ -11,11 +9,14 @@ export function notFound(req: Request, res: Response, next: NextFunction) {
export function handler(err: Error, req: Request, res: Response<Response.Error>, next: NextFunction) {
const statusCode = res.statusCode !== 200 ? res.statusCode : 500;
res.status(statusCode);
let message = err.message;

let message;
try {
let jsonMessage = JSON.parse(message);
const jsonMessage = JSON.parse(err.message);
message = jsonMessage;
} catch (e) {}
} catch (e) {
message = err.message;
}

const responseBody = {
status: statusCode,
Expand Down
10 changes: 7 additions & 3 deletions src/scripts/crypt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const crypto = require('crypto');
import * as crypto from 'crypto';

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

0 comments on commit 4fe4c9d

Please sign in to comment.