-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathlessRouteGroups.ts
More file actions
49 lines (45 loc) · 1.71 KB
/
Copy pathPathlessRouteGroups.ts
File metadata and controls
49 lines (45 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import AbstractController, {
type TMiddleware,
} from '@adaptivestone/framework/modules/AbstractController.js';
import Pagination from '@adaptivestone/framework/services/http/middleware/Pagination.js';
import type { Response } from 'express';
import { z } from 'zod';
// Generated beside this controller by `npm run gen`. The physical pathless
// route-group directory remains source organization and is absent from the URL.
import type { GetRouteGroupsRequest } from './PathlessRouteGroups.routes.gen.ts';
class PathlessRouteGroups extends AbstractController {
get routes() {
return {
get: {
'/': {
handler: this.getRouteGroups,
middleware: [Pagination],
// OpenAPI describes this as a date-time string while the generated
// handler type receives the coerced Date value.
query: z.object({ changedAfter: z.coerce.date().optional() }),
},
},
};
}
// GET /pathlessroutegroups, not /(public)/pathlessroutegroups.
async getRouteGroups(req: GetRouteGroupsRequest, res: Response) {
// The default memory cache works with no optional service. Applications can
// select the Redis driver when cache entries must be shared by workers.
const data = await req.appInfo.app.cache.getSetValue(
'pathless-route-groups',
async () => [{ convention: 'pathless-route-group-directories' }],
60,
);
return res.status(200).json({
data,
pagination: req.appInfo.pagination,
filters: {
changedAfter: req.appInfo.query.changedAfter?.toISOString() ?? null,
},
});
}
static get middleware(): Map<string, TMiddleware> {
return new Map([['/{*splat}', []]]);
}
}
export default PathlessRouteGroups;