@ruiapp/rapid-core 0.1.71 → 0.1.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,27 +1,28 @@
1
- import { RpdDataModel } from "~/types";
2
- import { isRelationProperty } from "../helpers/metaHelper";
3
-
4
- export function mapPropertyNameToColumnName(model: RpdDataModel, propertyName: string) {
5
- if (!model.properties) {
6
- return propertyName;
7
- }
8
-
9
- const property = model.properties.find((item) => item.code === propertyName);
10
- if (!property) {
11
- return propertyName;
12
- }
13
-
14
- if (isRelationProperty(property) && property.relation === "one") {
15
- return property.targetIdColumnName!;
16
- }
17
-
18
- return property.columnName || property.code;
19
- }
20
-
21
- export function mapPropertyNamesToColumnNames(model: RpdDataModel, propertyNames: string[]) {
22
- if (!propertyNames || !propertyNames.length) {
23
- return [];
24
- }
25
-
26
- return propertyNames.map((fieldName) => mapPropertyNameToColumnName(model, fieldName));
27
- }
1
+ import { RpdDataModel } from "~/types";
2
+ import { getEntityPropertyByCode, isOneRelationProperty } from "../helpers/metaHelper";
3
+ import { IRpdServer } from "~/core/server";
4
+
5
+ export function mapPropertyNameToColumnName(server: IRpdServer, model: RpdDataModel, propertyName: string) {
6
+ if (!model.properties) {
7
+ return propertyName;
8
+ }
9
+
10
+ const property = getEntityPropertyByCode(server, model, propertyName);
11
+ if (!property) {
12
+ return propertyName;
13
+ }
14
+
15
+ if (isOneRelationProperty(property)) {
16
+ return property.targetIdColumnName!;
17
+ }
18
+
19
+ return property.columnName || property.code;
20
+ }
21
+
22
+ export function mapPropertyNamesToColumnNames(server: IRpdServer, model: RpdDataModel, propertyNames: string[]) {
23
+ if (!propertyNames || !propertyNames.length) {
24
+ return [];
25
+ }
26
+
27
+ return propertyNames.map((fieldName) => mapPropertyNameToColumnName(server, model, fieldName));
28
+ }
@@ -61,3 +61,16 @@ export function getEntityProperty(server: IRpdServer, model: RpdDataModel, predi
61
61
 
62
62
  return property;
63
63
  }
64
+
65
+ export function getEntityPropertyByFieldName(server: IRpdServer, model: RpdDataModel, fieldName: string) {
66
+ let property = getEntityPropertyByCode(server, model, fieldName);
67
+ if (!property) {
68
+ property = getEntityProperty(server, model, (item) => item.relation === "one" && item.targetIdColumnName === fieldName);
69
+ }
70
+
71
+ if (!property) {
72
+ property = getEntityProperty(server, model, (item) => item.columnName === fieldName);
73
+ }
74
+
75
+ return property;
76
+ }
@@ -1,28 +1,33 @@
1
- import path from "path";
2
- import { readFile } from "~/utilities/fsUtility";
3
- import { ActionHandlerContext } from "~/core/actionHandler";
4
- import { RapidPlugin } from "~/core/server";
5
-
6
- export const code = "downloadFile";
7
-
8
- export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
9
- const { server, applicationConfig, routerContext, input } = ctx;
10
- const { request, response } = routerContext;
11
-
12
- const dataAccessor = ctx.server.getDataAccessor({
13
- singularCode: "ecm_storage_object",
14
- });
15
-
16
- const storageObject = await dataAccessor.findById(input.fileId);
17
- if (!storageObject) {
18
- ctx.output = { error: new Error("Storage object not found.") };
19
- return;
20
- }
21
-
22
- const fileKey = storageObject.key;
23
- const filePathName = path.join(server.config.localFileStoragePath, fileKey);
24
- const attachmentFileName = input.fileName || path.basename(fileKey);
25
-
26
- response.body = await readFile(filePathName);
27
- response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
28
- }
1
+ import path from "path";
2
+ import { readFile } from "~/utilities/fsUtility";
3
+ import { ActionHandlerContext } from "~/core/actionHandler";
4
+ import { RapidPlugin } from "~/core/server";
5
+
6
+ export const code = "downloadFile";
7
+
8
+ export async function handler(plugin: RapidPlugin, ctx: ActionHandlerContext, options: any) {
9
+ const { server, applicationConfig, routerContext, input } = ctx;
10
+ const { request, response } = routerContext;
11
+ //TODO: only public files can download by this handler
12
+
13
+ let fileKey: string = input.fileKey;
14
+
15
+ if (!fileKey && input.fileId) {
16
+ const dataAccessor = ctx.server.getDataAccessor({
17
+ singularCode: "ecm_storage_object",
18
+ });
19
+
20
+ const storageObject = await dataAccessor.findById(input.fileId);
21
+ if (!storageObject) {
22
+ ctx.output = { error: new Error("Storage object not found.") };
23
+ return;
24
+ }
25
+
26
+ fileKey = storageObject.key;
27
+ }
28
+ const filePathName = path.join(server.config.localFileStoragePath, fileKey);
29
+ const attachmentFileName = input.fileName || path.basename(fileKey);
30
+
31
+ response.body = await readFile(filePathName);
32
+ response.headers.set("Content-Disposition", `attachment; filename="${encodeURIComponent(attachmentFileName)}"`);
33
+ }