diff --git a/.eslintrc.js b/.eslintrc.js index 47d4e4f..885e908 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,7 @@ module.exports = { "ignoreRestSiblings": true } ], - 'no-undef': 'warn', + 'no-undef': 'off', 'semi': ['warn', 'always'], 'no-multi-spaces': 'warn', 'no-trailing-spaces': 'warn', @@ -26,7 +26,7 @@ module.exports = { 'func-style': ['warn', 'declaration', { 'allowArrowFunctions': true }], 'camelcase': 'warn', '@typescript-eslint/explicit-function-return-type': ['warn', { allowExpressions: true }], - '@typescript-eslint/explicit-member-accessibility': ['warn', { accessibility: 'explicit' }], + '@typescript-eslint/explicit-member-accessibility': ['off', { accessibility: 'explicit' }], 'no-unused-vars': 'warn', 'no-extra-semi': 'warn', }, diff --git a/package.json b/package.json index 70d4bec..969c161 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "@types/jest": "^29.5.12", "@types/jsend": "^1.0.32", "@types/morgan": "^1.9.9", + "@types/supertest": "^6.0.2", "@types/winston": "^2.4.4", "@typescript-eslint/eslint-plugin": "^7.7.1", "@typescript-eslint/parser": "^7.7.1", @@ -60,24 +61,5 @@ "ts-jest": "^29.1.2", "typescript": "^5.4.5", "typescript-eslint": "^7.7.1" - }, - "eslintConfig": { - "root": true, - "env": { - "node": true, - "es6": true - }, - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended" - ], - "parserOptions": { - "ecmaVersion": 2021, - "sourceType": "module" - }, - "rules": { - "@typescript-eslint/no-unused-vars": "error", - "@typescript-eslint/explicit-module-boundary-types": "off" - } } } diff --git a/src/index.ts b/src/index.ts index c090dcb..f51225b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,18 +13,13 @@ const port = process.env.PORT as string; app.use(express.json()); app.use(cors({ origin: "*" })); - +app.use(router); +addDocumentation(app); app.all('*', (req: Request,res: Response,next) =>{ const error = new CustomError(`Can't find ${req.originalUrl} on the server!`,404); error.status = 'fail'; next(error); }); - -addDocumentation(app); -app.get("/api/v1", (req: Request, res: Response) => { - res.send("Knights Ecommerce API"); -}); -app.use(router); app.use(errorHandler); //morgan @@ -33,6 +28,6 @@ app.use(morgan(morganFormat)); -app.listen(port, () => { +export const server = app.listen(port, () => { console.log(`[server]: Server is running at http://localhost:${port}`); }); diff --git a/src/routes/index.ts b/src/routes/index.ts index 8ae7a19..78cb97d 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,9 +1,13 @@ import { Request, Response, Router } from 'express'; import { responseSuccess } from '../utils/response.utils'; const router = Router(); +router.get("/", (req: Request, res: Response) => { + res.send("Knights Ecommerce API"); +}); router.get('/api/v1/status', (req: Request, res: Response) => { return responseSuccess(res, 202, 'This is a testing route that returns: 201'); }); + // All routes should be imported here and get export after specifying first route // example router.use("/stock". stockRoutes) =>:: First import stockRoutes and use it here, This shows how the route export will be handled diff --git a/tsconfig.json b/tsconfig.json index bfaf5b0..7d6a779 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,7 +29,7 @@ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ - "types": ["node"] /* Specify type package names to be included without being referenced in a source file. */, + "types": ["node", "jest"] /* Specify type package names to be included without being referenced in a source file. */, // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */