diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..b867ec2 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm check diff --git a/.vscode/settings.json b/.vscode/settings.json index cccef64..6a4b244 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -10,5 +10,8 @@ "editor.defaultFormatter": "biomejs.biome" }, "editor.formatOnSave": true, - "extensions.ignoreRecommendations": true + "extensions.ignoreRecommendations": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "always" + } } diff --git a/README.md b/README.md index 30582e7..b7947b6 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,8 @@ A ledger application for managing bank account transactions, built with TypeScri - [Jest](https://jestjs.io/) - Testing framework - [Biome](https://biomejs.dev/) - Code formatter and linter - [tsup](https://github.com/egoist/tsup) - TypeScript bundler +- [Husky](https://typicode.github.io/husky/) - Git hooks management +- [tsx](https://github.com/esbuild-kit/tsx) - TypeScript execution environment ## Available Scripts diff --git a/biome.json b/biome.json index a35b40c..30ca678 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "$schema": "https://biomejs.dev/schemas/2.0.0-beta.1/schema.json", "vcs": { "enabled": true, "clientKind": "git", @@ -7,14 +7,15 @@ }, "files": { "ignoreUnknown": false, - "ignore": [ - "node_modules", - "dist", - "build", - "coverage", - ".git", - ".vscode", - ".dockerignore" + "includes": [ + "**", + "!**/node_modules", + "!**/dist", + "!**/build", + "!**/coverage", + "!**/.git", + "!**/.vscode", + "!**/.dockerignore" ] }, "formatter": { @@ -23,13 +24,40 @@ "indentWidth": 2, "lineEnding": "lf" }, - "organizeImports": { - "enabled": false + "assist": { + "actions": { + "source": { + "organizeImports": "on" + } + } }, "linter": { "enabled": true, "rules": { - "recommended": true, + "style": { + "useLiteralEnumMembers": "error", + "noCommaOperator": "error", + "useNodejsImportProtocol": "error", + "useAsConstAssertion": "error", + "useNumericLiterals": "error", + "useEnumInitializers": "error", + "useSelfClosingElements": "error", + "useConst": "error", + "useSingleVarDeclarator": "error", + "noUnusedTemplateLiteral": "error", + "useNumberNamespace": "error", + "noInferrableTypes": "error", + "useExponentiationOperator": "error", + "useTemplate": "error", + "noParameterAssign": "error", + "noNonNullAssertion": "error", + "useDefaultParameterLast": "error", + "noArguments": "error", + "useImportType": "error", + "useExportType": "error", + "noUselessElse": "error", + "useShorthandFunctionType": "error" + }, "correctness": { "noUnusedImports": "error", "noUnusedVariables": "error", diff --git a/package.json b/package.json index 7026308..ccc4b79 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "build": "tsup", "dev": "tsx src/index.ts", "watch": "tsx watch --exclude src/**/*.test.ts src/ src/index.ts", - "seed": "tsx src/seeds/seed.ts" + "seed": "tsx src/seeds/seed.ts", + "prepare": "husky" }, "keywords": [ "botkeeper" @@ -29,7 +30,7 @@ "zod": "^3.24.2" }, "devDependencies": { - "@biomejs/biome": "1.9.4", + "@biomejs/biome": "2.0.0-beta.1", "@swc/core": "^1.11.16", "@swc/jest": "^0.2.37", "@types/express": "^5.0.1", @@ -37,6 +38,7 @@ "@types/supertest": "^6.0.3", "@types/swagger-ui-express": "^4.1.8", "dotenv": "^16.4.7", + "husky": "^9.1.7", "jest": "^29.7.0", "mongodb-memory-server": "^10.1.4", "supertest": "^7.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b13de6d..0bb3337 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -25,8 +25,8 @@ importers: version: 3.24.2 devDependencies: '@biomejs/biome': - specifier: 1.9.4 - version: 1.9.4 + specifier: 2.0.0-beta.1 + version: 2.0.0-beta.1 '@swc/core': specifier: ^1.11.16 version: 1.11.16 @@ -48,6 +48,9 @@ importers: dotenv: specifier: ^16.4.7 version: 16.4.7 + husky: + specifier: ^9.1.7 + version: 9.1.7 jest: specifier: ^29.7.0 version: 29.7.0(@types/node@22.13.17)(ts-node@10.9.2(@swc/core@1.11.16)(@types/node@22.13.17)(typescript@5.8.2)) @@ -240,55 +243,55 @@ packages: '@bcoe/v8-coverage@0.2.3': resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@biomejs/biome@1.9.4': - resolution: {integrity: sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==} + '@biomejs/biome@2.0.0-beta.1': + resolution: {integrity: sha512-MqRoy9CbTkrS45zW+S4u8p4kQUIFx0mGUWi789W1R3b1kXYIudEqsTKgXKtTGsI0kWOlvnjuKqwTrabjaGchhQ==} engines: {node: '>=14.21.3'} hasBin: true - '@biomejs/cli-darwin-arm64@1.9.4': - resolution: {integrity: sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==} + '@biomejs/cli-darwin-arm64@2.0.0-beta.1': + resolution: {integrity: sha512-RaGmpNLl5NFooXaoCwvgvcuU6Am/rMZ3R48pQeCVxjrCcz1BIlKLTai5UosiedazW7JbXAvgXdSNizYG7ITlAQ==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [darwin] - '@biomejs/cli-darwin-x64@1.9.4': - resolution: {integrity: sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==} + '@biomejs/cli-darwin-x64@2.0.0-beta.1': + resolution: {integrity: sha512-sTzSshkne7HKZFNfiIhmAji7gjtCBXvkTujZELCZWIZC7oj1Tjw/gvAzbdFj2UyHd5/i90pND4ybFOLQZm9gpg==} engines: {node: '>=14.21.3'} cpu: [x64] os: [darwin] - '@biomejs/cli-linux-arm64-musl@1.9.4': - resolution: {integrity: sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==} + '@biomejs/cli-linux-arm64-musl@2.0.0-beta.1': + resolution: {integrity: sha512-0MPUKzz9uBBxAYSJ+OlFi4+yGwiRcZeFqq39H0MxXCQ9MMpKJFH2Ek72fw8sXwG7Prn7EsW/3u1b7najyn1XGQ==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - '@biomejs/cli-linux-arm64@1.9.4': - resolution: {integrity: sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==} + '@biomejs/cli-linux-arm64@2.0.0-beta.1': + resolution: {integrity: sha512-bxce2O4nooBmp20Ey0+IFIZyy/b0RVnciIQk9euCfAi9evq7SvFtMBYo3YUZej0KIvrau5H7tJk5OqmRJk2l+g==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - '@biomejs/cli-linux-x64-musl@1.9.4': - resolution: {integrity: sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==} + '@biomejs/cli-linux-x64-musl@2.0.0-beta.1': + resolution: {integrity: sha512-dFvisnP1hFpVILNw0PZfs8piBwe8+aykO04Tb/4AJDVVzKkGgJfwSefwo4jqzO/Wk/Zruvhcp1nKbjgRXM+vDg==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - '@biomejs/cli-linux-x64@1.9.4': - resolution: {integrity: sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==} + '@biomejs/cli-linux-x64@2.0.0-beta.1': + resolution: {integrity: sha512-6P/AtJv4hOH8mu8ez0c4UInUpiet9NEoF25+O7OPyb4w6ZHJMp2qzvayJS7TKrTQzE5KUvSiNsACGRz34DzUkg==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - '@biomejs/cli-win32-arm64@1.9.4': - resolution: {integrity: sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==} + '@biomejs/cli-win32-arm64@2.0.0-beta.1': + resolution: {integrity: sha512-0C9YSqWHf2cJGnjKDbLi49xv6H9IfqbDsFav7X557PqwY64O6IKWqcmZzi/PkDFHjQM9opU6uhKapeGKGDxziQ==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [win32] - '@biomejs/cli-win32-x64@1.9.4': - resolution: {integrity: sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==} + '@biomejs/cli-win32-x64@2.0.0-beta.1': + resolution: {integrity: sha512-o8W6+DX0YRjt1kS8Y3ismq6EkjwiVDv7X0TEpfnFywoVG8HoJ7G7/m9r8LM1yE46WI3maPH2A0MoVpQ1ZNG++A==} engines: {node: '>=14.21.3'} cpu: [x64] os: [win32] @@ -1422,6 +1425,11 @@ packages: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + iconv-lite@0.6.3: resolution: {integrity: sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==} engines: {node: '>=0.10.0'} @@ -2624,39 +2632,39 @@ snapshots: '@bcoe/v8-coverage@0.2.3': {} - '@biomejs/biome@1.9.4': + '@biomejs/biome@2.0.0-beta.1': optionalDependencies: - '@biomejs/cli-darwin-arm64': 1.9.4 - '@biomejs/cli-darwin-x64': 1.9.4 - '@biomejs/cli-linux-arm64': 1.9.4 - '@biomejs/cli-linux-arm64-musl': 1.9.4 - '@biomejs/cli-linux-x64': 1.9.4 - '@biomejs/cli-linux-x64-musl': 1.9.4 - '@biomejs/cli-win32-arm64': 1.9.4 - '@biomejs/cli-win32-x64': 1.9.4 - - '@biomejs/cli-darwin-arm64@1.9.4': + '@biomejs/cli-darwin-arm64': 2.0.0-beta.1 + '@biomejs/cli-darwin-x64': 2.0.0-beta.1 + '@biomejs/cli-linux-arm64': 2.0.0-beta.1 + '@biomejs/cli-linux-arm64-musl': 2.0.0-beta.1 + '@biomejs/cli-linux-x64': 2.0.0-beta.1 + '@biomejs/cli-linux-x64-musl': 2.0.0-beta.1 + '@biomejs/cli-win32-arm64': 2.0.0-beta.1 + '@biomejs/cli-win32-x64': 2.0.0-beta.1 + + '@biomejs/cli-darwin-arm64@2.0.0-beta.1': optional: true - '@biomejs/cli-darwin-x64@1.9.4': + '@biomejs/cli-darwin-x64@2.0.0-beta.1': optional: true - '@biomejs/cli-linux-arm64-musl@1.9.4': + '@biomejs/cli-linux-arm64-musl@2.0.0-beta.1': optional: true - '@biomejs/cli-linux-arm64@1.9.4': + '@biomejs/cli-linux-arm64@2.0.0-beta.1': optional: true - '@biomejs/cli-linux-x64-musl@1.9.4': + '@biomejs/cli-linux-x64-musl@2.0.0-beta.1': optional: true - '@biomejs/cli-linux-x64@1.9.4': + '@biomejs/cli-linux-x64@2.0.0-beta.1': optional: true - '@biomejs/cli-win32-arm64@1.9.4': + '@biomejs/cli-win32-arm64@2.0.0-beta.1': optional: true - '@biomejs/cli-win32-x64@1.9.4': + '@biomejs/cli-win32-x64@2.0.0-beta.1': optional: true '@cspotcode/source-map-support@0.8.1': @@ -3810,6 +3818,8 @@ snapshots: human-signals@2.1.0: {} + husky@9.1.7: {} + iconv-lite@0.6.3: dependencies: safer-buffer: 2.1.2 diff --git a/src/app.ts b/src/app.ts index 30cd789..de02629 100644 --- a/src/app.ts +++ b/src/app.ts @@ -1,7 +1,7 @@ import express from 'express'; -import apiRoutes from '@/routes'; -import errorHandler from '@/middleware/errorHandler'; import swaggerUi from 'swagger-ui-express'; +import errorHandler from '@/middleware/errorHandler'; +import apiRoutes from '@/routes'; import swaggerDocument from './../swagger.json'; const app = express(); diff --git a/src/config/environment.ts b/src/config/environment.ts index ebec24c..6358749 100644 --- a/src/config/environment.ts +++ b/src/config/environment.ts @@ -1,5 +1,5 @@ -import { z } from 'zod'; import dotenv from 'dotenv'; +import { z } from 'zod'; dotenv.config(); diff --git a/src/index.ts b/src/index.ts index 5edd347..0697874 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,6 @@ import mongoose from 'mongoose'; - -import loadEnvironment from '@/config/environment'; import { connectDB } from '@/config/database'; +import loadEnvironment from '@/config/environment'; import app from './app'; diff --git a/src/middleware/errorHandler.test.ts b/src/middleware/errorHandler.test.ts index 83d22b4..2e21431 100644 --- a/src/middleware/errorHandler.test.ts +++ b/src/middleware/errorHandler.test.ts @@ -1,6 +1,6 @@ -import type { Request, Response, NextFunction } from 'express'; -import errorHandler from './errorHandler'; +import type { NextFunction, Request, Response } from 'express'; import { StatusCodes } from 'http-status-codes'; +import errorHandler from './errorHandler'; describe('Error Handler Middleware', () => { let mockRequest: Partial; diff --git a/src/middleware/schemaValidator.test.ts b/src/middleware/schemaValidator.test.ts index 1236bc2..329d51f 100644 --- a/src/middleware/schemaValidator.test.ts +++ b/src/middleware/schemaValidator.test.ts @@ -1,6 +1,6 @@ -import type { Request, Response, NextFunction } from 'express'; -import { z } from 'zod'; +import type { NextFunction, Request, Response } from 'express'; import { StatusCodes } from 'http-status-codes'; +import { z } from 'zod'; import schemaValidator from './schemaValidator'; describe('Schema Validator Middleware', () => { diff --git a/src/middleware/schemaValidator.ts b/src/middleware/schemaValidator.ts index c131edd..df7298b 100644 --- a/src/middleware/schemaValidator.ts +++ b/src/middleware/schemaValidator.ts @@ -1,6 +1,6 @@ -import type { Request, Response, NextFunction } from 'express'; -import { type z, ZodError } from 'zod'; +import type { NextFunction, Request, Response } from 'express'; import { StatusCodes } from 'http-status-codes'; +import { ZodError, type z } from 'zod'; type ValidationSchema = { body?: z.ZodType; diff --git a/src/models/Account.test.ts b/src/models/Account.test.ts index 0bbf6e2..8acfb75 100644 --- a/src/models/Account.test.ts +++ b/src/models/Account.test.ts @@ -1,5 +1,5 @@ -import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; +import mongoose from 'mongoose'; import { Account } from './Account'; describe('Account Model', () => { diff --git a/src/models/Transaction.test.ts b/src/models/Transaction.test.ts index feda1de..91e7e30 100644 --- a/src/models/Transaction.test.ts +++ b/src/models/Transaction.test.ts @@ -1,7 +1,7 @@ -import mongoose from 'mongoose'; import { MongoMemoryServer } from 'mongodb-memory-server'; -import { Transaction, TransactionType } from './Transaction'; +import mongoose from 'mongoose'; import { Account, type IAccount } from './Account'; +import { Transaction, TransactionType } from './Transaction'; describe('Transaction Model', () => { let mongoServer: MongoMemoryServer; diff --git a/src/routes/account/create/controller.test.ts b/src/routes/account/create/controller.test.ts index 1573d6a..7d4ae13 100644 --- a/src/routes/account/create/controller.test.ts +++ b/src/routes/account/create/controller.test.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import createAccountController from './controller'; import { Account } from '@/models/Account'; +import createAccountController from './controller'; describe('createAccountController', () => { let req: Partial; diff --git a/src/routes/account/create/controller.ts b/src/routes/account/create/controller.ts index dc7d3de..c7b6014 100644 --- a/src/routes/account/create/controller.ts +++ b/src/routes/account/create/controller.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; export default async (req: Request, res: Response) => { const account = await Account.create(req.body); diff --git a/src/routes/account/create/schema.test.ts b/src/routes/account/create/schema.test.ts index 01c8cc1..e264e4a 100644 --- a/src/routes/account/create/schema.test.ts +++ b/src/routes/account/create/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account create schema', () => { it('should succeed with valid data', () => { diff --git a/src/routes/account/credit/controller.test.ts b/src/routes/account/credit/controller.test.ts index fea8e41..8ce122e 100644 --- a/src/routes/account/credit/controller.test.ts +++ b/src/routes/account/credit/controller.test.ts @@ -1,8 +1,8 @@ import type { Response } from 'express'; -import creditAccountController, { type Request } from './controller'; +import { StatusCodes } from 'http-status-codes'; import { Account } from '@/models/Account'; import { Transaction, TransactionType } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; +import creditAccountController, { type Request } from './controller'; describe('creditAccountController', () => { let req: Partial; diff --git a/src/routes/account/credit/controller.ts b/src/routes/account/credit/controller.ts index 950e8d5..29bc815 100644 --- a/src/routes/account/credit/controller.ts +++ b/src/routes/account/credit/controller.ts @@ -1,9 +1,9 @@ import type { Request as ExpressRequest, Response } from 'express'; +import { StatusCodes } from 'http-status-codes'; +import type { z } from 'zod'; import { Account } from '@/models/Account'; import { Transaction, TransactionType } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; import type schema from './schema'; -import type { z } from 'zod'; export type Request = ExpressRequest, unknown, z.infer>; diff --git a/src/routes/account/credit/schema.test.ts b/src/routes/account/credit/schema.test.ts index 6854285..748ee1d 100644 --- a/src/routes/account/credit/schema.test.ts +++ b/src/routes/account/credit/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account credit schema', () => { it('should validate valid parameters', () => { diff --git a/src/routes/account/debit/controller.test.ts b/src/routes/account/debit/controller.test.ts index fd9e227..5881025 100644 --- a/src/routes/account/debit/controller.test.ts +++ b/src/routes/account/debit/controller.test.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express'; -import debitAccountController from './controller'; +import { StatusCodes } from 'http-status-codes'; import { Account } from '@/models/Account'; import { Transaction, TransactionType } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; +import debitAccountController from './controller'; describe('debitAccountController', () => { let req: Partial; diff --git a/src/routes/account/debit/controller.ts b/src/routes/account/debit/controller.ts index 13f725d..2ac3d54 100644 --- a/src/routes/account/debit/controller.ts +++ b/src/routes/account/debit/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; +import { StatusCodes } from 'http-status-codes'; import { Account } from '@/models/Account'; import { Transaction, TransactionType } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; export default async (req: Request, res: Response) => { const { accountId } = req.params; diff --git a/src/routes/account/debit/schema.test.ts b/src/routes/account/debit/schema.test.ts index 527fb06..df1a827 100644 --- a/src/routes/account/debit/schema.test.ts +++ b/src/routes/account/debit/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account debit schema', () => { it('should validate valid parameters', () => { diff --git a/src/routes/account/delete/controller.test.ts b/src/routes/account/delete/controller.test.ts index fccc24e..2f7975e 100644 --- a/src/routes/account/delete/controller.test.ts +++ b/src/routes/account/delete/controller.test.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express'; -import deleteAccountController from './controller'; +import { StatusCodes } from 'http-status-codes'; import { Account } from '@/models/Account'; import { Transaction } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; +import deleteAccountController from './controller'; describe('deleteAccountController', () => { let req: Partial; diff --git a/src/routes/account/delete/controller.ts b/src/routes/account/delete/controller.ts index e3bf544..2d99225 100644 --- a/src/routes/account/delete/controller.ts +++ b/src/routes/account/delete/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; +import { StatusCodes } from 'http-status-codes'; import { Account } from '@/models/Account'; import { Transaction } from '@/models/Transaction'; -import { StatusCodes } from 'http-status-codes'; export default async function deleteAccountController(req: Request, res: Response) { const { id } = req.params; diff --git a/src/routes/account/delete/schema.test.ts b/src/routes/account/delete/schema.test.ts index 59d8d3d..dfc23cc 100644 --- a/src/routes/account/delete/schema.test.ts +++ b/src/routes/account/delete/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account delete schema', () => { it('should validate valid id parameter', () => { diff --git a/src/routes/account/edit/controller.test.ts b/src/routes/account/edit/controller.test.ts index a758913..6948cac 100644 --- a/src/routes/account/edit/controller.test.ts +++ b/src/routes/account/edit/controller.test.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import editAccountController from './controller'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; +import editAccountController from './controller'; describe('editAccountController', () => { let req: Partial; diff --git a/src/routes/account/edit/controller.ts b/src/routes/account/edit/controller.ts index 22a6db4..d394896 100644 --- a/src/routes/account/edit/controller.ts +++ b/src/routes/account/edit/controller.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; export default async function editAccountController(req: Request, res: Response) { try { diff --git a/src/routes/account/edit/schema.test.ts b/src/routes/account/edit/schema.test.ts index ce3a7a5..3c3c12b 100644 --- a/src/routes/account/edit/schema.test.ts +++ b/src/routes/account/edit/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account edit schema', () => { it('should validate valid parameters and body', () => { diff --git a/src/routes/account/index.ts b/src/routes/account/index.ts index e0c27b6..607e653 100644 --- a/src/routes/account/index.ts +++ b/src/routes/account/index.ts @@ -2,10 +2,10 @@ import express from 'express'; import schemaValidator from '@/middleware/schemaValidator'; import create from './create'; -import debit from './debit'; import credit from './credit'; -import edit from './edit'; +import debit from './debit'; import deleteA from './delete'; +import edit from './edit'; import list from './list'; const router = express.Router(); diff --git a/src/routes/account/list/controller.test.ts b/src/routes/account/list/controller.test.ts index a361728..d4b8744 100644 --- a/src/routes/account/list/controller.test.ts +++ b/src/routes/account/list/controller.test.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import listAccountsController from './controller'; import { Account } from '@/models/Account'; +import listAccountsController from './controller'; describe('listAccountsController', () => { let req: Partial; diff --git a/src/routes/account/list/controller.ts b/src/routes/account/list/controller.ts index 1b24930..e92d7b7 100644 --- a/src/routes/account/list/controller.ts +++ b/src/routes/account/list/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import { Account } from '@/models/Account'; import type { FilterQuery } from 'mongoose'; import type { IAccount } from '@/models/Account'; +import { Account } from '@/models/Account'; export default async function listAccountsController(req: Request, res: Response) { const { page = 1, limit = 10, search, minBalance, maxBalance, sortBy = 'createdAt', sortOrder = 'desc' } = req.query; diff --git a/src/routes/account/list/schema.test.ts b/src/routes/account/list/schema.test.ts index 9597f34..540e938 100644 --- a/src/routes/account/list/schema.test.ts +++ b/src/routes/account/list/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Account list schema', () => { it('should use default values when not provided', () => { diff --git a/src/routes/index.ts b/src/routes/index.ts index 7e6ba3b..1e1d737 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -1,6 +1,6 @@ import express from 'express'; -import transactionRoutes from './transaction'; import accountRoutes from './account'; +import transactionRoutes from './transaction'; const app = express(); diff --git a/src/routes/transaction/create/controller.test.ts b/src/routes/transaction/create/controller.test.ts index b9a151c..a6ce78f 100644 --- a/src/routes/transaction/create/controller.test.ts +++ b/src/routes/transaction/create/controller.test.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import createTransactionController from './controller'; -import { Transaction } from '@/models/Transaction'; import { StatusCodes } from 'http-status-codes'; +import { Transaction } from '@/models/Transaction'; +import createTransactionController from './controller'; describe('createTransactionController', () => { let req: Partial; diff --git a/src/routes/transaction/create/controller.ts b/src/routes/transaction/create/controller.ts index 5779f89..6bd5d3f 100644 --- a/src/routes/transaction/create/controller.ts +++ b/src/routes/transaction/create/controller.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import { Transaction } from '@/models/Transaction'; import { StatusCodes } from 'http-status-codes'; +import { Transaction } from '@/models/Transaction'; export default async (req: Request, res: Response) => { const transaction = await Transaction.create(req.body); diff --git a/src/routes/transaction/create/schema.test.ts b/src/routes/transaction/create/schema.test.ts index 34aaf1f..f8d1c21 100644 --- a/src/routes/transaction/create/schema.test.ts +++ b/src/routes/transaction/create/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Transaction Create Schema', () => { const { body } = schema; diff --git a/src/routes/transaction/delete/controller.test.ts b/src/routes/transaction/delete/controller.test.ts index 2346e0c..50ec716 100644 --- a/src/routes/transaction/delete/controller.test.ts +++ b/src/routes/transaction/delete/controller.test.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express'; -import deleteTransactionController from './controller'; -import { Transaction, TransactionType } from '@/models/Transaction'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; +import { Transaction, TransactionType } from '@/models/Transaction'; +import deleteTransactionController from './controller'; describe('deleteTransactionController', () => { let req: Partial; diff --git a/src/routes/transaction/delete/controller.ts b/src/routes/transaction/delete/controller.ts index 2ef0d2b..7fffaf2 100644 --- a/src/routes/transaction/delete/controller.ts +++ b/src/routes/transaction/delete/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import { Transaction, TransactionType } from '@/models/Transaction'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; +import { Transaction, TransactionType } from '@/models/Transaction'; export default async function deleteTransactionController(req: Request, res: Response) { const session = await Transaction.startSession(); diff --git a/src/routes/transaction/delete/schema.test.ts b/src/routes/transaction/delete/schema.test.ts index d14408d..5fd38f3 100644 --- a/src/routes/transaction/delete/schema.test.ts +++ b/src/routes/transaction/delete/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Transaction delete schema', () => { it('should validate valid transaction ID', () => { diff --git a/src/routes/transaction/delete/schema.ts b/src/routes/transaction/delete/schema.ts index 189fb2d..9fda8c2 100644 --- a/src/routes/transaction/delete/schema.ts +++ b/src/routes/transaction/delete/schema.ts @@ -1,5 +1,5 @@ -import { z } from 'zod'; import mongoose from 'mongoose'; +import { z } from 'zod'; export default { params: z.object({ diff --git a/src/routes/transaction/edit/controller.test.ts b/src/routes/transaction/edit/controller.test.ts index 5aa285c..a9ebcfc 100644 --- a/src/routes/transaction/edit/controller.test.ts +++ b/src/routes/transaction/edit/controller.test.ts @@ -1,8 +1,8 @@ import type { Request, Response } from 'express'; -import editTransactionController from './controller'; -import { Transaction, TransactionType } from '@/models/Transaction'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; +import { Transaction, TransactionType } from '@/models/Transaction'; +import editTransactionController from './controller'; describe('editTransactionController', () => { let req: Partial; diff --git a/src/routes/transaction/edit/controller.ts b/src/routes/transaction/edit/controller.ts index 3f68bbf..ae1126b 100644 --- a/src/routes/transaction/edit/controller.ts +++ b/src/routes/transaction/edit/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import { Transaction, TransactionType } from '@/models/Transaction'; -import { Account } from '@/models/Account'; import { StatusCodes } from 'http-status-codes'; +import { Account } from '@/models/Account'; +import { Transaction, TransactionType } from '@/models/Transaction'; export default async function editTransactionController(req: Request, res: Response) { const { transactionId } = req.params; diff --git a/src/routes/transaction/edit/schema.test.ts b/src/routes/transaction/edit/schema.test.ts index caa5675..752e181 100644 --- a/src/routes/transaction/edit/schema.test.ts +++ b/src/routes/transaction/edit/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Transaction edit schema', () => { it('should validate valid input', () => { diff --git a/src/routes/transaction/edit/schema.ts b/src/routes/transaction/edit/schema.ts index de0b9de..81d3c44 100644 --- a/src/routes/transaction/edit/schema.ts +++ b/src/routes/transaction/edit/schema.ts @@ -1,5 +1,5 @@ -import { z } from 'zod'; import mongoose from 'mongoose'; +import { z } from 'zod'; export default { params: z.object({ diff --git a/src/routes/transaction/index.ts b/src/routes/transaction/index.ts index 2c914d5..b694b98 100644 --- a/src/routes/transaction/index.ts +++ b/src/routes/transaction/index.ts @@ -3,9 +3,9 @@ import schemaValidator from '@/middleware/schemaValidator'; import validate from '@/middleware/schemaValidator'; import create from './create'; -import list from './list'; -import edit from './edit'; import deleteT from './delete'; +import edit from './edit'; +import list from './list'; const router = Router(); diff --git a/src/routes/transaction/list/controller.test.ts b/src/routes/transaction/list/controller.test.ts index 0a9c334..ac5ea8f 100644 --- a/src/routes/transaction/list/controller.test.ts +++ b/src/routes/transaction/list/controller.test.ts @@ -1,6 +1,6 @@ import type { Request, Response } from 'express'; -import listTransactionsController from './controller'; import { Transaction, TransactionType } from '@/models/Transaction'; +import listTransactionsController from './controller'; describe('listTransactionsController', () => { let req: Partial; diff --git a/src/routes/transaction/list/controller.ts b/src/routes/transaction/list/controller.ts index 19f96ca..7f2b119 100644 --- a/src/routes/transaction/list/controller.ts +++ b/src/routes/transaction/list/controller.ts @@ -1,7 +1,7 @@ import type { Request, Response } from 'express'; -import { Transaction } from '@/models/Transaction'; import type { FilterQuery } from 'mongoose'; import type { ITransaction } from '@/models/Transaction'; +import { Transaction } from '@/models/Transaction'; const listTransactionController = async (req: Request, res: Response) => { const { diff --git a/src/routes/transaction/list/schema.test.ts b/src/routes/transaction/list/schema.test.ts index 455248e..2d8b7c2 100644 --- a/src/routes/transaction/list/schema.test.ts +++ b/src/routes/transaction/list/schema.test.ts @@ -1,5 +1,5 @@ -import schema from './schema'; import { z } from 'zod'; +import schema from './schema'; describe('Transaction list schema', () => { it('should use default values when not provided', () => { diff --git a/src/seeds/seed.ts b/src/seeds/seed.ts index 22416d5..b7a88e2 100644 --- a/src/seeds/seed.ts +++ b/src/seeds/seed.ts @@ -1,8 +1,8 @@ import dotenv from 'dotenv'; import mongoose from 'mongoose'; import { connectDB } from '@/config/database'; +import { Account, type IAccount } from '@/models/Account'; import { type ITransaction, Transaction, TransactionType } from '@/models/Transaction'; -import { type IAccount, Account } from '@/models/Account'; dotenv.config();