@steedos/data-import 2.1.37 → 2.1.38

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.
@@ -14,29 +14,53 @@ import _ from 'lodash';
14
14
  // declare var Meteor: any;
15
15
  declare var Steedos: any;
16
16
 
17
+ /**
18
+ * @param req
19
+ * @param res
20
+ * @returns
21
+ */
17
22
  const initiateImport = async function (req, res) {
18
23
  try {
19
- const userSession = req.user;
20
- // const spaceId = userSession.spaceId;
24
+ const userSession = req.user;
25
+ // const spaceId = userSession.spaceId;
26
+ let { importObjId, importObjectHistoryId } = req.body;
27
+ let fileId = null;
28
+ const isSpaceAdmin = req.user.is_space_admin;
29
+ //传入了importObjId参数,必须是工作区管理员权限
30
+ if (importObjId && !isSpaceAdmin) {
31
+ return res
32
+ .status(401)
33
+ .send({ status: "error", message: "Permission denied" });
34
+ }
21
35
 
22
- const isSpaceAdmin = req.user.is_space_admin;
23
- if (!isSpaceAdmin) {
24
- return res.status(401).send({ status: 'error', message: 'Permission denied' });
25
- }
36
+ if (importObjectHistoryId) {
37
+ const record = await getObject('queue_import_history').findOne(importObjectHistoryId);
38
+ if(!record){
39
+ throw new Error(
40
+ `can not find queue_import_history record with given id "${importObjectHistoryId}"`
41
+ );
42
+ }
43
+ if(!record.file){
44
+ throw new Error(`Upload excel file, please.`);
45
+ }
46
+ fileId = record.file
47
+ importObjId = record.queue_import
48
+ }
26
49
 
27
- // if (!Steedos.hasFeature('metadata_api', spaceId)) {
28
- // return res.status(403).send({ status: 'error', message: 'Please upgrade the platform license to Enterprise Edition' });
29
- // }
30
- const importObjId = req.body.importObjId;
31
- try {
32
- let result = await importWithCmsFile(importObjId, userSession);
33
- return res.status(200).send({ status: 'success', result });
34
- } catch (error) {
35
- return res.status(500).send({ status: 'failed', message: error.message });
36
- }
50
+ // if (!Steedos.hasFeature('metadata_api', spaceId)) {
51
+ // return res.status(403).send({ status: 'error', message: 'Please upgrade the platform license to Enterprise Edition' });
52
+ // }
37
53
 
54
+ try {
55
+ let result = await importWithCmsFile(importObjId, userSession, importObjectHistoryId, fileId);
56
+ return res.status(200).send({ status: "success", result });
57
+ } catch (error) {
58
+ return res
59
+ .status(500)
60
+ .send({ status: "failed", message: error.message });
61
+ }
38
62
  } catch (error) {
39
- return res.status(500).send({ status: 'failed', error: error.message });
63
+ return res.status(500).send({ status: "failed", error: error.message });
40
64
  }
41
65
  }
42
66