@opengis/fastify-table 2.5.42 → 2.5.44
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.
- package/dist/helper.d.ts +20 -0
- package/dist/helper.d.ts.map +1 -1
- package/dist/helper.js +26 -0
- package/dist/index.js +1 -1
- package/dist/server/plugins/access/funcs/getResources.d.ts +2 -1
- package/dist/server/plugins/access/funcs/getResources.d.ts.map +1 -1
- package/dist/server/plugins/access/funcs/getResources.js +5 -1
- package/dist/server/plugins/crud/funcs/getOpt.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/getOpt.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/getOpt.js +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.d.ts.map +1 -1
- package/dist/server/plugins/crud/funcs/setOpt.js +1 -1
- package/dist/server/plugins/crud/funcs/setToken.d.ts +1 -1
- package/dist/server/plugins/crud/funcs/setToken.d.ts.map +1 -1
- package/dist/server/plugins/file/utils/inspectContent.d.ts.map +1 -1
- package/dist/server/plugins/file/utils/inspectContent.js +7 -0
- package/dist/server/plugins/table/funcs/getData.d.ts +32 -0
- package/dist/server/plugins/table/funcs/getData.d.ts.map +1 -0
- package/dist/server/plugins/table/funcs/getData.js +703 -0
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts +2 -1
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.d.ts.map +1 -1
- package/dist/server/plugins/table/funcs/getFilterSQLParametrized/index.js +2 -2
- package/dist/server/routes/crud/controllers/table.d.ts +1 -2
- package/dist/server/routes/crud/controllers/table.d.ts.map +1 -1
- package/dist/server/routes/crud/controllers/table.js +1 -1
- package/dist/server/routes/crud/crud.route.d.ts +3 -0
- package/dist/server/routes/crud/crud.route.d.ts.map +1 -0
- package/dist/server/routes/crud/crud.route.js +161 -0
- package/dist/server/routes/crud/crud.schema.d.ts +114 -0
- package/dist/server/routes/crud/crud.schema.d.ts.map +1 -0
- package/dist/server/routes/crud/crud.schema.js +64 -0
- package/dist/server/routes/crud/functions/createTableRelation.d.ts +13 -0
- package/dist/server/routes/crud/functions/createTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/createTableRelation.js +93 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.d.ts +11 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/deleteTableRelation.js +74 -0
- package/dist/server/routes/crud/functions/readTableRelations.d.ts +25 -0
- package/dist/server/routes/crud/functions/readTableRelations.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/readTableRelations.js +76 -0
- package/dist/server/routes/crud/functions/updateTableRelation.d.ts +14 -0
- package/dist/server/routes/crud/functions/updateTableRelation.d.ts.map +1 -0
- package/dist/server/routes/crud/functions/updateTableRelation.js +117 -0
- package/dist/server/routes/file/schema.js +6 -6
- package/dist/server/routes/table/functions/getData.d.ts +3 -2
- package/dist/server/routes/table/functions/getData.d.ts.map +1 -1
- package/dist/server/routes/table/functions/getData.js +2 -14
- package/dist/server/routes/table/schema.d.ts +5 -4
- package/dist/server/routes/table/schema.d.ts.map +1 -1
- package/dist/server/routes/table/schema.js +13 -13
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ExtendedPG } from "../../../../types/core.js";
|
|
2
|
-
export default function getFilterSQLParametrized({ table, filter, pg, search, searchColumn: searchColumn1, filterList, query, custom, state, uid, objectId, }: {
|
|
2
|
+
export default function getFilterSQLParametrized({ table, filter, pg, search, searchColumn: searchColumn1, filterList, query, custom, state, uid, objectId, args: paramsArgs, }: {
|
|
3
3
|
table: string | undefined;
|
|
4
4
|
filter?: string;
|
|
5
5
|
pg: ExtendedPG;
|
|
@@ -12,6 +12,7 @@ export default function getFilterSQLParametrized({ table, filter, pg, search, se
|
|
|
12
12
|
uid?: string;
|
|
13
13
|
objectId?: string;
|
|
14
14
|
order?: string;
|
|
15
|
+
args?: any[];
|
|
15
16
|
}): Promise<{
|
|
16
17
|
q: string;
|
|
17
18
|
args: any[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/getFilterSQLParametrized/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAgD5D,wBAA8B,wBAAwB,CAAC,EACrD,KAAK,EACL,MAAM,EACN,EAAqB,EACrB,MAAM,EACN,YAAY,EAAE,aAAa,EAC3B,UAAU,EACV,KAAK,EACL,MAAM,EACN,KAAK,EACL,GAAG,EACH,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../server/plugins/table/funcs/getFilterSQLParametrized/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAgD5D,wBAA8B,wBAAwB,CAAC,EACrD,KAAK,EACL,MAAM,EACN,EAAqB,EACrB,MAAM,EACN,YAAY,EAAE,aAAa,EAC3B,UAAU,EACV,KAAK,EACL,MAAM,EACN,KAAK,EACL,GAAG,EACH,QAAQ,EACR,IAAI,EAAE,UAAU,GACjB,EAAE;IACD,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;CACd;;;GAoMA"}
|
|
@@ -23,11 +23,11 @@ function getExtraQuery({ columns, schema, table, pk, args, }) {
|
|
|
23
23
|
extraColumns,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
export default async function getFilterSQLParametrized({ table, filter, pg = pgClients.client, search, searchColumn: searchColumn1, filterList, query, custom, state, uid, objectId, }) {
|
|
26
|
+
export default async function getFilterSQLParametrized({ table, filter, pg = pgClients.client, search, searchColumn: searchColumn1, filterList, query, custom, state, uid, objectId, args: paramsArgs, }) {
|
|
27
27
|
if (!table) {
|
|
28
28
|
throw BadRequestError("param table is required");
|
|
29
29
|
}
|
|
30
|
-
const args = [];
|
|
30
|
+
const args = Array.from(paramsArgs || []);
|
|
31
31
|
const body = await getTemplate("table", table);
|
|
32
32
|
const loadTemplate = body?.form
|
|
33
33
|
? await getTemplate("form", body?.form)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAmBA,wBAA8B,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,gBAmQnE"}
|
|
@@ -9,7 +9,7 @@ import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
|
|
|
9
9
|
import extraDataGet from "../../../plugins/extra/extraDataGet.js";
|
|
10
10
|
import { resources } from "../../../plugins/access/funcs/getResources.js";
|
|
11
11
|
import { BadRequestError, ForbiddenError, NotFoundError, } from "../../../../errors.js";
|
|
12
|
-
export default async function tableAPI(req,
|
|
12
|
+
export default async function tableAPI(req, _, called) {
|
|
13
13
|
const { pg = pgClients.client, params, user = {}, query = {}, method } = req;
|
|
14
14
|
const tokenData = await getToken({
|
|
15
15
|
token: params?.table,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.route.d.ts","sourceRoot":"","sources":["../../../../server/routes/crud/crud.route.ts"],"names":[],"mappings":"AAuBA,iBAAS,MAAM,CAAC,GAAG,EAAE,GAAG,QAoMvB;AAED,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import update from "./controllers/update.js";
|
|
2
|
+
import insert from "./controllers/insert.js";
|
|
3
|
+
import deleteCrud from "./controllers/deleteCrud.js";
|
|
4
|
+
import table from "./controllers/table.js";
|
|
5
|
+
import { tableSchema, tableRelationSchema, createTableRelationSchema, updateTableRelationSchema, } from "./crud.schema.js";
|
|
6
|
+
import deleteTableRelation from "./functions/deleteTableRelation.js";
|
|
7
|
+
import readTableRelations from "./functions/readTableRelations.js";
|
|
8
|
+
import createTableRelation from "./functions/createTableRelation.js";
|
|
9
|
+
import updateTableRelation from "./functions/updateTableRelation.js";
|
|
10
|
+
// public access to API, permission check in route
|
|
11
|
+
const publicPolicy = "L0";
|
|
12
|
+
const authorizedPolicy = "L1";
|
|
13
|
+
const tags = ["core", "crud"];
|
|
14
|
+
const packageName = "fastify-table";
|
|
15
|
+
function plugin(app) {
|
|
16
|
+
app.put("/table/:table/:id?", {
|
|
17
|
+
config: {
|
|
18
|
+
tags,
|
|
19
|
+
package: packageName,
|
|
20
|
+
policy: authorizedPolicy,
|
|
21
|
+
summary: "Edit table data",
|
|
22
|
+
},
|
|
23
|
+
schema: tableSchema,
|
|
24
|
+
}, update);
|
|
25
|
+
app.delete("/table/:table/:id?", {
|
|
26
|
+
config: {
|
|
27
|
+
tags,
|
|
28
|
+
package: packageName,
|
|
29
|
+
policy: authorizedPolicy,
|
|
30
|
+
summary: "Delete table data",
|
|
31
|
+
},
|
|
32
|
+
schema: tableSchema,
|
|
33
|
+
}, deleteCrud);
|
|
34
|
+
app.post("/table/:table/:id?", {
|
|
35
|
+
config: {
|
|
36
|
+
tags,
|
|
37
|
+
package: packageName,
|
|
38
|
+
policy: authorizedPolicy,
|
|
39
|
+
summary: "Add table data",
|
|
40
|
+
},
|
|
41
|
+
schema: tableSchema,
|
|
42
|
+
}, insert);
|
|
43
|
+
app.get("/table/:table/:id?", {
|
|
44
|
+
config: {
|
|
45
|
+
tags,
|
|
46
|
+
package: packageName,
|
|
47
|
+
policy: publicPolicy,
|
|
48
|
+
summary: "Get table data",
|
|
49
|
+
},
|
|
50
|
+
schema: tableSchema,
|
|
51
|
+
}, table);
|
|
52
|
+
app.get("/table/:table/:id/:relname", {
|
|
53
|
+
config: {
|
|
54
|
+
tags,
|
|
55
|
+
package: packageName,
|
|
56
|
+
policy: publicPolicy,
|
|
57
|
+
summary: "Список пов’язаних записів",
|
|
58
|
+
},
|
|
59
|
+
schema: tableRelationSchema,
|
|
60
|
+
}, async ({ params, headers, query, user, pg }) => {
|
|
61
|
+
const result = await readTableRelations({
|
|
62
|
+
table: params.table,
|
|
63
|
+
id: params.id,
|
|
64
|
+
relname: params.relname,
|
|
65
|
+
uid: user?.uid,
|
|
66
|
+
userType: user?.user_type,
|
|
67
|
+
limit: query.limit,
|
|
68
|
+
page: query.page,
|
|
69
|
+
referer: headers.referer,
|
|
70
|
+
// called: false,
|
|
71
|
+
}, pg);
|
|
72
|
+
return result;
|
|
73
|
+
});
|
|
74
|
+
app.get("/table/:table/:id/:relname/:relationId", {
|
|
75
|
+
config: {
|
|
76
|
+
tags,
|
|
77
|
+
package: packageName,
|
|
78
|
+
policy: publicPolicy,
|
|
79
|
+
summary: "Отримати пов’язаний запис",
|
|
80
|
+
},
|
|
81
|
+
schema: tableRelationSchema,
|
|
82
|
+
}, async ({ params, headers, user, pg }) => {
|
|
83
|
+
const result = await readTableRelations({
|
|
84
|
+
table: params.table,
|
|
85
|
+
id: params.id,
|
|
86
|
+
relname: params.relname,
|
|
87
|
+
relationId: params.relationId,
|
|
88
|
+
uid: user?.uid,
|
|
89
|
+
userType: user?.user_type,
|
|
90
|
+
referer: headers.referer,
|
|
91
|
+
// called: false,
|
|
92
|
+
}, pg);
|
|
93
|
+
return result;
|
|
94
|
+
});
|
|
95
|
+
app.post("/table/:table/:id/:relname/:relationId?", {
|
|
96
|
+
config: {
|
|
97
|
+
tags,
|
|
98
|
+
package: packageName,
|
|
99
|
+
policy: authorizedPolicy,
|
|
100
|
+
summary: "Додати дочірній запис",
|
|
101
|
+
},
|
|
102
|
+
schema: createTableRelationSchema,
|
|
103
|
+
}, async ({ params, headers, body, user, pg }) => {
|
|
104
|
+
const result = await createTableRelation({
|
|
105
|
+
table: params.table,
|
|
106
|
+
id: params.id,
|
|
107
|
+
relname: params.relname,
|
|
108
|
+
relationId: params.relationId,
|
|
109
|
+
body,
|
|
110
|
+
uid: user?.uid,
|
|
111
|
+
userType: user?.user_type,
|
|
112
|
+
referer: headers.referer,
|
|
113
|
+
// called: false,
|
|
114
|
+
}, pg);
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
app.put("/table/:table/:id/:relname/:relationId", {
|
|
118
|
+
config: {
|
|
119
|
+
tags,
|
|
120
|
+
package: packageName,
|
|
121
|
+
policy: authorizedPolicy,
|
|
122
|
+
summary: "Оновити пов’язаний запис",
|
|
123
|
+
},
|
|
124
|
+
schema: updateTableRelationSchema,
|
|
125
|
+
}, async ({ params, headers, body, user, pg }) => {
|
|
126
|
+
const result = await updateTableRelation({
|
|
127
|
+
table: params.table,
|
|
128
|
+
id: params.id,
|
|
129
|
+
relname: params.relname,
|
|
130
|
+
relationId: params.relationId,
|
|
131
|
+
body,
|
|
132
|
+
uid: user?.uid,
|
|
133
|
+
userType: user?.user_type,
|
|
134
|
+
referer: headers.referer,
|
|
135
|
+
ignoreCheck: process.env.NODE_ENV === "test" || !!process.env.VITEST,
|
|
136
|
+
// called: false,
|
|
137
|
+
}, pg);
|
|
138
|
+
return result;
|
|
139
|
+
});
|
|
140
|
+
app.delete("/table/:table/:id/:relname/:relationId", {
|
|
141
|
+
config: {
|
|
142
|
+
tags,
|
|
143
|
+
package: packageName,
|
|
144
|
+
policy: authorizedPolicy,
|
|
145
|
+
summary: "Видалити або відв’язати запис",
|
|
146
|
+
},
|
|
147
|
+
schema: tableRelationSchema,
|
|
148
|
+
}, async ({ params, user, pg }) => {
|
|
149
|
+
const result = await deleteTableRelation({
|
|
150
|
+
table: params.table,
|
|
151
|
+
id: params.id,
|
|
152
|
+
relname: params.relname,
|
|
153
|
+
relationId: params.relationId,
|
|
154
|
+
uid: user?.uid,
|
|
155
|
+
userType: user?.user_type,
|
|
156
|
+
// called: false,
|
|
157
|
+
}, pg);
|
|
158
|
+
return result;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
export default plugin;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
export declare const tableSchema: {
|
|
2
|
+
params: {
|
|
3
|
+
type: string;
|
|
4
|
+
properties: {
|
|
5
|
+
id: {
|
|
6
|
+
type: string;
|
|
7
|
+
pattern: string;
|
|
8
|
+
};
|
|
9
|
+
table: {
|
|
10
|
+
type: string;
|
|
11
|
+
pattern: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare const tableRelationSchema: {
|
|
17
|
+
params: {
|
|
18
|
+
type: string;
|
|
19
|
+
additionalProperties: boolean;
|
|
20
|
+
required: string[];
|
|
21
|
+
properties: {
|
|
22
|
+
id: {
|
|
23
|
+
type: string;
|
|
24
|
+
pattern: string;
|
|
25
|
+
};
|
|
26
|
+
table: {
|
|
27
|
+
type: string;
|
|
28
|
+
pattern: string;
|
|
29
|
+
};
|
|
30
|
+
relname: {
|
|
31
|
+
type: string;
|
|
32
|
+
pattern: string;
|
|
33
|
+
};
|
|
34
|
+
relationId: {
|
|
35
|
+
type: string;
|
|
36
|
+
pattern: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
querystring: {
|
|
41
|
+
type: string;
|
|
42
|
+
additionalProperties: boolean;
|
|
43
|
+
properties: {
|
|
44
|
+
limit: {
|
|
45
|
+
type: string;
|
|
46
|
+
minimum: number;
|
|
47
|
+
maximum: number;
|
|
48
|
+
};
|
|
49
|
+
page: {
|
|
50
|
+
type: string;
|
|
51
|
+
minimum: number;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export declare const createTableRelationSchema: {
|
|
57
|
+
params: {
|
|
58
|
+
type: string;
|
|
59
|
+
additionalProperties: boolean;
|
|
60
|
+
required: string[];
|
|
61
|
+
properties: {
|
|
62
|
+
id: {
|
|
63
|
+
type: string;
|
|
64
|
+
pattern: string;
|
|
65
|
+
};
|
|
66
|
+
table: {
|
|
67
|
+
type: string;
|
|
68
|
+
pattern: string;
|
|
69
|
+
};
|
|
70
|
+
relname: {
|
|
71
|
+
type: string;
|
|
72
|
+
pattern: string;
|
|
73
|
+
};
|
|
74
|
+
relationId: {
|
|
75
|
+
type: string;
|
|
76
|
+
pattern: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
body: {
|
|
81
|
+
type: string;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
export declare const updateTableRelationSchema: {
|
|
85
|
+
params: {
|
|
86
|
+
type: string;
|
|
87
|
+
additionalProperties: boolean;
|
|
88
|
+
required: string[];
|
|
89
|
+
properties: {
|
|
90
|
+
id: {
|
|
91
|
+
type: string;
|
|
92
|
+
pattern: string;
|
|
93
|
+
};
|
|
94
|
+
table: {
|
|
95
|
+
type: string;
|
|
96
|
+
pattern: string;
|
|
97
|
+
};
|
|
98
|
+
relname: {
|
|
99
|
+
type: string;
|
|
100
|
+
pattern: string;
|
|
101
|
+
};
|
|
102
|
+
relationId: {
|
|
103
|
+
type: string;
|
|
104
|
+
pattern: string;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
body: {
|
|
109
|
+
type: string;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
declare const _default: null;
|
|
113
|
+
export default _default;
|
|
114
|
+
//# sourceMappingURL=crud.schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crud.schema.d.ts","sourceRoot":"","sources":["../../../../server/routes/crud/crud.schema.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAQvB,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoB/B,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAerC,CAAC;AAEF,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAerC,CAAC;;AAEF,wBAAoB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const idSchema = { type: "string", pattern: "^([\\w\\d_.]+)$" };
|
|
2
|
+
export const tableSchema = {
|
|
3
|
+
params: {
|
|
4
|
+
type: "object",
|
|
5
|
+
properties: {
|
|
6
|
+
id: idSchema,
|
|
7
|
+
table: idSchema,
|
|
8
|
+
},
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
export const tableRelationSchema = {
|
|
12
|
+
params: {
|
|
13
|
+
type: "object",
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
required: ["id", "table", "relname"],
|
|
16
|
+
properties: {
|
|
17
|
+
id: idSchema,
|
|
18
|
+
table: idSchema,
|
|
19
|
+
relname: idSchema,
|
|
20
|
+
relationId: idSchema,
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
querystring: {
|
|
24
|
+
type: "object",
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
properties: {
|
|
27
|
+
limit: { type: "integer", minimum: 1, maximum: 100 },
|
|
28
|
+
page: { type: "integer", minimum: 1 },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export const createTableRelationSchema = {
|
|
33
|
+
params: {
|
|
34
|
+
type: "object",
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
required: ["id", "table", "relname"],
|
|
37
|
+
properties: {
|
|
38
|
+
id: idSchema,
|
|
39
|
+
table: idSchema,
|
|
40
|
+
relname: idSchema,
|
|
41
|
+
relationId: idSchema,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
body: {
|
|
45
|
+
type: "object",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
export const updateTableRelationSchema = {
|
|
49
|
+
params: {
|
|
50
|
+
type: "object",
|
|
51
|
+
additionalProperties: false,
|
|
52
|
+
required: ["id", "table", "relname", "relationId"],
|
|
53
|
+
properties: {
|
|
54
|
+
id: idSchema,
|
|
55
|
+
table: idSchema,
|
|
56
|
+
relname: idSchema,
|
|
57
|
+
relationId: idSchema,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
body: {
|
|
61
|
+
type: "object",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
export default null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function createTableRelation({ table: paramsTable, form: paramsForm, id: paramsId, relname, relationId, body, uid, userType, referer, called, }: {
|
|
2
|
+
table: string;
|
|
3
|
+
form?: string;
|
|
4
|
+
id: string;
|
|
5
|
+
relname: string;
|
|
6
|
+
relationId?: string;
|
|
7
|
+
body: Record<string, any>;
|
|
8
|
+
uid?: string;
|
|
9
|
+
userType?: string;
|
|
10
|
+
referer?: string;
|
|
11
|
+
called?: boolean;
|
|
12
|
+
}, pg?: any): Promise<any>;
|
|
13
|
+
//# sourceMappingURL=createTableRelation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTableRelation.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/functions/createTableRelation.ts"],"names":[],"mappings":"AAqBA,wBAA8B,mBAAmB,CAC/C,EACE,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,UAAU,EAChB,EAAE,EAAE,QAAQ,EACZ,OAAO,EACP,UAAU,EACV,IAAI,EACJ,GAAG,EACH,QAAQ,EACR,OAAO,EACP,MAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB,gBAiItB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// import config from "../../../../config.js";
|
|
2
|
+
import pgClients from "../../../plugins/pg/pgClients.js";
|
|
3
|
+
import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
|
|
4
|
+
import dataInsert from "../../../plugins/crud/funcs/dataInsert.js";
|
|
5
|
+
import getAccess from "../../../plugins/crud/funcs/getAccess.js";
|
|
6
|
+
import checkXSS from "../../../plugins/policy/funcs/checkXSS.js";
|
|
7
|
+
import validateData from "../../../plugins/crud/funcs/validateData.js";
|
|
8
|
+
import logger from "../../../plugins/logger/getLogger.js";
|
|
9
|
+
import { resourcesObject } from "../../../plugins/access/funcs/getResources.js";
|
|
10
|
+
import { BadRequestError, ConflictError, ForbiddenError, NotFoundError, UnauthorizedError, } from "../../../../errors.js";
|
|
11
|
+
export default async function createTableRelation({ table: paramsTable, form: paramsForm, id: paramsId, relname, relationId, body, uid, userType, referer, called = false, }, pg = pgClients.client) {
|
|
12
|
+
if (!uid) {
|
|
13
|
+
throw UnauthorizedError("unauthorized");
|
|
14
|
+
}
|
|
15
|
+
const resource = resourcesObject[paramsTable]?.table
|
|
16
|
+
? paramsTable
|
|
17
|
+
: undefined;
|
|
18
|
+
const mainForm = paramsForm || resourcesObject[paramsTable]?.form;
|
|
19
|
+
const mainTable = resourcesObject[paramsTable]?.table || paramsTable;
|
|
20
|
+
const { actions = [], message: accessMessage } = (await getAccess({
|
|
21
|
+
resource,
|
|
22
|
+
table: mainTable,
|
|
23
|
+
form: mainForm,
|
|
24
|
+
user: { uid, user_type: userType },
|
|
25
|
+
method: "POST",
|
|
26
|
+
}, pg)) || {};
|
|
27
|
+
if (accessMessage) {
|
|
28
|
+
throw ForbiddenError(accessMessage);
|
|
29
|
+
}
|
|
30
|
+
if (!actions.includes("add") && !called) {
|
|
31
|
+
throw ForbiddenError("access restricted: actions");
|
|
32
|
+
}
|
|
33
|
+
const loadTemplate = await getTemplate("table", mainTable);
|
|
34
|
+
if (!loadTemplate) {
|
|
35
|
+
throw NotFoundError(`table not found: ${mainTable}`);
|
|
36
|
+
}
|
|
37
|
+
const { relations = {} } = loadTemplate || {};
|
|
38
|
+
if (!relations[relname]) {
|
|
39
|
+
throw NotFoundError(`table relation not found: ${relname}`);
|
|
40
|
+
}
|
|
41
|
+
const { table: relationTable, form: relationForm,
|
|
42
|
+
// localKey = relations[relname]?.localKey,
|
|
43
|
+
foreignKey = relations[relname]?.foreignKey, } = relations[relname]?.resource
|
|
44
|
+
? resourcesObject[relations[relname].resource]
|
|
45
|
+
: relations[relname];
|
|
46
|
+
if (!foreignKey) {
|
|
47
|
+
throw new Error("invalid relation: foreignKey not set");
|
|
48
|
+
}
|
|
49
|
+
const relationTableTemplate = await getTemplate("table", relationTable);
|
|
50
|
+
const formData = await getTemplate("form", relationTableTemplate?.form || relationForm);
|
|
51
|
+
const schema = formData?.schema || formData;
|
|
52
|
+
const xssCheck = checkXSS({ body, schema });
|
|
53
|
+
if (xssCheck.error && formData?.xssCheck !== false) {
|
|
54
|
+
logger.file("injection/xss", {
|
|
55
|
+
table: relationTable,
|
|
56
|
+
form: relationForm,
|
|
57
|
+
body,
|
|
58
|
+
uid,
|
|
59
|
+
msg: xssCheck.error,
|
|
60
|
+
});
|
|
61
|
+
throw ConflictError("Дані містять заборонені символи. Приберіть їх та спробуйте ще раз");
|
|
62
|
+
}
|
|
63
|
+
const fieldCheck = validateData({ body, schema });
|
|
64
|
+
if (fieldCheck.error) {
|
|
65
|
+
logger.file("injection/formdata", {
|
|
66
|
+
table: relationTable,
|
|
67
|
+
form: relationForm,
|
|
68
|
+
uid,
|
|
69
|
+
...fieldCheck,
|
|
70
|
+
});
|
|
71
|
+
throw ConflictError("Дані не пройшли валідацію. Приберіть некоректні дані та спробуйте ще раз");
|
|
72
|
+
}
|
|
73
|
+
if (relationTable !== "admin.users") {
|
|
74
|
+
Object.assign(body, { uid, editor_id: uid });
|
|
75
|
+
}
|
|
76
|
+
const res = await dataInsert({
|
|
77
|
+
pg,
|
|
78
|
+
id: relationId || body.id,
|
|
79
|
+
table: relationTableTemplate?.table || relationTable,
|
|
80
|
+
data: { ...body, [foreignKey]: paramsId },
|
|
81
|
+
uid,
|
|
82
|
+
referer,
|
|
83
|
+
});
|
|
84
|
+
if (!res) {
|
|
85
|
+
throw BadRequestError("nothing added");
|
|
86
|
+
}
|
|
87
|
+
if (Array.isArray(body.files) && res?.id) {
|
|
88
|
+
await Promise.all(body.files
|
|
89
|
+
.filter((el) => el.file_id && el.file_path)
|
|
90
|
+
.map(async (el) => pg.query("update crm.files set entity_id=$1 where entity_id = 'uploads' and file_id=$2 and file_path=$3", [res.id, el.file_id, el.file_path])));
|
|
91
|
+
}
|
|
92
|
+
return { id: res?.id, ...(res || {}) };
|
|
93
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function deleteTableRelation({ table: paramsTable, id: paramsId, form: paramsForm, relname, relationId, uid, userType, called, }: {
|
|
2
|
+
table: string;
|
|
3
|
+
id: string;
|
|
4
|
+
form?: string;
|
|
5
|
+
relname: string;
|
|
6
|
+
relationId: string;
|
|
7
|
+
uid?: string;
|
|
8
|
+
userType?: string;
|
|
9
|
+
called?: boolean;
|
|
10
|
+
}, pg?: any): Promise<any>;
|
|
11
|
+
//# sourceMappingURL=deleteTableRelation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deleteTableRelation.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/functions/deleteTableRelation.ts"],"names":[],"mappings":"AAgBA,wBAA8B,mBAAmB,CAC/C,EACE,KAAK,EAAE,WAAW,EAClB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,UAAU,EAChB,OAAO,EACP,UAAU,EACV,GAAG,EACH,QAAQ,EACR,MAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB,gBAuGtB"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// import config from "../../../../config.js";
|
|
2
|
+
import pgClients from "../../../plugins/pg/pgClients.js";
|
|
3
|
+
import getTemplate from "../../../plugins/table/funcs/getTemplate.js";
|
|
4
|
+
import getAccess from "../../../plugins/crud/funcs/getAccess.js";
|
|
5
|
+
import { resourcesObject } from "../../../plugins/access/funcs/getResources.js";
|
|
6
|
+
import { BadRequestError, ForbiddenError, NotFoundError, UnauthorizedError, } from "../../../../errors.js";
|
|
7
|
+
export default async function deleteTableRelation({ table: paramsTable, id: paramsId, form: paramsForm, relname, relationId, uid, userType, called = false, }, pg = pgClients.client) {
|
|
8
|
+
if (!uid) {
|
|
9
|
+
throw UnauthorizedError("unauthorized");
|
|
10
|
+
}
|
|
11
|
+
if (!relationId) {
|
|
12
|
+
throw BadRequestError("not enough params: relationId");
|
|
13
|
+
}
|
|
14
|
+
const resource = resourcesObject[paramsTable] ? paramsTable : undefined;
|
|
15
|
+
const mainTable = resourcesObject[paramsTable]?.table || paramsTable;
|
|
16
|
+
const { actions = [], message: accessMessage } = (await getAccess({
|
|
17
|
+
resource,
|
|
18
|
+
table: mainTable,
|
|
19
|
+
form: resourcesObject[paramsTable]?.form || paramsForm,
|
|
20
|
+
id: paramsId,
|
|
21
|
+
user: { uid, user_type: userType },
|
|
22
|
+
method: "DELETE",
|
|
23
|
+
}, pg)) || {};
|
|
24
|
+
if (accessMessage && !called) {
|
|
25
|
+
throw ForbiddenError(accessMessage);
|
|
26
|
+
}
|
|
27
|
+
if (!actions.includes("del") && !called) {
|
|
28
|
+
throw ForbiddenError("access restricted: actions");
|
|
29
|
+
}
|
|
30
|
+
const loadTemplate = await getTemplate("table", mainTable);
|
|
31
|
+
if (!loadTemplate) {
|
|
32
|
+
throw NotFoundError(`table not found: ${mainTable}`);
|
|
33
|
+
}
|
|
34
|
+
const { relations = {} } = loadTemplate || {};
|
|
35
|
+
if (!relations[relname]) {
|
|
36
|
+
throw NotFoundError(`table relation not found: ${relname}`);
|
|
37
|
+
}
|
|
38
|
+
const { table: relationTable, foreignKey = relations[relname]?.foreignKey } = relations[relname]?.resource
|
|
39
|
+
? resourcesObject[relations[relname].resource]
|
|
40
|
+
: relations[relname];
|
|
41
|
+
if (!foreignKey) {
|
|
42
|
+
throw new Error("invalid relation: foreignKey not set");
|
|
43
|
+
}
|
|
44
|
+
const relationTableTemplate = await getTemplate("table", relationTable);
|
|
45
|
+
const pks = await pg
|
|
46
|
+
.query(`
|
|
47
|
+
SELECT
|
|
48
|
+
connamespace::regnamespace::text,
|
|
49
|
+
conrelid::regclass,
|
|
50
|
+
(
|
|
51
|
+
SELECT attname FROM pg_attribute WHERE attrelid = c.conrelid AND attnum = c.conkey[1]
|
|
52
|
+
) as pk
|
|
53
|
+
FROM pg_constraint c
|
|
54
|
+
WHERE contype = 'p'
|
|
55
|
+
AND connamespace::regnamespace::text NOT IN ('sde')`)
|
|
56
|
+
.then((r) => r.rows || []);
|
|
57
|
+
const pkList = pks.reduce((acc, curr) => ({
|
|
58
|
+
...acc,
|
|
59
|
+
[curr.connamespace === "public"
|
|
60
|
+
? `${curr.connamespace}.${curr.conrelid}`
|
|
61
|
+
: curr.conrelid]: curr.pk,
|
|
62
|
+
}), {});
|
|
63
|
+
const relationPk = pkList[relationTableTemplate?.table || relationTable];
|
|
64
|
+
if (!relationPk) {
|
|
65
|
+
throw NotFoundError("invalid relation: primary key column not found");
|
|
66
|
+
}
|
|
67
|
+
const row = await pg
|
|
68
|
+
.query(`delete from ${relationTableTemplate?.table || relationTable} where ${foreignKey}=$1 and ${relationPk}=$2 returning *`, [paramsId, relationId])
|
|
69
|
+
.then((r) => r.rows?.[0]);
|
|
70
|
+
if (!row) {
|
|
71
|
+
throw NotFoundError(`relation row not found: ${relationId}`);
|
|
72
|
+
}
|
|
73
|
+
return { id: relationId, ...row };
|
|
74
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default function readTableRelations({ table: paramsTable, id, relname, relationId, uid, userType, referer, limit, page, called, }: {
|
|
2
|
+
table: string;
|
|
3
|
+
id: string;
|
|
4
|
+
relname: string;
|
|
5
|
+
relationId?: string;
|
|
6
|
+
uid: string;
|
|
7
|
+
userType?: string;
|
|
8
|
+
referer?: string;
|
|
9
|
+
limit?: number;
|
|
10
|
+
page?: number;
|
|
11
|
+
called?: boolean;
|
|
12
|
+
}, pg?: any): Promise<{
|
|
13
|
+
count: any;
|
|
14
|
+
filtered: any;
|
|
15
|
+
total: any;
|
|
16
|
+
limit: number;
|
|
17
|
+
page: number;
|
|
18
|
+
rows: any;
|
|
19
|
+
schema: any;
|
|
20
|
+
} | {
|
|
21
|
+
id: string;
|
|
22
|
+
data: any;
|
|
23
|
+
schema: any;
|
|
24
|
+
}>;
|
|
25
|
+
//# sourceMappingURL=readTableRelations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"readTableRelations.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/functions/readTableRelations.ts"],"names":[],"mappings":"AAcA,wBAA8B,kBAAkB,CAC9C,EACE,KAAK,EAAE,WAAW,EAClB,EAAE,EACF,OAAO,EACP,UAAU,EACV,GAAG,EACH,QAAQ,EACR,OAAO,EACP,KAAU,EACV,IAAQ,EACR,MAAc,GACf,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB,EACD,EAAE,MAAmB;;;;;;;;;;;;GAkGtB"}
|