-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor more on frontend and add confirm dialog context
- Loading branch information
Showing
39 changed files
with
658 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...s/mern-sample-app/app-node-express/src/app/infrastructure/middleware/withValidatedBody.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @packageDocumentation | ||
*/ | ||
|
||
import type { VALIDATORS } from "../validators"; | ||
import type { RouteMiddlewareFactory } from "@org/app-node-express/lib/@ts-rest"; | ||
import type { RequestHandler } from "express"; | ||
|
||
import { IocRegistry, inject } from "@org/app-node-express/lib/ioc"; | ||
import { RestError, type ValidatorOptions, type Validators } from "@org/lib-api-client"; | ||
|
||
const IOC_KEY = "withValidatedBody"; | ||
|
||
export type ValidatorSchema = keyof typeof VALIDATORS; | ||
|
||
export interface ValidatedBodyMiddleware { | ||
middleware(validators: Validators, options: ValidatorOptions): RequestHandler[]; | ||
} | ||
|
||
@inject(IOC_KEY) | ||
export class WithValidatedBody implements ValidatedBodyMiddleware { | ||
middleware(validators: Validators, options: ValidatorOptions): RequestHandler[] { | ||
return [ | ||
async (req, _res, next) => { | ||
const body = req.body || undefined; | ||
if (!body) return next(); | ||
const validatorEntries = Object.entries(validators); | ||
const validationResults = await Promise.all( | ||
validatorEntries.map(([, validate]) => validate(body, options)), | ||
); | ||
const hasErrors = validationResults.some(res => !res); | ||
if (hasErrors) return next(new RestError(400, "Body validation failed")); | ||
next(); | ||
}, | ||
]; | ||
} | ||
} | ||
|
||
export function withValidatedBody( | ||
validators: Validators, | ||
options: ValidatorOptions = { groups: [] }, | ||
): RouteMiddlewareFactory { | ||
return () => { | ||
return IocRegistry.getInstance() | ||
.inject<ValidatedBodyMiddleware>(IOC_KEY) | ||
.middleware(validators, options); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/mern-sample-app/app-vite-react/public/locales/ar/translation.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"accountSettings": "إعدادات الحساب", | ||
"appTheme": "الثيم", | ||
"apps": "التطبيقات", | ||
"borderRadius": "نصف قطر الحافة", | ||
"calendar": "التقويم", | ||
"cards": "البطاقات", | ||
"dashboard": "لوحة التحكم", | ||
"doSearch": "بحث", | ||
"error": "خطأ", | ||
"forms": "النماذج", | ||
"icons": "الرموز", | ||
"invoice": "فاتورة", | ||
"list": "قائمة", | ||
"login": "تسجيل الدخول", | ||
"pages": "الصفحات", | ||
"register": "التسجيل", | ||
"rolesAndPermissions": "الأدوار والصلاحيات", | ||
"setDarkMode": "وضع داكن", | ||
"setLightMode": "وضع مضيء", | ||
"systemLanguage": "اللغة", | ||
"systemLayout": "التخطيط", | ||
"systemLayoutHorizontal": "تصميم أفقي", | ||
"systemLayoutSidebar": "تصميم بشريط جانبي", | ||
"tables": "الجداول", | ||
"test": "اختبار", | ||
"typography": "الخطوط", | ||
"user": "المستخدم", | ||
"userInterface": "واجهة المستخدم", | ||
"view": "عرض" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.