mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
fix user module
This commit is contained in:
42
packages/api-common/src/constants/apiModules.ts
Normal file
42
packages/api-common/src/constants/apiModules.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
export const flatResponseModules: string[] = [
|
||||
"/api/file-settings",
|
||||
"/api/auth",
|
||||
"/api/sessions",
|
||||
"/api/users",
|
||||
"/api/roles",
|
||||
"/api/user-roles",
|
||||
"/api/permissions",
|
||||
"/api/role-permissions",
|
||||
"/api/user-documents",
|
||||
"/api/documentary-requirements",
|
||||
"/api/account-configurations",
|
||||
"/api/applications",
|
||||
"/api/organization-types",
|
||||
"/api/default-units",
|
||||
"/api/default-positions",
|
||||
"/api/organizations",
|
||||
"/api/units",
|
||||
"/api/unit-settings",
|
||||
"/api/organization-configurations",
|
||||
"/api/positions",
|
||||
"/api/employees",
|
||||
"/api/employee-positions",
|
||||
"/api/migrate",
|
||||
"/api/projects",
|
||||
"/api/position-permissions",
|
||||
"/api/position-type-permissions",
|
||||
"/api/position-types",
|
||||
"/api/position-configurations",
|
||||
"/api/organization-global-configurations",
|
||||
"/api/global-unit-configurations",
|
||||
"/api/position-type-configurations",
|
||||
"/api/organization-settings",
|
||||
"/api/location-types",
|
||||
"/api/locations",
|
||||
"/api/unit-clusters",
|
||||
"/api/seals",
|
||||
"/api/headers",
|
||||
"/api/footers",
|
||||
"/api/employee-signatures",
|
||||
"/api/employee-stamps",
|
||||
];
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
import { Readable } from "stream";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
import { flatResponseModules } from "../constants/apiModules";
|
||||
|
||||
export interface StandardResponse<T> {
|
||||
success: true;
|
||||
@@ -33,6 +34,25 @@ export class ResponseTransformInterceptor<T> implements NestInterceptor<
|
||||
) {
|
||||
return data;
|
||||
}
|
||||
const request = _context.switchToHttp().getRequest();
|
||||
const path = request.route?.path ?? request.originalUrl ?? "";
|
||||
|
||||
const shouldFlatten = flatResponseModules.some((module) =>
|
||||
path.startsWith(module),
|
||||
);
|
||||
|
||||
if (
|
||||
shouldFlatten &&
|
||||
data &&
|
||||
typeof data === "object" &&
|
||||
!Array.isArray(data)
|
||||
) {
|
||||
return {
|
||||
success: true,
|
||||
...data,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
|
||||
Reference in New Issue
Block a user