|
1 | 1 | import { GraphQLNonNull, GraphQLID, GraphQLError } from 'graphql'; |
2 | 2 | import { DashboardType } from '../types'; |
3 | | -import { |
4 | | - ApiConfiguration, |
5 | | - Dashboard, |
6 | | - Page, |
7 | | - Record, |
8 | | - ReferenceData, |
9 | | -} from '@models'; |
| 3 | +import { Dashboard } from '@models'; |
10 | 4 | import extendAbilityForContent from '@security/extendAbilityForContent'; |
11 | | -import { CustomAPI } from '@server/apollo/dataSources'; |
12 | | -import { Types } from 'mongoose'; |
13 | 5 | import { logger } from '@services/logger.service'; |
14 | 6 |
|
15 | 7 | /** |
@@ -39,55 +31,58 @@ export default { |
39 | 31 | context.i18next.t('common.errors.permissionNotGranted') |
40 | 32 | ); |
41 | 33 | } |
| 34 | + // todo: reactivate if we want to inject context in dashboard |
42 | 35 | // Check if dashboard has context linked to it |
43 | | - const page = await Page.findOne({ |
44 | | - contentWithContext: { $elemMatch: { content: args.id } }, |
45 | | - }); |
| 36 | + // const page = await Page.findOne({ |
| 37 | + // contentWithContext: { $elemMatch: { content: args.id } }, |
| 38 | + // }); |
46 | 39 |
|
47 | 40 | // If a page was found, means the dashboard has context |
48 | | - if (page && page.context) { |
49 | | - // get the id of the resource or refData |
50 | | - const contentWithContext = page.contentWithContext.find((c) => |
51 | | - (c.content as Types.ObjectId).equals(args.id) |
52 | | - ); |
53 | | - const id = |
54 | | - 'element' in contentWithContext && contentWithContext.element |
55 | | - ? contentWithContext.element |
56 | | - : 'record' in contentWithContext && contentWithContext.record |
57 | | - ? contentWithContext.record |
58 | | - : null; |
| 41 | + // if (page && page.context) { |
| 42 | + // // get the id of the resource or refData |
| 43 | + // const contentWithContext = page.contentWithContext.find((c) => |
| 44 | + // (c.content as Types.ObjectId).equals(args.id) |
| 45 | + // ); |
| 46 | + // const id = |
| 47 | + // 'element' in contentWithContext && contentWithContext.element |
| 48 | + // ? contentWithContext.element |
| 49 | + // : 'record' in contentWithContext && contentWithContext.record |
| 50 | + // ? contentWithContext.record |
| 51 | + // : null; |
59 | 52 |
|
60 | | - const ctx = page.context; |
61 | | - let data: any; |
| 53 | + // const ctx = page.context; |
| 54 | + // let data: any; |
62 | 55 |
|
63 | | - if ('resource' in ctx && ctx.resource) { |
64 | | - const record = await Record.findById(id); |
65 | | - data = record.data; |
66 | | - } else if ('refData' in ctx && ctx.refData) { |
67 | | - // get refData from page |
68 | | - const referenceData = await ReferenceData.findById(ctx.refData); |
69 | | - const apiConfiguration = await ApiConfiguration.findById( |
70 | | - referenceData.apiConfiguration |
71 | | - ); |
72 | | - const items = apiConfiguration |
73 | | - ? await ( |
74 | | - context.dataSources[apiConfiguration.name] as CustomAPI |
75 | | - ).getReferenceDataItems(referenceData, apiConfiguration) |
76 | | - : referenceData.data; |
77 | | - data = items.find((x) => x[referenceData.valueField] === id); |
78 | | - } |
| 56 | + // if ('resource' in ctx && ctx.resource) { |
| 57 | + // const record = await Record.findById(id); |
| 58 | + // data = record.data; |
| 59 | + // } else if ('refData' in ctx && ctx.refData) { |
| 60 | + // // get refData from page |
| 61 | + // const referenceData = await ReferenceData.findById(ctx.refData); |
| 62 | + // const apiConfiguration = await ApiConfiguration.findById( |
| 63 | + // referenceData.apiConfiguration |
| 64 | + // ); |
| 65 | + // const items = apiConfiguration |
| 66 | + // ? await ( |
| 67 | + // context.dataSources[apiConfiguration.name] as CustomAPI |
| 68 | + // ).getReferenceDataItems(referenceData, apiConfiguration) |
| 69 | + // : referenceData.data; |
| 70 | + // data = items.find((x) => x[referenceData.valueField] === id); |
| 71 | + // } |
79 | 72 |
|
80 | | - const stringifiedStructure = JSON.stringify(dashboard.structure); |
81 | | - const regex = /{{context\.(.*?)}}/g; |
| 73 | + // const stringifiedStructure = JSON.stringify(dashboard.structure); |
| 74 | + // const regex = /{{context\.(.*?)}}/g; |
82 | 75 |
|
83 | | - // replace all {{context.<field>}} with the value from the data |
84 | | - dashboard.structure = JSON.parse( |
85 | | - stringifiedStructure.replace(regex, (match) => { |
86 | | - const field = match.replace('{{context.', '').replace('}}', ''); |
87 | | - return data[field] || match; |
88 | | - }) |
89 | | - ); |
90 | | - } |
| 76 | + // console.log(stringifiedStructure); |
| 77 | + |
| 78 | + // // replace all {{context.<field>}} with the value from the data |
| 79 | + // dashboard.structure = JSON.parse( |
| 80 | + // stringifiedStructure.replace(regex, (match) => { |
| 81 | + // const field = match.replace('{{context.', '').replace('}}', ''); |
| 82 | + // return data[field] || match; |
| 83 | + // }) |
| 84 | + // ); |
| 85 | + // } |
91 | 86 | return dashboard; |
92 | 87 | } catch (err) { |
93 | 88 | logger.error(err.message, { stack: err.stack }); |
|
0 commit comments