@dssp/supervision 1.0.0-alpha.0 → 1.0.0-alpha.1

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.
Files changed (99) hide show
  1. package/dist-client/pages/building-inspection/building-inspection-detail-checklist.js +1 -1
  2. package/dist-client/pages/building-inspection/building-inspection-detail-checklist.js.map +1 -1
  3. package/dist-client/route.d.ts +1 -1
  4. package/dist-client/tsconfig.tsbuildinfo +1 -1
  5. package/package.json +5 -5
  6. package/client/bootstrap.ts +0 -1
  7. package/client/index.ts +0 -0
  8. package/client/pages/action-plan/action-plan-importer.ts +0 -94
  9. package/client/pages/action-plan/action-plan-list-page.ts +0 -340
  10. package/client/pages/building-inspection/building-inspection-detail-camera.ts +0 -277
  11. package/client/pages/building-inspection/building-inspection-detail-checklist.ts +0 -258
  12. package/client/pages/building-inspection/building-inspection-detail-drawing.ts +0 -288
  13. package/client/pages/building-inspection/building-inspection-list.ts +0 -565
  14. package/client/pages/building-inspection/component/building-inspection-detail-header.ts +0 -123
  15. package/client/pages/building-inspection/component/inspection-event-provider.ts +0 -81
  16. package/client/pages/building-inspection/inspection-create-popup.ts +0 -785
  17. package/client/pages/checklist/attachment-list-popup.ts +0 -301
  18. package/client/pages/checklist/checklist-view.ts +0 -581
  19. package/client/pages/checklist/comment-list-popup.ts +0 -328
  20. package/client/pages/checklist/file-preview-popup.ts +0 -70
  21. package/client/pages/checklist-template/checklist-template-item.ts +0 -240
  22. package/client/pages/checklist-template/checklist-template-list.ts +0 -368
  23. package/client/pages/checklist-template/checklist-type-management.ts +0 -262
  24. package/client/pages/issue/issue-importer.ts +0 -94
  25. package/client/pages/issue/issue-list-page.ts +0 -340
  26. package/client/pages/project-report/project-report-importer.ts +0 -94
  27. package/client/pages/project-report/project-report-list-page.ts +0 -340
  28. package/client/pages/supervisor/supervisor-importer.ts +0 -94
  29. package/client/pages/supervisor/supervisor-list-page.ts +0 -340
  30. package/client/route.ts +0 -27
  31. package/client/tsconfig.json +0 -11
  32. package/server/controllers/index.ts +0 -0
  33. package/server/index.ts +0 -4
  34. package/server/middlewares/index.ts +0 -3
  35. package/server/migrations/index.ts +0 -9
  36. package/server/routes.ts +0 -28
  37. package/server/service/action-plan/action-plan-mutation.ts +0 -198
  38. package/server/service/action-plan/action-plan-query.ts +0 -62
  39. package/server/service/action-plan/action-plan-type.ts +0 -61
  40. package/server/service/action-plan/action-plan.ts +0 -103
  41. package/server/service/action-plan/index.ts +0 -7
  42. package/server/service/building-inspection/building-inspection-history.ts +0 -72
  43. package/server/service/building-inspection/building-inspection-mutation.ts +0 -276
  44. package/server/service/building-inspection/building-inspection-query.ts +0 -242
  45. package/server/service/building-inspection/building-inspection-type.ts +0 -145
  46. package/server/service/building-inspection/building-inspection.ts +0 -108
  47. package/server/service/building-inspection/event-subscriber.ts +0 -20
  48. package/server/service/building-inspection/index.ts +0 -11
  49. package/server/service/checklist/checklist-history.ts +0 -96
  50. package/server/service/checklist/checklist-mutation.ts +0 -103
  51. package/server/service/checklist/checklist-query.ts +0 -58
  52. package/server/service/checklist/checklist-type.ts +0 -49
  53. package/server/service/checklist/checklist.ts +0 -127
  54. package/server/service/checklist/event-subscriber.ts +0 -17
  55. package/server/service/checklist/index.ts +0 -9
  56. package/server/service/checklist-item/checklist-item-mutation.ts +0 -5
  57. package/server/service/checklist-item/checklist-item-query.ts +0 -84
  58. package/server/service/checklist-item/checklist-item-type.ts +0 -12
  59. package/server/service/checklist-item/checklist-item.ts +0 -103
  60. package/server/service/checklist-item/index.ts +0 -7
  61. package/server/service/checklist-item-comment/checklist-item-comment-history.ts +0 -69
  62. package/server/service/checklist-item-comment/checklist-item-comment-mutation.ts +0 -80
  63. package/server/service/checklist-item-comment/checklist-item-comment-query.ts +0 -36
  64. package/server/service/checklist-item-comment/checklist-item-comment-type.ts +0 -32
  65. package/server/service/checklist-item-comment/checklist-item-comment.ts +0 -56
  66. package/server/service/checklist-item-comment/event-subscriber.ts +0 -17
  67. package/server/service/checklist-item-comment/index.ts +0 -9
  68. package/server/service/checklist-template/checklist-template-mutation.ts +0 -66
  69. package/server/service/checklist-template/checklist-template-query.ts +0 -39
  70. package/server/service/checklist-template/checklist-template-type.ts +0 -23
  71. package/server/service/checklist-template/checklist-template.ts +0 -71
  72. package/server/service/checklist-template/index.ts +0 -6
  73. package/server/service/checklist-template-item/checklist-template-item-mutation.ts +0 -64
  74. package/server/service/checklist-template-item/checklist-template-item-query.ts +0 -44
  75. package/server/service/checklist-template-item/checklist-template-item-type.ts +0 -39
  76. package/server/service/checklist-template-item/checklist-template-item.ts +0 -68
  77. package/server/service/checklist-template-item/index.ts +0 -6
  78. package/server/service/checklist-type/checklist-type-mutation.ts +0 -66
  79. package/server/service/checklist-type/checklist-type-query.ts +0 -39
  80. package/server/service/checklist-type/checklist-type-type.ts +0 -26
  81. package/server/service/checklist-type/checklist-type.ts +0 -64
  82. package/server/service/checklist-type/index.ts +0 -6
  83. package/server/service/index.ts +0 -88
  84. package/server/service/issue/index.ts +0 -7
  85. package/server/service/issue/issue-mutation.ts +0 -198
  86. package/server/service/issue/issue-query.ts +0 -62
  87. package/server/service/issue/issue-type.ts +0 -61
  88. package/server/service/issue/issue.ts +0 -100
  89. package/server/service/project-report/index.ts +0 -7
  90. package/server/service/project-report/project-report-mutation.ts +0 -198
  91. package/server/service/project-report/project-report-query.ts +0 -62
  92. package/server/service/project-report/project-report-type.ts +0 -61
  93. package/server/service/project-report/project-report.ts +0 -113
  94. package/server/service/supervisor/index.ts +0 -7
  95. package/server/service/supervisor/supervisor-mutation.ts +0 -198
  96. package/server/service/supervisor/supervisor-query.ts +0 -62
  97. package/server/service/supervisor/supervisor-type.ts +0 -61
  98. package/server/service/supervisor/supervisor.ts +0 -108
  99. package/server/tsconfig.json +0 -10
@@ -1,340 +0,0 @@
1
- import '@material/web/icon/icon.js'
2
- import '@operato/data-grist'
3
-
4
- import { CommonButtonStyles, CommonGristStyles, ScrollbarStyles } from '@operato/styles'
5
- import { PageView, store } from '@operato/shell'
6
- import { css, html } from 'lit'
7
- import { customElement, property, query, state } from 'lit/decorators.js'
8
- import { ScopedElementsMixin } from '@open-wc/scoped-elements'
9
- import { ColumnConfig, DataGrist, FetchOption, SortersControl } from '@operato/data-grist'
10
- import { client } from '@operato/graphql'
11
- import { i18next, localize } from '@operato/i18n'
12
- import { notify, openPopup } from '@operato/layout'
13
- import { OxPopup, OxPrompt } from '@operato/popup'
14
- import { isMobileDevice } from '@operato/utils'
15
-
16
- import { connect } from 'pwa-helpers/connect-mixin'
17
- import gql from 'graphql-tag'
18
-
19
- import { SupervisorImporter } from './supervisor-importer'
20
-
21
- @customElement('supervisor-list-page')
22
- export class SupervisorListPage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
23
- static styles = [
24
- ScrollbarStyles,
25
- CommonGristStyles,
26
- css`
27
- :host {
28
- display: flex;
29
-
30
- width: 100%;
31
-
32
- --grid-record-emphasized-background-color: red;
33
- --grid-record-emphasized-color: yellow;
34
- }
35
- `
36
- ]
37
-
38
- static get scopedElements() {
39
- return {
40
- 'supervisor-importer': SupervisorImporter
41
- }
42
- }
43
-
44
- @state() private gristConfig: any
45
- @state() private mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'
46
-
47
- @query('ox-grist') private grist!: DataGrist
48
- @query('#sorter-control') private sortersControl!: OxPopup
49
-
50
- get context() {
51
- return {
52
- title: i18next.t('title.supervisor list'),
53
- search: {
54
- handler: (search: string) => {
55
- this.grist.searchText = search
56
- },
57
- value: this.grist.searchText
58
- },
59
- filter: {
60
- handler: () => {
61
- this.grist.toggleHeadroom()
62
- }
63
- },
64
- help: 'supervision/supervisor',
65
- actions: [
66
- {
67
- title: i18next.t('button.save'),
68
- action: this.updateSupervisor.bind(this),
69
- ...CommonButtonStyles.save
70
- },
71
- {
72
- title: i18next.t('button.delete'),
73
- action: this.deleteSupervisor.bind(this),
74
- ...CommonButtonStyles.delete
75
- }
76
- ],
77
- exportable: {
78
- name: i18next.t('title.supervisor list'),
79
- data: this.exportHandler.bind(this)
80
- },
81
- importable: {
82
- handler: this.importHandler.bind(this)
83
- }
84
- }
85
- }
86
-
87
- render() {
88
- const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')
89
-
90
- return html`
91
- <ox-grist .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
92
- <div slot="headroom">
93
- <div id="filters">
94
- <ox-filters-form autofocus></ox-filters-form>
95
- </div>
96
-
97
- <div id="sorters">
98
- Sort
99
- <md-icon
100
- @click=${e => {
101
- const target = e.currentTarget
102
- this.sortersControl.open({
103
- right: 0,
104
- top: target.offsetTop + target.offsetHeight
105
- })
106
- }}
107
- >expand_more</md-icon
108
- >
109
- <ox-popup id="sorter-control">
110
- <ox-sorters-control> </ox-sorters-control>
111
- </ox-popup>
112
- </div>
113
-
114
- <div id="modes">
115
- <md-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</md-icon>
116
- <md-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</md-icon>
117
- <md-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</md-icon>
118
- </div>
119
- </div>
120
- </ox-grist>
121
- `
122
- }
123
-
124
- async pageInitialized(lifecycle: any) {
125
- this.gristConfig = {
126
- list: {
127
- fields: ['name', 'description'],
128
- details: ['active', 'updatedAt']
129
- },
130
- columns: [
131
- { type: 'gutter', gutterName: 'sequence' },
132
- { type: 'gutter', gutterName: 'row-selector', multiple: true },
133
- {
134
- type: 'string',
135
- name: 'name',
136
- header: i18next.t('field.name'),
137
- record: {
138
- editable: true
139
- },
140
- filter: 'search',
141
- sortable: true,
142
- width: 150
143
- },
144
- {
145
- type: 'string',
146
- name: 'description',
147
- header: i18next.t('field.description'),
148
- record: {
149
- editable: true
150
- },
151
- filter: 'search',
152
- width: 200
153
- },
154
- {
155
- type: 'checkbox',
156
- name: 'active',
157
- label: true,
158
- header: i18next.t('field.active'),
159
- record: {
160
- editable: true
161
- },
162
- filter: true,
163
- sortable: true,
164
- width: 60
165
- },
166
- {
167
- type: 'resource-object',
168
- name: 'updater',
169
- header: i18next.t('field.updater'),
170
- record: {
171
- editable: false
172
- },
173
- sortable: true,
174
- width: 120
175
- },
176
- {
177
- type: 'datetime',
178
- name: 'updatedAt',
179
- header: i18next.t('field.updated_at'),
180
- record: {
181
- editable: false
182
- },
183
- sortable: true,
184
- width: 180
185
- }
186
- ],
187
- rows: {
188
- selectable: {
189
- multiple: true
190
- }
191
- },
192
- sorters: [
193
- {
194
- name: 'name'
195
- }
196
- ]
197
- }
198
- }
199
-
200
- async pageUpdated(changes: any, lifecycle: any) {
201
- if (this.active) {
202
- // do something here when this page just became as active
203
- }
204
- }
205
-
206
- async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
207
- const response = await client.query({
208
- query: gql`
209
- query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
210
- responses: supervisors(filters: $filters, pagination: $pagination, sortings: $sortings) {
211
- items {
212
- id
213
- name
214
- description
215
- active
216
- updater {
217
- id
218
- name
219
- }
220
- updatedAt
221
- }
222
- total
223
- }
224
- }
225
- `,
226
- variables: {
227
- filters,
228
- pagination: { page, limit },
229
- sortings
230
- }
231
- })
232
-
233
- return {
234
- total: response.data.responses.total || 0,
235
- records: response.data.responses.items || []
236
- }
237
- }
238
-
239
- private async deleteSupervisor() {
240
- if (
241
- await OxPrompt.open({
242
- title: i18next.t('text.are_you_sure'),
243
- text: i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }),
244
- confirmButton: { text: i18next.t('button.confirm') },
245
- cancelButton: { text: i18next.t('button.cancel') }
246
- })
247
- ) {
248
- const ids = this.grist.selected.map(record => record.id)
249
- if (ids && ids.length > 0) {
250
- const response = await client.mutate({
251
- mutation: gql`
252
- mutation ($ids: [String!]!) {
253
- deleteSupervisors(ids: $ids)
254
- }
255
- `,
256
- variables: {
257
- ids
258
- }
259
- })
260
-
261
- if (!response.errors) {
262
- this.grist.fetch()
263
- notify({
264
- message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
265
- })
266
- }
267
- }
268
- }
269
- }
270
-
271
- private async updateSupervisor() {
272
- let patches = this.grist.dirtyRecords
273
- if (patches && patches.length) {
274
- patches = patches.map(patch => {
275
- let patchField: any = patch.id ? { id: patch.id } : {}
276
- const dirtyFields = patch.__dirtyfields__
277
- for (let key in dirtyFields) {
278
- patchField[key] = dirtyFields[key].after
279
- }
280
- patchField.cuFlag = patch.__dirty__
281
-
282
- return patchField
283
- })
284
-
285
- const response = await client.mutate({
286
- mutation: gql`
287
- mutation ($patches: [SupervisorPatch!]!) {
288
- updateMultipleSupervisor(patches: $patches) {
289
- name
290
- }
291
- }
292
- `,
293
- variables: {
294
- patches
295
- }
296
- })
297
-
298
- if (!response.errors) {
299
- this.grist.fetch()
300
- }
301
- }
302
- }
303
-
304
- private async exportHandler() {
305
- const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records
306
- const targetFieldSet = new Set(['id', 'name', 'description', 'active'])
307
-
308
- return exportTargets.map(supervisor => {
309
- let tempObj = {}
310
- for (const field of targetFieldSet) {
311
- tempObj[field] = supervisor[field]
312
- }
313
-
314
- return tempObj
315
- })
316
- }
317
-
318
- private async importHandler(records) {
319
- const popup = openPopup(
320
- html`
321
- <supervisor-importer
322
- .supervisors=${records}
323
- @imported=${() => {
324
- history.back()
325
- this.grist.fetch()
326
- }}
327
- ></supervisor-importer>
328
- `,
329
- {
330
- backdrop: true,
331
- size: 'large',
332
- title: i18next.t('title.import supervisor')
333
- }
334
- )
335
-
336
- popup.onclosed = () => {
337
- this.grist.fetch()
338
- }
339
- }
340
- }
package/client/route.ts DELETED
@@ -1,27 +0,0 @@
1
- export default function route(page: string) {
2
- switch (page) {
3
- case 'checklist-template-list':
4
- import('./pages/checklist-template/checklist-template-list')
5
- return page
6
-
7
- case 'checklist-type-management':
8
- import('./pages/checklist-template/checklist-type-management')
9
- return page
10
-
11
- case 'building-inspection-list':
12
- import('./pages/building-inspection/building-inspection-list')
13
- return page
14
-
15
- case 'building-inspection-detail-drawing':
16
- import('./pages/building-inspection/building-inspection-detail-drawing')
17
- return page
18
-
19
- case 'building-inspection-detail-checklist':
20
- import('./pages/building-inspection/building-inspection-detail-checklist')
21
- return page
22
-
23
- case 'building-inspection-detail-camera':
24
- import('./pages/building-inspection/building-inspection-detail-camera')
25
- return page
26
- }
27
- }
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "../../tsconfig-base.json",
3
- "compilerOptions": {
4
- "strict": true,
5
- "declaration": true,
6
- "module": "esnext",
7
- "outDir": "../dist-client",
8
- "baseUrl": "./"
9
- },
10
- "include": ["./**/*"]
11
- }
File without changes
package/server/index.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './migrations'
2
- export * from './service'
3
-
4
- import './routes'
@@ -1,3 +0,0 @@
1
- export function initMiddlewares(app) {
2
- /* can add middlewares into app */
3
- }
@@ -1,9 +0,0 @@
1
- const glob = require('glob')
2
- const path = require('path')
3
-
4
- export var migrations = []
5
-
6
- glob.sync(path.resolve(__dirname, '.', '**', '*.js')).forEach(function(file) {
7
- if (file.indexOf('index.js') !== -1) return
8
- migrations = migrations.concat(Object.values(require(path.resolve(file))) || [])
9
- })
package/server/routes.ts DELETED
@@ -1,28 +0,0 @@
1
- // const debug = require('debug')('dssp:supervision:routes')
2
-
3
- process.on('bootstrap-module-global-public-route' as any, (app, globalPublicRouter) => {
4
- /*
5
- * can add global public routes to application (auth not required, tenancy not required)
6
- *
7
- * ex) routes.get('/path', async(context, next) => {})
8
- * ex) routes.post('/path', async(context, next) => {})
9
- */
10
- })
11
-
12
- process.on('bootstrap-module-global-private-route' as any, (app, globalPrivateRouter) => {
13
- /*
14
- * can add global private routes to application (auth required, tenancy not required)
15
- */
16
- })
17
-
18
- process.on('bootstrap-module-domain-public-route' as any, (app, domainPublicRouter) => {
19
- /*
20
- * can add domain public routes to application (auth not required, tenancy required)
21
- */
22
- })
23
-
24
- process.on('bootstrap-module-domain-private-route' as any, (app, domainPrivateRouter) => {
25
- /*
26
- * can add domain private routes to application (auth required, tenancy required)
27
- */
28
- })
@@ -1,198 +0,0 @@
1
- import { Resolver, Mutation, Arg, Ctx, Directive } from 'type-graphql'
2
- import { In } from 'typeorm'
3
-
4
- import { createAttachment, deleteAttachmentsByRef } from '@things-factory/attachment-base'
5
-
6
- import { ActionPlan } from './action-plan'
7
- import { NewActionPlan, ActionPlanPatch } from './action-plan-type'
8
-
9
- @Resolver(ActionPlan)
10
- export class ActionPlanMutation {
11
- @Directive('@transaction')
12
- @Mutation(returns => ActionPlan, { description: 'To create new ActionPlan' })
13
- async createActionPlan(@Arg('actionPlan') actionPlan: NewActionPlan, @Ctx() context: ResolverContext): Promise<ActionPlan> {
14
- const { domain, user, tx } = context.state
15
-
16
- const result = await tx.getRepository(ActionPlan).save({
17
- ...actionPlan,
18
- domain,
19
- creator: user,
20
- updater: user
21
- })
22
-
23
- if (actionPlan.thumbnail) {
24
- await createAttachment(
25
- null,
26
- {
27
- attachment: {
28
- file: actionPlan.thumbnail,
29
- refType: ActionPlan.name,
30
- refBy: result.id
31
- }
32
- },
33
- context
34
- )
35
- }
36
-
37
- return result
38
- }
39
-
40
- @Directive('@transaction')
41
- @Mutation(returns => ActionPlan, { description: 'To modify ActionPlan information' })
42
- async updateActionPlan(
43
- @Arg('id') id: string,
44
- @Arg('patch') patch: ActionPlanPatch,
45
- @Ctx() context: ResolverContext
46
- ): Promise<ActionPlan> {
47
- const { domain, user, tx } = context.state
48
-
49
- const repository = tx.getRepository(ActionPlan)
50
- const actionPlan = await repository.findOne({
51
- where: { domain: { id: domain.id }, id }
52
- })
53
-
54
- const result = await repository.save({
55
- ...actionPlan,
56
- ...patch,
57
- updater: user
58
- })
59
-
60
- if (patch.thumbnail) {
61
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
62
- await createAttachment(
63
- null,
64
- {
65
- attachment: {
66
- file: patch.thumbnail,
67
- refType: ActionPlan.name,
68
- refBy: result.id
69
- }
70
- },
71
- context
72
- )
73
- }
74
-
75
- return result
76
- }
77
-
78
- @Directive('@transaction')
79
- @Mutation(returns => [ActionPlan], { description: "To modify multiple ActionPlans' information" })
80
- async updateMultipleActionPlan(
81
- @Arg('patches', type => [ActionPlanPatch]) patches: ActionPlanPatch[],
82
- @Ctx() context: ResolverContext
83
- ): Promise<ActionPlan[]> {
84
- const { domain, user, tx } = context.state
85
-
86
- let results = []
87
- const _createRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === '+')
88
- const _updateRecords = patches.filter((patch: any) => patch.cuFlag.toUpperCase() === 'M')
89
- const actionPlanRepo = tx.getRepository(ActionPlan)
90
-
91
- if (_createRecords.length > 0) {
92
- for (let i = 0; i < _createRecords.length; i++) {
93
- const newRecord = _createRecords[i]
94
-
95
- const result = await actionPlanRepo.save({
96
- ...newRecord,
97
- domain,
98
- creator: user,
99
- updater: user
100
- })
101
-
102
- if (newRecord.thumbnail) {
103
- await createAttachment(
104
- null,
105
- {
106
- attachment: {
107
- file: newRecord.thumbnail,
108
- refType: ActionPlan.name,
109
- refBy: result.id
110
- }
111
- },
112
- context
113
- )
114
- }
115
-
116
- results.push({ ...result, cuFlag: '+' })
117
- }
118
- }
119
-
120
- if (_updateRecords.length > 0) {
121
- for (let i = 0; i < _updateRecords.length; i++) {
122
- const updateRecord = _updateRecords[i]
123
- const actionPlan = await actionPlanRepo.findOneBy({ id: updateRecord.id })
124
-
125
- const result = await actionPlanRepo.save({
126
- ...actionPlan,
127
- ...updateRecord,
128
- updater: user
129
- })
130
-
131
- if (updateRecord.thumbnail) {
132
- await deleteAttachmentsByRef(null, { refBys: [result.id] }, context)
133
- await createAttachment(
134
- null,
135
- {
136
- attachment: {
137
- file: updateRecord.thumbnail,
138
- refType: ActionPlan.name,
139
- refBy: result.id
140
- }
141
- },
142
- context
143
- )
144
- }
145
-
146
- results.push({ ...result, cuFlag: 'M' })
147
- }
148
- }
149
-
150
- return results
151
- }
152
-
153
- @Directive('@transaction')
154
- @Mutation(returns => Boolean, { description: 'To delete ActionPlan' })
155
- async deleteActionPlan(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<boolean> {
156
- const { domain, tx } = context.state
157
-
158
- await tx.getRepository(ActionPlan).delete({ domain: { id: domain.id }, id })
159
- await deleteAttachmentsByRef(null, { refBys: [id] }, context)
160
-
161
- return true
162
- }
163
-
164
- @Directive('@transaction')
165
- @Mutation(returns => Boolean, { description: 'To delete multiple ActionPlans' })
166
- async deleteActionPlans(
167
- @Arg('ids', type => [String]) ids: string[],
168
- @Ctx() context: ResolverContext
169
- ): Promise<boolean> {
170
- const { domain, tx } = context.state
171
-
172
- await tx.getRepository(ActionPlan).delete({
173
- domain: { id: domain.id },
174
- id: In(ids)
175
- })
176
-
177
- await deleteAttachmentsByRef(null, { refBys: ids }, context)
178
-
179
- return true
180
- }
181
-
182
- @Directive('@transaction')
183
- @Mutation(returns => Boolean, { description: 'To import multiple ActionPlans' })
184
- async importActionPlans(
185
- @Arg('actionPlans', type => [ActionPlanPatch]) actionPlans: ActionPlanPatch[],
186
- @Ctx() context: ResolverContext
187
- ): Promise<boolean> {
188
- const { domain, tx } = context.state
189
-
190
- await Promise.all(
191
- actionPlans.map(async (actionPlan: ActionPlanPatch) => {
192
- const createdActionPlan: ActionPlan = await tx.getRepository(ActionPlan).save({ domain, ...actionPlan })
193
- })
194
- )
195
-
196
- return true
197
- }
198
- }
@@ -1,62 +0,0 @@
1
- import { Resolver, Query, FieldResolver, Root, Args, Arg, Ctx, Directive } from 'type-graphql'
2
- import { Attachment } from '@things-factory/attachment-base'
3
- import { Domain, getQueryBuilderFromListParams, getRepository, ListParam } from '@things-factory/shell'
4
- import { User } from '@things-factory/auth-base'
5
- import { ActionPlan } from './action-plan'
6
- import { ActionPlanList } from './action-plan-type'
7
-
8
- @Resolver(ActionPlan)
9
- export class ActionPlanQuery {
10
- @Query(returns => ActionPlan!, { nullable: true, description: 'To fetch a ActionPlan' })
11
- async actionPlan(@Arg('id') id: string, @Ctx() context: ResolverContext): Promise<ActionPlan> {
12
- const { domain } = context.state
13
-
14
- return await getRepository(ActionPlan).findOne({
15
- where: { domain: { id: domain.id }, id }
16
- })
17
- }
18
-
19
- @Query(returns => ActionPlanList, { description: 'To fetch multiple ActionPlans' })
20
- async actionPlans(@Args() params: ListParam, @Ctx() context: ResolverContext): Promise<ActionPlanList> {
21
- const { domain } = context.state
22
-
23
- const queryBuilder = getQueryBuilderFromListParams({
24
- domain,
25
- params,
26
- repository: await getRepository(ActionPlan),
27
- searchables: ['name', 'description']
28
- })
29
-
30
- const [items, total] = await queryBuilder.getManyAndCount()
31
-
32
- return { items, total }
33
- }
34
-
35
- @FieldResolver(type => String)
36
- async thumbnail(@Root() actionPlan: ActionPlan): Promise<string | undefined> {
37
- const attachment: Attachment = await getRepository(Attachment).findOne({
38
- where: {
39
- domain: { id: actionPlan.domainId },
40
- refType: ActionPlan.name,
41
- refBy: actionPlan.id
42
- }
43
- })
44
-
45
- return attachment?.fullpath
46
- }
47
-
48
- @FieldResolver(type => Domain)
49
- async domain(@Root() actionPlan: ActionPlan): Promise<Domain> {
50
- return await getRepository(Domain).findOneBy({ id: actionPlan.domainId })
51
- }
52
-
53
- @FieldResolver(type => User)
54
- async updater(@Root() actionPlan: ActionPlan): Promise<User> {
55
- return await getRepository(User).findOneBy({ id: actionPlan.updaterId })
56
- }
57
-
58
- @FieldResolver(type => User)
59
- async creator(@Root() actionPlan: ActionPlan): Promise<User> {
60
- return await getRepository(User).findOneBy({ id: actionPlan.creatorId })
61
- }
62
- }