Skip to content

Commit f9de8c7

Browse files
committed
feat: add ITranslateFunction, IAdminUserExpressRequest and ITranslateExpressRequest data types
1 parent afc3e0b commit f9de8c7

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

adminforth/documentation/docs/tutorial/03-Customization/06-customPages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ Open `index.ts` file and add the following code *BEFORE* `admin.express.serve(`
310310
311311
app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
312312
admin.express.authorize(
313-
async (req:any, res:any) => {
313+
async (req:IAdminUserExpressRequest, res:any) => {
314314
const days = req.body.days || 7;
315315
const apartsByDays = admin.resource('aparts').dataConnector.client.prepare(
316316
`SELECT

adminforth/types/Back.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Express } from 'express';
1+
import type { Express, Request } from 'express';
22
import type { Writable } from 'stream';
33

44
import { ActionCheckSource, AdminForthFilterOperators, AdminForthSortDirections, AllowedActionsEnum,
@@ -105,6 +105,25 @@ export interface IExpressHttpServer extends IHttpServer {
105105
authorize(callable: Function): void;
106106
}
107107

108+
export interface ITranslateFunction {
109+
(
110+
msg: string,
111+
category: string,
112+
lang: string,
113+
params: any,
114+
pluralizationNumber?: number
115+
): Promise<string>;
116+
}
117+
118+
export interface IAdminUserExpressRequest extends Request {
119+
adminUser: AdminUser;
120+
}
121+
122+
export interface ITranslateExpressRequest extends Request {
123+
tr: ITranslateFunction;
124+
}
125+
126+
108127

109128
export interface IAdminForthSingleFilter {
110129
field?: string;
@@ -332,7 +351,7 @@ export interface IAdminForth {
332351

333352
formatAdminForth(): string;
334353

335-
tr(msg: string, category: string, lang: string, params: any, pluralizationNumber?: number): Promise<string>;
354+
tr: ITranslateFunction;
336355

337356
createResourceRecord(
338357
params: { resource: AdminForthResource, record: any, adminUser: AdminUser, extra?: HttpExtra }

dev-demo/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import betterSqlite3 from 'better-sqlite3';
22
import express from 'express';
33
import AdminForth, { AdminUser, Filters } from '../adminforth/index.js';
4-
4+
import type { IAdminUserExpressRequest, ITranslateExpressRequest } from '../adminforth/spa/src/types/Back.js';
55
import clicksResource from './resources/clicks.js';
66
import apartmentsResource from './resources/apartments.js';
77
import apartmentBuyersResource from './resources/apartment_buyers.js';
@@ -355,7 +355,7 @@ const port = process.env.PORT || 3000;
355355
app.get(
356356
'/api/testtest/',
357357
admin.express.authorize(
358-
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
358+
async (req: IAdminUserExpressRequest, res: express.Response, next: express.NextFunction) => {
359359
res.json({ ok: true, data: [1,2,3], adminUser: req.adminUser });
360360
}
361361
)
@@ -364,7 +364,7 @@ app.get(
364364
app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
365365
admin.express.authorize(
366366
admin.express.translatable(
367-
async (req: any, res: express.Response) => {
367+
async (req: IAdminUserExpressRequest & ITranslateExpressRequest, res: express.Response) => {
368368
const days = req.body.days || 7;
369369
const apartsByDays = await admin.resource('aparts').dataConnector.client.prepare(
370370
`SELECT
@@ -464,7 +464,7 @@ app.get(`${ADMIN_BASE_URL}/api/dashboard/`,
464464

465465
app.get(`${ADMIN_BASE_URL}/api/aparts-by-room-percentages/`,
466466
admin.express.authorize(
467-
async (req, res) => {
467+
async (req:IAdminUserExpressRequest, res) => {
468468
const roomPercentages = await admin.resource('aparts').dataConnector.client.prepare(
469469
`SELECT
470470
number_of_rooms,

0 commit comments

Comments
 (0)