Skip to content

Commit 4099952

Browse files
feat: Stop SELECT * queries
1 parent 7692926 commit 4099952

File tree

5 files changed

+37
-50
lines changed

5 files changed

+37
-50
lines changed

jest.config.ts

-25
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ const customJestConfig = {
114114
setupFiles: [
115115
// "<rootDir>/__tests__/setupDotEnv.ts",
116116
"<rootDir>/src/__tests__/setupGlobals.ts",
117-
"<rootDir>/src/__tests__/consoleOverrides.ts",
118117
],
119118

120119
// A list of paths to modules that run some code to configure or set up the testing framework before each test
@@ -143,18 +142,6 @@ const customJestConfig = {
143142
// "/node_modules/"
144143
// ],
145144

146-
// The regexp pattern or array of patterns that Jest uses to detect test files
147-
// testRegex: [],
148-
149-
// This option allows the use of a custom results processor
150-
// testResultsProcessor: undefined,
151-
152-
// This option allows use of a custom test runner
153-
// testRunner: "jest-circus/runner",
154-
155-
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
156-
// testURL: "http://localhost",
157-
158145
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
159146
// timers: "real",
160147

@@ -164,18 +151,6 @@ const customJestConfig = {
164151
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
165152
transformIgnorePatterns: [],
166153

167-
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
168-
// unmockedModulePathPatterns: undefined,
169-
170-
// Indicates whether each individual test should be reported during the run
171-
// verbose: undefined,
172-
173-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
174-
// watchPathIgnorePatterns: [],
175-
176-
// Whether to use watchman for file crawling
177-
// watchman: true,
178-
179154
testTimeout: 10000,
180155
};
181156

next-env.d.ts

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
4-
// NOTE: This file should not be edited
5-
// see https://nextjs.org/docs/basic-features/typescript for more information.

src/__tests__/consoleOverrides.ts

-18
This file was deleted.

src/backend/data/data.controller.ts

+32-4
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,39 @@ export class DataController {
115115
return TemplateService.compile(relationshipSettings.format, data);
116116
}
117117

118+
private async getAllowedCrudsFieldsToShow(
119+
entity: string,
120+
crudKey: "hidden_entity_details_columns"
121+
): Promise<string[]> {
122+
const [hiddenFields, entityFields] = await Promise.all([
123+
this._configurationService.show<string[]>(crudKey, entity),
124+
this._entitiesService.getEntityFields(entity),
125+
]);
126+
127+
if (hiddenFields.length === 0) {
128+
return entityFields.map(({ name }) => name);
129+
}
130+
131+
const hiddenFieldsMap = Object.fromEntries(
132+
hiddenFields.map((field) => [field, 1])
133+
);
134+
135+
return entityFields
136+
.filter((entityField) => !hiddenFieldsMap[entityField.name])
137+
.map(({ name }) => name);
138+
}
139+
118140
async showData(entity: string, id: string) {
119-
// Send in the show fields
120-
return await this._dataService.show(entity, [], {
121-
[await this._entitiesService.getEntityPrimaryField(entity)]: id,
122-
});
141+
return await this._dataService.show(
142+
entity,
143+
await this.getAllowedCrudsFieldsToShow(
144+
entity,
145+
"hidden_entity_details_columns"
146+
),
147+
{
148+
[await this._entitiesService.getEntityPrimaryField(entity)]: id,
149+
}
150+
);
123151
}
124152

125153
async createData(entity: string, data: Record<string, unknown>) {

src/backend/data/data.service.ts

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export class DataService {
121121
select: string[],
122122
query: Record<string, unknown>
123123
): Promise<T> {
124+
if (select.length === 0) {
125+
throw new Error(
126+
"We dont do that here, Please define the fields you want to select"
127+
);
128+
}
124129
return await (await DataService.getInstance())
125130
.table(entity)
126131
.select(select)

0 commit comments

Comments
 (0)