Browse Source

refactor: add _name to getData response documents on the backend

Kristian Vos 1 month ago
parent
commit
f0bcc35199

+ 2 - 0
backend/src/modules/DataModule.ts

@@ -178,6 +178,8 @@ export class DataModule extends BaseModule {
 
 		if (getDataEnabled) schema.plugin(getDataPlugin);
 
+		schema.static("getModelName", () => modelName);
+
 		await this._registerEvents(modelName, schema);
 
 		await this._registerEventListeners(schema);

+ 8 - 0
backend/src/modules/DataModule/plugins/getData.ts

@@ -249,6 +249,14 @@ export default function getDataPlugin(schema: Schema) {
 				}
 			});
 
+			result.documents = result.documents.map((document: any) => ({
+				...document,
+				// TODO properly support getModelName in TypeScript
+				// eslint-disable-next-line
+				// @ts-ignore
+				_name: schema.statics.getModelName()
+			}));
+
 			const { documents: data } = result;
 			const { count } = result.count[0];
 

+ 0 - 1
frontend/src/components/AdvancedTable.vue

@@ -298,7 +298,6 @@ const getData = async () => {
 		row =>
 			new Model({
 				...row,
-				_name: props.model,
 				selected: false
 			})
 	);