Compare commits

..

No commits in common. "46031a5fd2de5065459a44e141782da350155762" and "e81f6ac8b79e32b201a64661b3529a538614e2b5" have entirely different histories.

6 changed files with 20 additions and 35 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "axp-server", "name": "axp-server",
"version": "1.4.13", "version": "1.4.12",
"description": "My helper library", "description": "My helper library",
"author": "AntoXa PRO <info@antoxa.pro>", "author": "AntoXa PRO <info@antoxa.pro>",
"homepage": "https://antoxahub.ru/antoxa/axp-server", "homepage": "https://antoxahub.ru/antoxa/axp-server",
@ -20,16 +20,16 @@
"prepare": "npm run build" "prepare": "npm run build"
}, },
"dependencies": { "dependencies": {
"axp-ts": "^1.9.10", "axp-ts": "^1.9.6",
"dotenv": "^16.3.1", "dotenv": "^16.3.1",
"express": "^4.18.2", "express": "^4.18.2",
"mongoose": "^6.12.0" "mongoose": "^6.11.2"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-typescript": "^11.1.3", "@rollup/plugin-typescript": "^11.1.2",
"@types/express": "^4.17.17", "@types/express": "^4.17.17",
"prettier": "^2.8.8", "prettier": "^2.8.8",
"rollup": "^3.29.2", "rollup": "^3.26.2",
"tslib": "^2.6.2" "tslib": "^2.6.0"
} }
} }

View File

@ -7,6 +7,6 @@ export default defineConfig({
dir: 'dist', dir: 'dist',
format: 'es' format: 'es'
}, },
plugins: [typescript()],
external: ['path', 'axp-ts', 'dotenv', 'express', 'mongoose'], external: ['path', 'axp-ts', 'dotenv', 'express', 'mongoose'],
plugins: [typescript()]
}) })

View File

@ -8,7 +8,6 @@ import { api404Handler, resultHandler } from './core/handlers'
export default async ( export default async (
modules: (typeof AppModule)[] = [] modules: (typeof AppModule)[] = []
): Promise<Express> => { ): Promise<Express> => {
// Express. // Express.
const app = express() const app = express()
const apiRouter = Router() const apiRouter = Router()

View File

@ -3,7 +3,6 @@ import { DataResultEntity } from 'axp-ts'
/** /**
* Базовый контроллер. * Базовый контроллер.
* @deprecated
*/ */
export class BaseController { export class BaseController {
/** /**

View File

@ -1,4 +1,4 @@
import { NotificationItem, TNotificationItem } from 'axp-ts' import { TNotificationItem } from 'axp-ts'
/** /**
* Тип - Http ошибка. * Тип - Http ошибка.
@ -13,17 +13,15 @@ export type THttpError = {
* Http ошибка. * Http ошибка.
*/ */
export class HttpError implements THttpError { export class HttpError implements THttpError {
status: number status: number = 500
message: string message: string = 'Server Error'
errors: TNotificationItem[] = [] errors: TNotificationItem[] = []
constructor(args?: { text?: string; code?: string; statusCode?: number }) { constructor(args?: { text?: string; code?: string; statusCode?: number }) {
this.status = args?.statusCode || 500 this.status = args?.statusCode || 500
this.message = this.getStatusMessage(this.status) this.message = this.getStatusMessage(this.status)
if (args?.text) { if (args?.text) {
this.errors.push( this.errors.push({ code: args.code || 'error', text: args.text })
new NotificationItem({ code: args.code || 'error', text: args.text })
)
} }
} }

View File

@ -1,6 +1,4 @@
import type { Request, Response, NextFunction } from 'express' import { Request, Response, NextFunction } from 'express'
import type { IFormModel } from 'axp-ts'
import { z } from 'zod' import { z } from 'zod'
import { DataResultEntity } from 'axp-ts' import { DataResultEntity } from 'axp-ts'
@ -11,9 +9,9 @@ import { HttpError } from './errors'
*/ */
export const resultHandler = ( export const resultHandler = (
result: any, result: any,
{}: Request, { }: Request,
res: Response, res: Response,
{}: NextFunction { }: NextFunction
) => { ) => {
const dR = new DataResultEntity() const dR = new DataResultEntity()
@ -48,8 +46,8 @@ export const resultHandler = (
* Обработчик 404 ошибки. * Обработчик 404 ошибки.
*/ */
export const api404Handler = ( export const api404Handler = (
{}: Request, { }: Request,
{}: Response, { }: Response,
next: NextFunction next: NextFunction
) => { ) => {
next( next(
@ -77,6 +75,10 @@ export const zodMiddle =
(schemas: TZodMiddleArgs) => (schemas: TZodMiddleArgs) =>
(req: Request, {}: Response, next: NextFunction) => { (req: Request, {}: Response, next: NextFunction) => {
try { try {
// req.params._id = ''
// req.body.email = 'test'
// console.log(req.body)
if (schemas.query) req.query = schemas.query.parse(req.query) if (schemas.query) req.query = schemas.query.parse(req.query)
if (schemas.params) req.params = schemas.params.parse(req.params) if (schemas.params) req.params = schemas.params.parse(req.params)
if (schemas.body) req.body = schemas.body.parse(req.body) if (schemas.body) req.body = schemas.body.parse(req.body)
@ -94,16 +96,3 @@ export const zodMiddle =
next(httpError) next(httpError)
} }
} }
export const validFormMiddle =
(model: IFormModel<any>) =>
(req: Request, {}: Response, next: NextFunction) => {
if (model.isValid()) {
req.body = model.obj
next()
} else {
const httpError = new HttpError({ statusCode: 400 })
httpError.errors = model.errors
next(httpError)
}
}