@openinc/parse-server-opendash 4.41.0 → 5.0.0

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 (194) hide show
  1. package/dist/features/config/helper/customOptions.js +1 -1
  2. package/dist/features/config/types/ConfigKeys.d.ts +0 -3
  3. package/dist/features/config/types/ConfigKeys.js +3 -23
  4. package/dist/features/openservice/index.d.ts +6 -27
  5. package/dist/features/openservice/index.js +7 -44
  6. package/dist/features/openservice/init.d.ts +5 -13
  7. package/dist/features/openservice/init.js +17 -46
  8. package/dist/features/openservice/serviceSchedules/calendarSync/Access.d.ts +9 -0
  9. package/dist/features/openservice/serviceSchedules/calendarSync/CalendarManager.d.ts +71 -0
  10. package/dist/features/openservice/serviceSchedules/calendarSync/CalendarManager.js +300 -0
  11. package/dist/features/openservice/{schedules → serviceSchedules}/calendarSync/Event.d.ts +0 -4
  12. package/dist/features/openservice/{types/Material.js → serviceSchedules/calendarSync/Event.js} +3 -0
  13. package/dist/features/openservice/serviceSchedules/calendarSync/ServiceCalendarSyncPoller.d.ts +37 -53
  14. package/dist/features/openservice/serviceSchedules/calendarSync/ServiceCalendarSyncPoller.js +284 -187
  15. package/dist/features/openservice/serviceSchedules/calendarSync/ServiceSyncTypes.d.ts +17 -15
  16. package/dist/features/openservice/serviceSchedules/calendarSync/ServiceSyncTypes.js +4 -5
  17. package/dist/features/openservice/serviceSchedules/calendarSync/eventToPlan.d.ts +1 -1
  18. package/dist/features/openservice/serviceSchedules/calendarSync/inboundChanges.d.ts +65 -0
  19. package/dist/features/openservice/serviceSchedules/calendarSync/inboundChanges.js +101 -0
  20. package/dist/features/openservice/serviceSchedules/calendarSync/index.d.ts +2 -2
  21. package/dist/features/openservice/serviceSchedules/calendarSync/index.js +3 -1
  22. package/dist/features/openservice/serviceSchedules/calendarSync/outlookRecurrence.d.ts +1 -1
  23. package/dist/features/openservice/serviceSchedules/calendarSync/planLock.d.ts +11 -0
  24. package/dist/features/openservice/serviceSchedules/calendarSync/planLock.js +48 -0
  25. package/dist/features/openservice/serviceSchedules/calendarSync/planToEvent.d.ts +1 -1
  26. package/dist/features/openservice/serviceSchedules/calendarSync/serviceCalendarMeta.d.ts +11 -32
  27. package/dist/features/openservice/serviceSchedules/calendarSync/serviceCalendarMeta.js +20 -22
  28. package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanExceptions.d.ts +4 -5
  29. package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanExceptions.js +2 -3
  30. package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanToCalendar.d.ts +10 -1
  31. package/dist/features/openservice/serviceSchedules/calendarSync/syncPlanToCalendar.js +25 -2
  32. package/dist/features/openservice/serviceSchedules/initServiceSchedulesFeature.d.ts +6 -4
  33. package/dist/features/openservice/serviceSchedules/initServiceSchedulesFeature.js +24 -11
  34. package/dist/features/openware/index.d.ts +0 -1
  35. package/dist/features/permissions/types/Permissions.d.ts +0 -14
  36. package/dist/features/permissions/types/Permissions.js +0 -18
  37. package/dist/features/translations/services/initTranslation.js +1 -1
  38. package/dist/hooks/Config_open_service.js +0 -60
  39. package/dist/hooks/Meta_Entry.js +3 -6
  40. package/dist/hooks/Service_Schedule.js +14 -7
  41. package/dist/index.js +2 -7
  42. package/dist/scripts/migration/passes/18-calendar-links.js +6 -2
  43. package/package.json +3 -4
  44. package/pnpm-workspace.yaml +7 -0
  45. package/dist/features/openservice/functions/assignUsersAndRoles.d.ts +0 -13
  46. package/dist/features/openservice/functions/assignUsersAndRoles.js +0 -212
  47. package/dist/features/openservice/functions/getSourceMetaMap.d.ts +0 -13
  48. package/dist/features/openservice/functions/getSourceMetaMap.js +0 -52
  49. package/dist/features/openservice/functions/getTicketObject.d.ts +0 -9
  50. package/dist/features/openservice/functions/getTicketObject.js +0 -31
  51. package/dist/features/openservice/functions/saveDescription.d.ts +0 -9
  52. package/dist/features/openservice/functions/saveDescription.js +0 -12
  53. package/dist/features/openservice/functions/saveDowntime.d.ts +0 -8
  54. package/dist/features/openservice/functions/saveDowntime.js +0 -32
  55. package/dist/features/openservice/functions/saveDuedate.d.ts +0 -13
  56. package/dist/features/openservice/functions/saveDuedate.js +0 -39
  57. package/dist/features/openservice/functions/saveFrequency.d.ts +0 -8
  58. package/dist/features/openservice/functions/saveFrequency.js +0 -32
  59. package/dist/features/openservice/functions/saveIssuecategory.d.ts +0 -14
  60. package/dist/features/openservice/functions/saveIssuecategory.js +0 -53
  61. package/dist/features/openservice/functions/saveMaterial.d.ts +0 -9
  62. package/dist/features/openservice/functions/saveMaterial.js +0 -18
  63. package/dist/features/openservice/functions/saveMessage.d.ts +0 -10
  64. package/dist/features/openservice/functions/saveMessage.js +0 -54
  65. package/dist/features/openservice/functions/savePriority.d.ts +0 -8
  66. package/dist/features/openservice/functions/savePriority.js +0 -32
  67. package/dist/features/openservice/functions/saveProject.d.ts +0 -8
  68. package/dist/features/openservice/functions/saveProject.js +0 -98
  69. package/dist/features/openservice/functions/saveRestriction.d.ts +0 -8
  70. package/dist/features/openservice/functions/saveRestriction.js +0 -32
  71. package/dist/features/openservice/functions/saveSource.d.ts +0 -8
  72. package/dist/features/openservice/functions/saveSource.js +0 -32
  73. package/dist/features/openservice/functions/saveState.d.ts +0 -14
  74. package/dist/features/openservice/functions/saveState.js +0 -52
  75. package/dist/features/openservice/functions/saveTicketMeta.d.ts +0 -9
  76. package/dist/features/openservice/functions/saveTicketMeta.js +0 -32
  77. package/dist/features/openservice/functions/saveTicketTitle.d.ts +0 -8
  78. package/dist/features/openservice/functions/saveTicketTitle.js +0 -28
  79. package/dist/features/openservice/issuecategory/initIssuecategory.d.ts +0 -5
  80. package/dist/features/openservice/issuecategory/initIssuecategory.js +0 -42
  81. package/dist/features/openservice/kanbanState/initKanbanStates.d.ts +0 -21
  82. package/dist/features/openservice/kanbanState/initKanbanStates.js +0 -187
  83. package/dist/features/openservice/messages/initMessages.d.ts +0 -8
  84. package/dist/features/openservice/messages/initMessages.js +0 -466
  85. package/dist/features/openservice/messages/removeLatestMessage.d.ts +0 -9
  86. package/dist/features/openservice/messages/removeLatestMessage.js +0 -30
  87. package/dist/features/openservice/schedules/calendarSync/Access.d.ts +0 -12
  88. package/dist/features/openservice/schedules/calendarSync/CalendarManager.d.ts +0 -49
  89. package/dist/features/openservice/schedules/calendarSync/CalendarManager.js +0 -211
  90. package/dist/features/openservice/schedules/calendarSync/CalendarSyncPoller.d.ts +0 -25
  91. package/dist/features/openservice/schedules/calendarSync/CalendarSyncPoller.js +0 -202
  92. package/dist/features/openservice/schedules/calendarSync/ConfigValues.d.ts +0 -13
  93. package/dist/features/openservice/schedules/calendarSync/ConfigValues.js +0 -2
  94. package/dist/features/openservice/schedules/calendarSync/Event.js +0 -9
  95. package/dist/features/openservice/schedules/calendarSync/calendarMetaHelper.d.ts +0 -76
  96. package/dist/features/openservice/schedules/calendarSync/calendarMetaHelper.js +0 -119
  97. package/dist/features/openservice/schedules/calendarSync/eventToSchedule.d.ts +0 -37
  98. package/dist/features/openservice/schedules/calendarSync/eventToSchedule.js +0 -103
  99. package/dist/features/openservice/schedules/calendarSync/scheduleToEvent.d.ts +0 -9
  100. package/dist/features/openservice/schedules/calendarSync/scheduleToEvent.js +0 -122
  101. package/dist/features/openservice/schedules/checkStatus.d.ts +0 -9
  102. package/dist/features/openservice/schedules/checkStatus.js +0 -31
  103. package/dist/features/openservice/schedules/getScheduleLink.d.ts +0 -10
  104. package/dist/features/openservice/schedules/getScheduleLink.js +0 -32
  105. package/dist/features/openservice/schedules/initSchedulesFeature.d.ts +0 -5
  106. package/dist/features/openservice/schedules/initSchedulesFeature.js +0 -32
  107. package/dist/features/openservice/schedules/reassignScheduleExecutions.d.ts +0 -5
  108. package/dist/features/openservice/schedules/reassignScheduleExecutions.js +0 -39
  109. package/dist/features/openservice/ticket/getTicketLink.d.ts +0 -9
  110. package/dist/features/openservice/ticket/getTicketLink.js +0 -32
  111. package/dist/features/openservice/ticket/initTicket.d.ts +0 -4
  112. package/dist/features/openservice/ticket/initTicket.js +0 -56
  113. package/dist/features/openservice/types/FetchOptions.d.ts +0 -4
  114. package/dist/features/openservice/types/FetchOptions.js +0 -2
  115. package/dist/features/openservice/types/Material.d.ts +0 -10
  116. package/dist/features/openservice/types/OpenserviceTranslationKeys.d.ts +0 -102
  117. package/dist/features/openservice/types/OpenserviceTranslationKeys.js +0 -106
  118. package/dist/features/openservice/types/SaveValues.d.ts +0 -33
  119. package/dist/features/openservice/types/SaveValues.js +0 -2
  120. package/dist/features/openservice/types/TicketData.d.ts +0 -22
  121. package/dist/features/openservice/types/TicketData.js +0 -2
  122. package/dist/features/openware/types/OpenWareTicketObject.d.ts +0 -14
  123. package/dist/features/openware/types/OpenWareTicketObject.js +0 -2
  124. package/dist/functions/openinc-openservice-get-sourcemeta-map.d.ts +0 -1
  125. package/dist/functions/openinc-openservice-get-sourcemeta-map.js +0 -41
  126. package/dist/functions/openinc-openservice-save-ticket-data.d.ts +0 -6
  127. package/dist/functions/openinc-openservice-save-ticket-data.js +0 -517
  128. package/dist/functions/openinc-openservice-ticket-data.d.ts +0 -44
  129. package/dist/functions/openinc-openservice-ticket-data.js +0 -380
  130. package/dist/helper/removeShorltyPreviousEntry.d.ts +0 -2
  131. package/dist/helper/removeShorltyPreviousEntry.js +0 -31
  132. package/dist/hooks/Maintenance_Downtime.d.ts +0 -1
  133. package/dist/hooks/Maintenance_Downtime.js +0 -106
  134. package/dist/hooks/Maintenance_Duedate.d.ts +0 -1
  135. package/dist/hooks/Maintenance_Duedate.js +0 -128
  136. package/dist/hooks/Maintenance_Frequency.d.ts +0 -1
  137. package/dist/hooks/Maintenance_Frequency.js +0 -106
  138. package/dist/hooks/Maintenance_Issuecategory.d.ts +0 -1
  139. package/dist/hooks/Maintenance_Issuecategory.js +0 -19
  140. package/dist/hooks/Maintenance_Item.d.ts +0 -1
  141. package/dist/hooks/Maintenance_Item.js +0 -17
  142. package/dist/hooks/Maintenance_Kanban_State.d.ts +0 -1
  143. package/dist/hooks/Maintenance_Kanban_State.js +0 -17
  144. package/dist/hooks/Maintenance_Media.d.ts +0 -1
  145. package/dist/hooks/Maintenance_Media.js +0 -17
  146. package/dist/hooks/Maintenance_Message.d.ts +0 -1
  147. package/dist/hooks/Maintenance_Message.js +0 -20
  148. package/dist/hooks/Maintenance_Order.d.ts +0 -1
  149. package/dist/hooks/Maintenance_Order.js +0 -17
  150. package/dist/hooks/Maintenance_Priority.d.ts +0 -1
  151. package/dist/hooks/Maintenance_Priority.js +0 -110
  152. package/dist/hooks/Maintenance_Project.d.ts +0 -1
  153. package/dist/hooks/Maintenance_Project.js +0 -30
  154. package/dist/hooks/Maintenance_Restriction.d.ts +0 -1
  155. package/dist/hooks/Maintenance_Restriction.js +0 -113
  156. package/dist/hooks/Maintenance_Schedule.d.ts +0 -1
  157. package/dist/hooks/Maintenance_Schedule.js +0 -146
  158. package/dist/hooks/Maintenance_Schedule_Execution.d.ts +0 -1
  159. package/dist/hooks/Maintenance_Schedule_Execution.js +0 -118
  160. package/dist/hooks/Maintenance_Schedule_Execution_Step.d.ts +0 -1
  161. package/dist/hooks/Maintenance_Schedule_Execution_Step.js +0 -17
  162. package/dist/hooks/Maintenance_Schedule_Step.d.ts +0 -1
  163. package/dist/hooks/Maintenance_Schedule_Step.js +0 -26
  164. package/dist/hooks/Maintenance_Schedule_Template.d.ts +0 -1
  165. package/dist/hooks/Maintenance_Schedule_Template.js +0 -92
  166. package/dist/hooks/Maintenance_Source_File.d.ts +0 -1
  167. package/dist/hooks/Maintenance_Source_File.js +0 -17
  168. package/dist/hooks/Maintenance_Ticket.d.ts +0 -1
  169. package/dist/hooks/Maintenance_Ticket.js +0 -15
  170. package/dist/hooks/Maintenance_Ticket_Assignment.d.ts +0 -1
  171. package/dist/hooks/Maintenance_Ticket_Assignment.js +0 -17
  172. package/dist/hooks/Maintenance_Ticket_FormConfig.d.ts +0 -1
  173. package/dist/hooks/Maintenance_Ticket_FormConfig.js +0 -17
  174. package/dist/hooks/Maintenance_Ticket_Issuecategory.d.ts +0 -1
  175. package/dist/hooks/Maintenance_Ticket_Issuecategory.js +0 -109
  176. package/dist/hooks/Maintenance_Ticket_Kanban_State.d.ts +0 -1
  177. package/dist/hooks/Maintenance_Ticket_Kanban_State.js +0 -134
  178. package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.d.ts +0 -1
  179. package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.js +0 -15
  180. package/dist/hooks/Maintenance_Ticket_Material.d.ts +0 -4
  181. package/dist/hooks/Maintenance_Ticket_Material.js +0 -104
  182. package/dist/hooks/Maintenance_Ticket_Project.d.ts +0 -1
  183. package/dist/hooks/Maintenance_Ticket_Project.js +0 -88
  184. package/dist/hooks/Maintenance_Ticket_QR_Code.d.ts +0 -1
  185. package/dist/hooks/Maintenance_Ticket_QR_Code.js +0 -17
  186. package/dist/hooks/Maintenance_Ticket_Source.d.ts +0 -1
  187. package/dist/hooks/Maintenance_Ticket_Source.js +0 -124
  188. package/dist/hooks/Maintenance_Ticket_Title.d.ts +0 -1
  189. package/dist/hooks/Maintenance_Ticket_Title.js +0 -107
  190. package/dist/i18n/de-DE/maintenance.json +0 -16
  191. package/dist/i18n/en-US/maintenance.json +0 -16
  192. package/dist/scripts/seed-v1-testdata.d.ts +0 -43
  193. package/dist/scripts/seed-v1-testdata.js +0 -982
  194. /package/dist/features/openservice/{schedules → serviceSchedules}/calendarSync/Access.js +0 -0
@@ -1,982 +0,0 @@
1
- "use strict";
2
- /**
3
- * Seed **v1** (`OD3_Maintenance_*`) test data, for exercising the v1 → v2 migration.
4
- *
5
- * DEV ONLY. Never run this against production.
6
- *
7
- * OD_MIGRATION_MODE=1 PARSE_APP_ID=… PARSE_MAINTENANCE_KEY=… \
8
- * node dist/scripts/seed-v1-testdata.js [--purge]
9
- *
10
- * ## Why the maintenance key
11
- *
12
- * Realistic timestamps are the whole point. The migration's fold picks the newest
13
- * side-table row and its replay builds a timeline from them — neither can be tested
14
- * against data where every row was created in the same second. Historical
15
- * `createdAt` / `updatedAt` require the maintenance key, so this seeder needs the
16
- * same setup as the migration. That makes it a useful smoke test of the write path
17
- * in its own right: if this runs, the migration's transport works.
18
- *
19
- * ## Why OD_MIGRATION_MODE
20
- *
21
- * All 29 v1 hooks call `defaultHandler`, which throws on a request with no user —
22
- * and maintenance-key requests have none. The flag gates that off, so this seeder
23
- * sets `tenant`, `user` and ACLs itself, exactly as the migration does.
24
- *
25
- * ## What it deliberately includes
26
- *
27
- * Every case the migration audits turned up, so a dry run has something to say:
28
- *
29
- * - two tenants, each with their own kanban states and meta fields
30
- * - a ticket with no kanban state at all (inbox fallback)
31
- * - a ticket with `enabled: false`, and one with `enabled` *unset*
32
- * - side-table rows where `updatedAt` disagrees with `createdAt` ordering
33
- * - a completed todo, and a todo whose title is an i18n key
34
- * - a comment with an i18n-key title, and one with no author but an attachment
35
- * - a source with no tag, and a source tree needing ancestors
36
- * - an item with a German-decimal price and one with an unparseable price
37
- * - a two-level issue-category tree (closure expansion)
38
- * - an assignment batch (three rows, one `batchStamp`)
39
- * - a message referencing a non-ticket object (orphan skip)
40
- * - assets on a real and on a `temp-` media context
41
- * - maintenance plans, templates and executions in every v1 shape — see
42
- * `seedSchedules`
43
- */
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- const node_1 = __importDefault(require("parse/node"));
49
- const acl_js_1 = require("./migration/lib/acl.js");
50
- const env_js_1 = require("./migration/lib/env.js");
51
- const rest_js_1 = require("./migration/lib/rest.js");
52
- // ── helpers ────────────────────────────────────────────────────────────────
53
- const ptr = (className, objectId) => ({
54
- __type: "Pointer",
55
- className,
56
- objectId,
57
- });
58
- const dateVal = (d) => ({ __type: "Date", iso: d.toISOString() });
59
- /** Days before now, at a fixed time of day so runs are comparable. */
60
- function daysAgo(days, hour = 9) {
61
- const d = new Date();
62
- d.setDate(d.getDate() - days);
63
- d.setHours(hour, 0, 0, 0);
64
- return d;
65
- }
66
- /** Marker so `--purge` can find exactly what this seeder created. */
67
- const SEED_MARKER = "seed:v1-testdata";
68
- async function create(ctx, className, payload, createdAt, updatedAt,
69
- /**
70
- * The ACL to write instead of the default one — `null` for none at all,
71
- * which is what v1 left on every plan written with the master key.
72
- */
73
- acl) {
74
- const tenantId = payload.tenant?.objectId;
75
- const userId = payload.user?.objectId;
76
- const body = {
77
- ...payload,
78
- ...(acl === null
79
- ? {}
80
- : {
81
- ACL: acl ??
82
- (0, acl_js_1.migrationAcl)({
83
- tenantId,
84
- userId,
85
- allowTenantUserWrite: true,
86
- }).toJSON(),
87
- }),
88
- };
89
- const result = await (0, rest_js_1.restCreateRaw)(ctx.config, className, body, createdAt, updatedAt);
90
- ctx.created.set(className, (ctx.created.get(className) ?? 0) + 1);
91
- return result.objectId;
92
- }
93
- /** Remove a field entirely, which a schema `defaultValue` otherwise prevents. */
94
- async function unsetField(config, className, objectId, field) {
95
- const response = await fetch(`${config.parseUrl}/classes/${className}/${objectId}`, {
96
- method: "PUT",
97
- headers: {
98
- "X-Parse-Application-Id": config.appId,
99
- "X-Parse-Maintenance-Key": config.maintenanceKey,
100
- "X-Parse-Cloud-Context": JSON.stringify({ skipChangelog: true }),
101
- "Content-Type": "application/json",
102
- },
103
- body: JSON.stringify({ [field]: { __op: "Delete" } }),
104
- });
105
- if (!response.ok) {
106
- throw new Error(`unset ${className}.${field} → ${response.status}: ${(await response.text()).slice(0, 200)}`);
107
- }
108
- }
109
- /** Update fields of an existing object — after whatever its hooks made of it. */
110
- async function update(config, className, objectId, body) {
111
- const response = await fetch(`${config.parseUrl}/classes/${className}/${objectId}`, {
112
- method: "PUT",
113
- headers: {
114
- "X-Parse-Application-Id": config.appId,
115
- "X-Parse-Maintenance-Key": config.maintenanceKey,
116
- "X-Parse-Cloud-Context": JSON.stringify({ skipChangelog: true }),
117
- "Content-Type": "application/json",
118
- },
119
- body: JSON.stringify(body),
120
- });
121
- if (!response.ok) {
122
- throw new Error(`update ${className} ${objectId} → ${response.status}: ${(await response.text()).slice(0, 200)}`);
123
- }
124
- }
125
- // ── the data ───────────────────────────────────────────────────────────────
126
- async function seed(ctx) {
127
- const { tenantId, tenant2Id, userId, roleId } = ctx;
128
- const tenant = ptr("OD3_Tenant", tenantId);
129
- const tenant2 = ptr("OD3_Tenant", tenant2Id);
130
- const user = ptr("_User", userId);
131
- // ── source meta: created first, because Source.meta points at it ───────────
132
- // Covers every branch of the SourceMeta -> equipment-meta step in pass 03:
133
- // scalar/array values, a cross-source type conflict, a data key colliding with
134
- // a SourceMeta column, and meta on a source D3 will not migrate.
135
- const hallMetaId = await create(ctx, "OD3_SourceMeta", {
136
- name: "Halle B Stammdaten",
137
- // `baujahr` is a String here and a Number on CNC-04 below: the pass must
138
- // report the type conflict and keep the first definition.
139
- data: { hersteller: "Diverse", baujahr: "unbekannt" },
140
- tenant,
141
- }, daysAgo(401));
142
- const cncMetaId = await create(ctx, "OD3_SourceMeta", {
143
- name: "CNC-04 Stammdaten",
144
- description: "Kopfdaten der Fräse",
145
- location: { __type: "GeoPoint", latitude: 52.0211, longitude: 8.5347 },
146
- data: {
147
- hersteller: "Siemens",
148
- baujahr: 2018,
149
- wartungspflichtig: true,
150
- zertifikate: ["CE", "ISO9001"],
151
- },
152
- tenant,
153
- }, daysAgo(396));
154
- // `data.name` collides with the SourceMeta `name` column: data wins, the
155
- // column moves to `sourceMetaName`.
156
- const untaggedMetaId = await create(ctx, "OD3_SourceMeta", {
157
- name: "Presse Stammdaten",
158
- data: { name: "Presse A intern", hersteller: "Schuler" },
159
- tenant,
160
- }, daysAgo(391));
161
- // Hangs off a source nothing references: must be counted, not migrated.
162
- const orphanMetaId = await create(ctx, "OD3_SourceMeta", { name: "Sensor Stammdaten", data: { irrelevant: "wird nicht migriert" }, tenant }, daysAgo(381));
163
- // ── sources: a two-level tree, plus one with no tag, plus one nothing uses ──
164
- const hallId = await create(ctx, "OD3_Source", {
165
- name: "Halle B",
166
- tag: "halle-b",
167
- meta: ptr("OD3_SourceMeta", hallMetaId),
168
- tenant,
169
- }, daysAgo(400));
170
- const cncId = await create(ctx, "OD3_Source", {
171
- name: "CNC-04",
172
- tag: "cnc-04",
173
- parent: ptr("OD3_Source", hallId),
174
- meta: ptr("OD3_SourceMeta", cncMetaId),
175
- tenant,
176
- }, daysAgo(395));
177
- // No tag: pass 03 must warn that this equipment cannot match a source.
178
- const untaggedId = await create(ctx, "OD3_Source", {
179
- name: "Presse A (ohne Tag)",
180
- parent: ptr("OD3_Source", hallId),
181
- meta: ptr("OD3_SourceMeta", untaggedMetaId),
182
- tenant,
183
- }, daysAgo(390));
184
- // Referenced by nothing: pass 03 must skip it (D3).
185
- await create(ctx, "OD3_Source", {
186
- name: "Sensor XYZ (unreferenziert)",
187
- tag: "sensor-xyz",
188
- meta: ptr("OD3_SourceMeta", orphanMetaId),
189
- tenant,
190
- }, daysAgo(380));
191
- // ── kanban states: tenant 1 reuses the auto-seeded ones, plus a working state.
192
- const inProgressId = await create(ctx, "OD3_Maintenance_Kanban_State", { label: "In Arbeit", order: 50, color: "#cce5ff", enabled: true, tenant }, daysAgo(370));
193
- const finishedId = await create(ctx, "OD3_Maintenance_Kanban_State", {
194
- label: "Erledigt",
195
- order: 90,
196
- color: "#d4edda",
197
- isFinished: true,
198
- enabled: true,
199
- description: "Wird beim Abschluss gesetzt",
200
- tenant,
201
- }, daysAgo(370));
202
- const inboxId = await create(ctx, "OD3_Maintenance_Kanban_State", { label: "Eingang", order: 10, isInbox: true, enabled: true, tenant }, daysAgo(370));
203
- // A disabled state -> deleted: true in v2.
204
- await create(ctx, "OD3_Maintenance_Kanban_State", { label: "Alt / stillgelegt", order: 99, enabled: false, tenant }, daysAgo(360));
205
- // Tenant 2 gets its own, so the multi-tenant path is exercised.
206
- await create(ctx, "OD3_Maintenance_Kanban_State", { label: "Offen (T2)", order: 10, isInbox: true, enabled: true, tenant: tenant2 }, daysAgo(360));
207
- // ── issue categories: two levels, so the closure has something to expand ──
208
- const mechId = await create(ctx, "OD3_Maintenance_Issuecategory", { name: "Mechanik", enabled: true, issuecode: "100", icon: "fa:gear", tenant }, daysAgo(350));
209
- const bearingId = await create(ctx, "OD3_Maintenance_Issuecategory", {
210
- name: "Lagerschaden",
211
- parent: ptr("OD3_Maintenance_Issuecategory", mechId),
212
- enabled: true,
213
- issuecode: "110",
214
- tenant,
215
- }, daysAgo(349));
216
- // ── projects: a parent/child pair, one finished ───────────────────────────
217
- const projectId = await create(ctx, "OD3_Maintenance_Project", {
218
- name: "Instandhaltung 2025",
219
- description: "Laufende Instandhaltung",
220
- color: "#4f7f2c",
221
- start: dateVal(daysAgo(330)),
222
- user,
223
- tenant,
224
- }, daysAgo(330));
225
- await create(ctx, "OD3_Maintenance_Project", {
226
- name: "Umbau Halle B (abgeschlossen)",
227
- parent: ptr("OD3_Maintenance_Project", projectId),
228
- finished: true,
229
- user,
230
- tenant,
231
- }, daysAgo(320));
232
- // ── items: German decimal, unparseable, and a source link ────────────────
233
- const itemDichtung = await create(ctx, "OD3_Maintenance_Item", {
234
- name: "Dichtung 12mm",
235
- price: "12,50 €",
236
- stock: 42,
237
- stockUnit: "Stk",
238
- internalNumber: "D-12",
239
- storageLocation: "Regal 3",
240
- supplier: "Muster GmbH",
241
- tenant,
242
- // v1 linked an item to the sources it belongs to via a Relation. Pass 05
243
- // resolves those through the pass-03 map and stores the migrated Equipment
244
- // ids on the article meta entry. Seeded so that path is covered — the
245
- // comment above promised a source link that was never actually created.
246
- sources: {
247
- __op: "AddRelation",
248
- objects: [
249
- { __type: "Pointer", className: "OD3_Source", objectId: cncId },
250
- ],
251
- },
252
- }, daysAgo(300));
253
- const itemOel = await create(ctx, "OD3_Maintenance_Item", { name: "Spezialöl", price: "auf Anfrage", stock: 3, tenant }, daysAgo(299));
254
- // ── ticket 1: the rich one. History across several side tables. ───────────
255
- const t1 = await create(ctx, "OD3_Maintenance_Ticket", {
256
- title: "Lager läuft heiß",
257
- description: "Temperatur an Spindel steigt seit Tagen.",
258
- enabled: true,
259
- latestPriorityValue: 80,
260
- project: ptr("OD3_Maintenance_Project", projectId),
261
- // `kostenstelle` and `schicht` are defined by the form config below;
262
- // `altfeld` is NOT — it only exists here, which is exactly the case pass 07
263
- // unions in from tickets so pass 09 does not write an undefined-able value.
264
- meta: {
265
- fields: [
266
- { name: "kostenstelle", label: "Kostenstelle", type: "string", value: "4711" },
267
- { name: "schicht", label: "Schicht", type: "select", options: ["Früh", "Spät", "Nacht"], value: "Spät" },
268
- { name: "altfeld", label: "Altes Feld", type: "string", value: "nur am Ticket" },
269
- ],
270
- },
271
- user,
272
- tenant,
273
- }, daysAgo(60, 8));
274
- // Priority raised over time -> a real timeline.
275
- await create(ctx, "OD3_Maintenance_Priority", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 20, user, tenant }, daysAgo(60, 9));
276
- await create(ctx, "OD3_Maintenance_Priority", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 60, user, tenant }, daysAgo(40, 9));
277
- await create(ctx, "OD3_Maintenance_Priority", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 80, user, tenant }, daysAgo(10, 9));
278
- // THE `effectiveAt` CASE: created earlier but edited later, so `updatedAt`
279
- // ordering differs from `createdAt` ordering. The fold and the replay must agree
280
- // on which of these two wins.
281
- await create(ctx, "OD3_Maintenance_Downtime", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 30, user, tenant }, daysAgo(50, 9), daysAgo(5, 9));
282
- await create(ctx, "OD3_Maintenance_Downtime", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 15, user, tenant }, daysAgo(20, 9), daysAgo(20, 9));
283
- await create(ctx, "OD3_Maintenance_Frequency", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 40, user, tenant }, daysAgo(45, 9));
284
- await create(ctx, "OD3_Maintenance_Restriction", { ticket: ptr("OD3_Maintenance_Ticket", t1), value: 60, user, tenant }, daysAgo(45, 10));
285
- await create(ctx, "OD3_Maintenance_Duedate", {
286
- ticket: ptr("OD3_Maintenance_Ticket", t1),
287
- start: dateVal(daysAgo(30)),
288
- end: dateVal(daysAgo(-14)),
289
- startformat: "date",
290
- endformat: "date",
291
- user,
292
- tenant,
293
- }, daysAgo(30, 11));
294
- // Title changed after creation -> the fold must prefer the override.
295
- await create(ctx, "OD3_Maintenance_Ticket_Title", { ticket: ptr("OD3_Maintenance_Ticket", t1), title: "Lager läuft heiß (Spindel 2)", user, tenant }, daysAgo(35, 9));
296
- await create(ctx, "OD3_Maintenance_Ticket_Source", { ticket: ptr("OD3_Maintenance_Ticket", t1), source: ptr("OD3_Source", cncId), user, tenant }, daysAgo(60, 9));
297
- await create(ctx, "OD3_Maintenance_Ticket_Project", { ticket: ptr("OD3_Maintenance_Ticket", t1), project: ptr("OD3_Maintenance_Project", projectId), user, tenant }, daysAgo(60, 9));
298
- await create(ctx, "OD3_Maintenance_Ticket_Issuecategory", { ticket: ptr("OD3_Maintenance_Ticket", t1), issuecategory: ptr("OD3_Maintenance_Issuecategory", bearingId), user, tenant }, daysAgo(59, 9));
299
- // Status history: inbox -> in progress. No finished row, so `closedAt` stays null.
300
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State", { ticket: ptr("OD3_Maintenance_Ticket", t1), state: ptr("OD3_Maintenance_Kanban_State", inboxId), user, tenant }, daysAgo(60, 9));
301
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State", { ticket: ptr("OD3_Maintenance_Ticket", t1), state: ptr("OD3_Maintenance_Kanban_State", inProgressId), user, tenant }, daysAgo(38, 9));
302
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State_Current", { ticket: ptr("OD3_Maintenance_Ticket", t1), state: ptr("OD3_Maintenance_Kanban_State", inProgressId), tenant }, daysAgo(38, 9));
303
- // An assignment batch: several rows sharing one `batchStamp`, which the replay
304
- // must collapse into a SINGLE timeline event rather than one per assignee.
305
- const batchStamp = dateVal(daysAgo(37, 14));
306
- await create(ctx, "OD3_Maintenance_Ticket_Assignment", { ticket: ptr("OD3_Maintenance_Ticket", t1), assignedUser: user, batchStamp, user, tenant }, daysAgo(37, 14));
307
- if (ctx.roleId) {
308
- await create(ctx, "OD3_Maintenance_Ticket_Assignment", {
309
- ticket: ptr("OD3_Maintenance_Ticket", t1),
310
- assignedRole: ptr("_Role", ctx.roleId),
311
- batchStamp,
312
- user,
313
- tenant,
314
- }, daysAgo(37, 14));
315
- }
316
- // A second, later batch -> a second event, so the timeline shows a reassignment.
317
- await create(ctx, "OD3_Maintenance_Ticket_Assignment", {
318
- ticket: ptr("OD3_Maintenance_Ticket", t1),
319
- assignedUser: user,
320
- batchStamp: dateVal(daysAgo(8, 11)),
321
- user,
322
- tenant,
323
- }, daysAgo(8, 11));
324
- // Material: an append-only side table where each row carries the WHOLE list,
325
- // so two rows means one edit. Covers all three cases the migration handles:
326
- // a catalogue item (maps to an Article), an ad-hoc line v1 allowed with a
327
- // synthetic id, and a quantity changed later so the fold must pick row 2.
328
- await create(ctx, "OD3_Maintenance_Ticket_Material", {
329
- ticket: ptr("OD3_Maintenance_Ticket", t1),
330
- itemList: [
331
- { id: itemDichtung, name: "Dichtung 12mm", quantity: 3, unit: "Stk" },
332
- ],
333
- user,
334
- tenant,
335
- }, daysAgo(12, 9));
336
- await create(ctx, "OD3_Maintenance_Ticket_Material", {
337
- ticket: ptr("OD3_Maintenance_Ticket", t1),
338
- itemList: [
339
- { id: itemDichtung, name: "Dichtung 12mm", quantity: 5, unit: "Stk" },
340
- { id: itemOel, name: "Spezialöl", quantity: 1, unit: "L" },
341
- { id: "manual-1", name: "Kabelbinder (Restbestand)", quantity: 10, unit: "Stk" },
342
- ],
343
- user,
344
- tenant,
345
- }, daysAgo(9, 14));
346
- // ── comments + todos on ticket 1 ─────────────────────────────────────────
347
- await create(ctx, "OD3_Maintenance_Message", {
348
- classname: "OD3_Maintenance_Ticket",
349
- referencedObjectId: t1,
350
- title: "Erste Sichtung",
351
- content: "Lager sichtbar verfärbt, Austausch nötig.",
352
- data: { type: "userinput" },
353
- displayAt: dateVal(daysAgo(58)),
354
- user,
355
- tenant,
356
- }, daysAgo(58, 10));
357
- // Title is an i18n KEY (user left the subject blank) -> must not be rendered.
358
- await create(ctx, "OD3_Maintenance_Message", {
359
- classname: "OD3_Maintenance_Ticket",
360
- referencedObjectId: t1,
361
- title: "maintenance:article.create.default_subject.userinput",
362
- content: "Ersatzteil bestellt, Lieferung nächste Woche.",
363
- data: { type: "userinput" },
364
- user,
365
- tenant,
366
- }, daysAgo(30, 10));
367
- // A completed todo, and one still open with an i18n-key title.
368
- await create(ctx, "OD3_Maintenance_Message", {
369
- classname: "OD3_Maintenance_Ticket",
370
- referencedObjectId: t1,
371
- title: "Lager ausmessen",
372
- content: "Innendurchmesser prüfen",
373
- data: { type: "todo", todoCompleted: true },
374
- user,
375
- tenant,
376
- }, daysAgo(50, 10));
377
- await create(ctx, "OD3_Maintenance_Message", {
378
- classname: "OD3_Maintenance_Ticket",
379
- referencedObjectId: t1,
380
- title: "maintenance:article.create.default_subject.todo",
381
- content: "Schmierplan anpassen",
382
- data: { type: "todo", todoCompleted: false },
383
- user,
384
- tenant,
385
- }, daysAgo(20, 10));
386
- // ── ticket 2: no kanban state at all -> inbox fallback ───────────────────
387
- const t2 = await create(ctx, "OD3_Maintenance_Ticket", { title: "Kühlmittel nachfüllen", enabled: true, user, tenant }, daysAgo(25, 8));
388
- await create(ctx, "OD3_Maintenance_Ticket_Source", { ticket: ptr("OD3_Maintenance_Ticket", t2), source: ptr("OD3_Source", untaggedId), user, tenant }, daysAgo(25, 9));
389
- // ── ticket 2b: closed, so `closedAt` can be derived ─────────────────────
390
- // v1 has no closedAt column; pass 08 infers it from the newest state-history row
391
- // whose state is `isFinished`. Without a ticket like this that logic is untested.
392
- const tClosed = await create(ctx, "OD3_Maintenance_Ticket", {
393
- title: "Riemen getauscht",
394
- description: "Antriebsriemen war gerissen.",
395
- enabled: true,
396
- latestPriorityValue: 40,
397
- user,
398
- tenant,
399
- }, daysAgo(120, 8));
400
- await create(ctx, "OD3_Maintenance_Ticket_Source", { ticket: ptr("OD3_Maintenance_Ticket", tClosed), source: ptr("OD3_Source", cncId), user, tenant }, daysAgo(120, 9));
401
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State", { ticket: ptr("OD3_Maintenance_Ticket", tClosed), state: ptr("OD3_Maintenance_Kanban_State", inboxId), user, tenant }, daysAgo(120, 9));
402
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State", { ticket: ptr("OD3_Maintenance_Ticket", tClosed), state: ptr("OD3_Maintenance_Kanban_State", inProgressId), user, tenant }, daysAgo(118, 9));
403
- // The finished row: its updatedAt is what `closedAt` must end up as.
404
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State", { ticket: ptr("OD3_Maintenance_Ticket", tClosed), state: ptr("OD3_Maintenance_Kanban_State", finishedId), user, tenant }, daysAgo(115, 16));
405
- await create(ctx, "OD3_Maintenance_Ticket_Kanban_State_Current", { ticket: ptr("OD3_Maintenance_Ticket", tClosed), state: ptr("OD3_Maintenance_Kanban_State", finishedId), tenant }, daysAgo(115, 16));
406
- // ── ticket 3: disabled -> deleted: true ──────────────────────────────────
407
- await create(ctx, "OD3_Maintenance_Ticket", { title: "Storniert: Fehlalarm", enabled: false, user, tenant }, daysAgo(80, 8));
408
- // ── ticket 4: `enabled` UNSET -> must also become deleted: true ───────────
409
- const t4 = await create(ctx, "OD3_Maintenance_Ticket", { title: "Altlast ohne enabled-Flag", enabled: true, user, tenant }, daysAgo(500, 8));
410
- await unsetField(ctx.config, "OD3_Maintenance_Ticket", t4, "enabled");
411
- // ── ticket 5: tenant 2, so the multi-tenant path has data ────────────────
412
- await create(ctx, "OD3_Maintenance_Ticket", {
413
- title: "T2: Förderband prüfen",
414
- enabled: true,
415
- meta: {
416
- fields: [
417
- { name: "kostenstelle", label: "Kostenstelle", type: "string", value: "T2-4711" },
418
- ],
419
- },
420
- user,
421
- tenant: tenant2,
422
- }, daysAgo(15, 8));
423
- // ── a message pointing at something that is not a ticket -> orphan skip ──
424
- await create(ctx, "OD3_Maintenance_Message", {
425
- classname: "OD3_Source",
426
- referencedObjectId: cncId,
427
- title: "Maschinennotiz",
428
- content: "Gehört zu einer Source, nicht zu einem Ticket.",
429
- data: { type: "userinput" },
430
- user,
431
- tenant,
432
- }, daysAgo(45, 10));
433
- // ── form config, incl. meta field definitions and priority labels ─────────
434
- await create(ctx, "OD3_Maintenance_Ticket_FormConfig", {
435
- view: "formular",
436
- label: "Standardformular",
437
- config: {
438
- config: [
439
- { name: "title", required: true, label: "Kurzbeschreibung" },
440
- { name: "description", label: "-" },
441
- {
442
- name: "priority",
443
- required: true,
444
- customLabels: [
445
- { label: "verylow", value: "Sehr niedrig" },
446
- { label: "low", value: "Niedrig" },
447
- { label: "mid", value: "Mittel" },
448
- { label: "high", value: "Hoch" },
449
- { label: "ultra", value: "Kritisch" },
450
- ],
451
- },
452
- { name: "media", label: "Fotos" },
453
- { name: "material", label: "Material" },
454
- { name: "source", required: true },
455
- { name: "issuecategory", help: "Bitte möglichst genau wählen" },
456
- {
457
- name: "meta",
458
- fields: [
459
- { name: "kostenstelle", label: "Kostenstelle", type: "string" },
460
- { name: "stillstand", label: "Stillstand?", type: "boolean" },
461
- {
462
- name: "schicht",
463
- label: "Schicht",
464
- type: "select",
465
- options: ["Früh", "Spät", "Nacht"],
466
- },
467
- ],
468
- },
469
- ],
470
- },
471
- tenant,
472
- // v1 stored this as a Parse Relation. Pass 06 reads it with relationIds()
473
- // and writes a plain id array, which is what the v2 FormConfig.roles
474
- // column is — seeded so that conversion is actually covered.
475
- ...(roleId
476
- ? {
477
- roles: {
478
- __op: "AddRelation",
479
- objects: [{ __type: "Pointer", className: "_Role", objectId: roleId }],
480
- },
481
- }
482
- : {}),
483
- }, daysAgo(340));
484
- await seedSchedules(ctx, { hallId, cncId, untaggedId, itemOel });
485
- // ── assets: one real ticket-media context, one abandoned temp context ────
486
- await create(ctx, "OD3_Assets", {
487
- context: `ticket-media-${t1}`,
488
- description: "Foto Lager",
489
- file: { __type: "File", name: "lager.txt", url: "https://example.invalid/lager.txt" },
490
- user,
491
- tenant,
492
- }, daysAgo(57, 10));
493
- await create(ctx, "OD3_Assets", {
494
- context: "ticket-media-temp-abandoned-uuid",
495
- description: "Verwaister Upload",
496
- file: { __type: "File", name: "temp.txt", url: "https://example.invalid/temp.txt" },
497
- user,
498
- tenant,
499
- }, daysAgo(56, 10));
500
- }
501
- // ── schedules ──────────────────────────────────────────────────────────────
502
- /**
503
- * v1 maintenance plans, templates and executions for passes 13–19.
504
- *
505
- * v1 wrote these rows in several shapes over two years, and the passes have a
506
- * branch for each — so each shape appears once:
507
- *
508
- * - a plan that inherits interval and steps from its template, overriding
509
- * only the interval number; the template starts on 31 January (month end)
510
- * - a template in the pre-2025-07 interval shape (`run_cron`), disabled
511
- * - a yearly plan starting 29 February, with no ACL at all (as the v1 Outlook
512
- * import left them), disabled, a sub-day reminder and an Outlook link
513
- * - a plan with interval number 0 (a single appointment) and an `endDate`
514
- * stored as a bare ISO string (what v1's "shift" left behind)
515
- * - steps in all three eras: static admin fields (A), field configs (B), a
516
- * `Meta_Config` (C); one step shared by a template and two plans
517
- * - executions: a protocol with material, a comment and era-C values; a
518
- * `terminated` run; a run v1 rewrote to `completed` although a step is
519
- * open; an open run with era-B values; a direct maintenance with a skipped
520
- * step; a pre-2025-08 run naming only template and source
521
- * - files on every v1 context, and in the old `Maintenance_Media` relations
522
- */
523
- async function seedSchedules(ctx, sources) {
524
- const { tenantId, userId, roleId } = ctx;
525
- const tenant = ptr("OD3_Tenant", tenantId);
526
- const user = ptr("_User", userId);
527
- const P = (cls, id) => ptr(cls, id);
528
- const relation = (className, ids) => ({
529
- __op: "AddRelation",
530
- objects: ids.map((id) => ptr(className, id)),
531
- });
532
- const localDate = (y, m, d, h = 8) => new Date(y, m - 1, d, h, 0, 0, 0);
533
- // What v1's afterSave wrote on a plan or template a user created: the
534
- // creator reads and writes, od-admin too, tenant users do not read.
535
- const creatorAcl = {
536
- [userId]: { read: true, write: true },
537
- "role:od-admin": { read: true, write: true },
538
- };
539
- const roleName = roleId
540
- ? (await new node_1.default.Query(node_1.default.Role).get(roleId, env_js_1.MK)).getName()
541
- : undefined;
542
- const kompressorId = await create(ctx, "OD3_Source", { name: "Kompressor K1", tag: "kompressor-k1", tenant }, daysAgo(380));
543
- const contactId = await create(ctx, "OD3_Contact", {
544
- firstname: "Max",
545
- lastname: "Dienstleister",
546
- email: "service@example.invalid",
547
- description: SEED_MARKER,
548
- tenant,
549
- }, daysAgo(370));
550
- // ── files in the old Media store ─────────────────────────────────────────
551
- const file = (name) => ({
552
- __type: "File",
553
- name,
554
- url: `https://example.invalid/${name}`,
555
- });
556
- const stepMediaId = await create(ctx, "OD3_Maintenance_Media", { media: file("anleitung-oelwechsel.txt"), description: "Anleitung Ölwechsel", tenant }, daysAgo(365));
557
- const executionMediaId = await create(ctx, "OD3_Maintenance_Media", { media: file("foto-altoel.txt"), description: "Foto Altöl", tenant }, daysAgo(90, 11));
558
- // ── steps, one per era ───────────────────────────────────────────────────
559
- const drainId = await create(ctx, "OD3_Maintenance_Schedule_Step", {
560
- title: "Öl ablassen",
561
- description: "Ablassschraube lösen, Altöl auffangen.",
562
- order: 1,
563
- // Era A: a static value an admin set, shown to the technician.
564
- fields: [
565
- { value: "Handschuhe, Schutzbrille", metafield: { label: "PSA", allowedValues: [], required: false } },
566
- ],
567
- media: relation("OD3_Maintenance_Media", [stepMediaId]),
568
- tenant,
569
- }, daysAgo(365));
570
- const pressureId = await create(ctx, "OD3_Maintenance_Schedule_Step", { title: "Druck messen", order: 2, tenant }, daysAgo(365));
571
- // Era C: the step's capture fields as a Meta_Config.
572
- await create(ctx, "OD3_Meta_Config", {
573
- context: JSON.stringify(["schedule", "step", "meta", pressureId]),
574
- config: {
575
- fields: [{ name: "druck", label: "Druck (bar)", type: "number" }],
576
- description: SEED_MARKER,
577
- },
578
- tenant,
579
- }, daysAgo(200));
580
- const filterId = await create(ctx, "OD3_Maintenance_Schedule_Step", {
581
- title: "Filter prüfen",
582
- order: 1,
583
- // Era B: a field config, values captured per run into `meta`.
584
- fields: [
585
- { name: "zustand", label: "Zustand", type: "select", options: ["gut", "verschlissen"] },
586
- ],
587
- tenant,
588
- }, daysAgo(250));
589
- const visualId = await create(ctx, "OD3_Maintenance_Schedule_Step", { title: "Sichtprüfung Hallendach", order: 1, tenant }, daysAgo(250));
590
- // ── templates ────────────────────────────────────────────────────────────
591
- const templateId = await create(ctx, "OD3_Maintenance_Schedule_Template", {
592
- title: "Ölwechsel",
593
- description: "Standard-Ölwechsel für Werkzeugmaschinen",
594
- color: "#336699",
595
- enabled: true,
596
- // Starts on 31 January: v1's dayjs clamps to the month end.
597
- cron: {
598
- schedule_type: "timestamp",
599
- timestamp: { startDate: dateVal(localDate(2025, 1, 31)), number: 1, unit: "months" },
600
- },
601
- notifyBeforeDue: { value: 7, unit: "days" },
602
- steps: relation("OD3_Maintenance_Schedule_Step", [drainId, pressureId]),
603
- contacts: relation("OD3_Contact", [contactId]),
604
- sources: relation("OD3_Source", [sources.cncId]),
605
- tenant,
606
- }, daysAgo(365), undefined, creatorAcl);
607
- await create(ctx, "OD3_Maintenance_Schedule_Template", {
608
- title: "Alte Vorlage (Editor-Format 2024)",
609
- enabled: false,
610
- cron: {
611
- scheduletype: "human",
612
- run_cron: "0 8 * * 1",
613
- run_startdate: dateVal(daysAgo(700)),
614
- is_week: false,
615
- week_interval: 1,
616
- is_one_time: false,
617
- },
618
- tenant,
619
- }, daysAgo(700), undefined, creatorAcl);
620
- // ── plans ────────────────────────────────────────────────────────────────
621
- // Inherits the template's steps (none of its own) and interval, overriding
622
- // only the number: every 3 months from 31 January.
623
- const inheritedId = await create(ctx, "OD3_Maintenance_Schedule", {
624
- title: "CNC-04 - Ölwechsel",
625
- description: "Laut Herstellerhandbuch, Kap. 7",
626
- color: "#ff8800",
627
- enabled: true,
628
- template: P("OD3_Maintenance_Schedule_Template", templateId),
629
- source: P("OD3_Source", sources.cncId),
630
- cron: { schedule_type: "timestamp", timestamp: { number: 3 } },
631
- contacts: relation("OD3_Contact", [contactId]),
632
- tenant,
633
- }, daysAgo(360), undefined, roleName
634
- ? { ...creatorAcl, [`role:${roleName}`]: { read: true } }
635
- : creatorAcl);
636
- const filterPlanId = await create(ctx, "OD3_Maintenance_Schedule", {
637
- title: "Presse A - Filter",
638
- enabled: true,
639
- source: P("OD3_Source", sources.untaggedId),
640
- cron: {
641
- schedule_type: "timestamp",
642
- timestamp: {
643
- startDate: dateVal(daysAgo(200)),
644
- // A bare string, as `shiftScheduleInterval` leaves it.
645
- endDate: daysAgo(-100).toISOString(),
646
- number: 2,
647
- unit: "weeks",
648
- },
649
- },
650
- // What the admin form writes on mount: no reminder.
651
- notifyBeforeDue: { value: 0, unit: "milliseconds" },
652
- steps: relation("OD3_Maintenance_Schedule_Step", [filterId]),
653
- tenant,
654
- }, daysAgo(210), undefined, creatorAcl);
655
- // Imported by the v1 Outlook poller: master key, so no ACL was ever saved.
656
- const importedId = await create(ctx, "OD3_Maintenance_Schedule", {
657
- title: "Halle B - Jahresprüfung",
658
- enabled: false,
659
- source: P("OD3_Source", sources.hallId),
660
- cron: {
661
- schedule_type: "timestamp",
662
- timestamp: { startDate: dateVal(localDate(2024, 2, 29, 9)), number: 1, unit: "years" },
663
- },
664
- notifyBeforeDue: { value: 3, unit: "hours" },
665
- steps: relation("OD3_Maintenance_Schedule_Step", [visualId]),
666
- tenant,
667
- }, daysAgo(300), undefined, null);
668
- // v1's afterSave gives a new plan an ACL and saves it whenever the write
669
- // was not master — and a maintenance-key write is not. So the plan above
670
- // got `od-admin` after all. Readable-by-everybody is what the import left in
671
- // effect; public read is the nearest this seeder can write.
672
- await update(ctx.config, "OD3_Maintenance_Schedule", importedId, {
673
- ACL: { "*": { read: true, write: true } },
674
- });
675
- await create(ctx, "OD3_Meta_Entry", {
676
- context: JSON.stringify(["schedule", "sync", "microsoft"]),
677
- entryClassName: "OD3_Maintenance_Schedule",
678
- entryObjectId: importedId,
679
- config: { description: SEED_MARKER },
680
- values: {
681
- microsoftCalendarEventId: "seed-outlook-event-1",
682
- microsoftCalendarChangeKey: "seed-change-key-1",
683
- },
684
- tenant,
685
- }, daysAgo(300));
686
- // Interval number 0: "only on the start date". Shares a step with the
687
- // template, on the same machine as the inherited plan.
688
- await create(ctx, "OD3_Maintenance_Schedule", {
689
- title: "CNC-04 - Einmalprüfung",
690
- enabled: true,
691
- source: P("OD3_Source", sources.cncId),
692
- cron: {
693
- schedule_type: "timestamp",
694
- timestamp: { startDate: dateVal(daysAgo(-20)), number: 0, unit: "days" },
695
- },
696
- steps: relation("OD3_Maintenance_Schedule_Step", [drainId]),
697
- tenant,
698
- }, daysAgo(40), undefined, creatorAcl);
699
- // ── executions ───────────────────────────────────────────────────────────
700
- // Created without their plan, which is set afterwards. v1's afterSave builds
701
- // a fresh set of execution steps from the plan whenever an execution is
702
- // *created* with one — on top of the steps seeded here, which would leave
703
- // every run with a second, all-open set. Real v1 data has one set: the
704
- // hook's, ticked off by the runner. The hook ignores updates.
705
- const execution = async (payload, createdAt, updatedAt) => {
706
- const { schedule, ...rest } = payload;
707
- const id = await create(ctx, "OD3_Maintenance_Schedule_Execution", { user, tenant, ...rest }, createdAt, updatedAt);
708
- if (schedule) {
709
- await update(ctx.config, "OD3_Maintenance_Schedule_Execution", id, {
710
- schedule,
711
- });
712
- }
713
- return id;
714
- };
715
- const executionStep = (executionId, payload, createdAt) => create(ctx, "OD3_Maintenance_Schedule_Execution_Step", {
716
- scheduleexecution: P("OD3_Maintenance_Schedule_Execution", executionId),
717
- tenant,
718
- ...payload,
719
- }, createdAt);
720
- const planRef = P("OD3_Maintenance_Schedule", inheritedId);
721
- const templateRef = P("OD3_Maintenance_Schedule_Template", templateId);
722
- // A protocol: completed, with material, a comment and era-C values.
723
- const protocolId = await execution({
724
- schedule: planRef,
725
- origin: templateRef,
726
- source: P("OD3_Source", sources.cncId),
727
- title: "CNC-04 - Ölwechsel",
728
- status: "completed",
729
- finishedAt: dateVal(daysAgo(90, 11)),
730
- material: [
731
- { id: sources.itemOel, name: "Spezialöl", quantity: 2, unit: "L" },
732
- { id: "manual-7", name: "Putzlappen", quantity: 3, unit: "Stk" },
733
- ],
734
- media: relation("OD3_Maintenance_Media", [executionMediaId]),
735
- }, daysAgo(90, 10), daysAgo(90, 11));
736
- await executionStep(protocolId, {
737
- step: P("OD3_Maintenance_Schedule_Step", drainId),
738
- title: "Öl ablassen",
739
- description: "Ablassschraube lösen, Altöl auffangen.",
740
- order: 1,
741
- done: true,
742
- comment: "Altöl sehr dunkel, Intervall prüfen",
743
- }, daysAgo(90, 10));
744
- const measuredId = await executionStep(protocolId, {
745
- step: P("OD3_Maintenance_Schedule_Step", pressureId),
746
- title: "Druck messen",
747
- order: 2,
748
- done: true,
749
- comment: "",
750
- }, daysAgo(90, 10));
751
- await create(ctx, "OD3_Meta_Entry", {
752
- context: JSON.stringify(["schedule", "step", "meta", pressureId]),
753
- entryClassName: "OD3_Maintenance_Schedule_Execution_Step",
754
- entryObjectId: measuredId,
755
- values: { druck: 5.5 },
756
- config: {
757
- fields: [{ name: "druck", label: "Druck (bar)", type: "number" }],
758
- description: SEED_MARKER,
759
- },
760
- tenant,
761
- }, daysAgo(90, 11));
762
- // Closed by a re-run: `terminated` — not a protocol.
763
- const terminatedId = await execution({
764
- schedule: planRef,
765
- title: "CNC-04 - Ölwechsel",
766
- status: "terminated",
767
- finishedAt: dateVal(daysAgo(60, 9)),
768
- }, daysAgo(60, 8));
769
- await executionStep(terminatedId, { step: P("OD3_Maintenance_Schedule_Step", drainId), title: "Öl ablassen", order: 1, done: false }, daysAgo(60, 8));
770
- // The same, after a server restart rewrote the status to `completed`.
771
- const rewrittenId = await execution({
772
- schedule: planRef,
773
- title: "CNC-04 - Ölwechsel",
774
- status: "completed",
775
- finishedAt: dateVal(daysAgo(30, 9)),
776
- }, daysAgo(30, 8));
777
- await executionStep(rewrittenId, { step: P("OD3_Maintenance_Schedule_Step", drainId), title: "Öl ablassen", order: 1, done: true }, daysAgo(30, 8));
778
- await executionStep(rewrittenId, { step: P("OD3_Maintenance_Schedule_Step", pressureId), title: "Druck messen", order: 2, done: false }, daysAgo(30, 8));
779
- // An open run, with an era-B value captured so far.
780
- const openId = await execution({
781
- schedule: P("OD3_Maintenance_Schedule", filterPlanId),
782
- title: "Presse A - Filter",
783
- status: "running",
784
- }, daysAgo(3, 7));
785
- await executionStep(openId, {
786
- step: P("OD3_Maintenance_Schedule_Step", filterId),
787
- title: "Filter prüfen",
788
- order: 1,
789
- done: false,
790
- meta: [
791
- { name: "zustand", label: "Zustand", type: "select", options: ["gut", "verschlissen"], value: "verschlissen" },
792
- ],
793
- }, daysAgo(3, 7));
794
- // A direct maintenance ("Direkte Wartung"): no plan, one step skipped.
795
- const directId = await execution({
796
- source: P("OD3_Source", kompressorId),
797
- title: "Sichtprüfung Kompressor",
798
- description: "Nach Störungsmeldung der Frühschicht",
799
- status: "completed",
800
- finishedAt: dateVal(daysAgo(15, 10)),
801
- }, daysAgo(15, 9));
802
- await executionStep(directId, { title: "Leckage prüfen", order: 0, done: true }, daysAgo(15, 9));
803
- await executionStep(directId, { title: "Riemen prüfen", order: 0, done: false }, daysAgo(15, 9));
804
- // Before 2025-08: template and source, no plan pointer, no step pointer.
805
- const legacyId = await execution({
806
- origin: templateRef,
807
- source: P("OD3_Source", sources.cncId),
808
- title: "CNC-04 - Ölwechsel",
809
- status: "completed",
810
- finishedAt: dateVal(daysAgo(200, 12)),
811
- }, daysAgo(200, 11));
812
- await executionStep(legacyId, { title: "Öl ablassen", order: 0, done: true }, daysAgo(200, 11));
813
- // ── files on the v1 asset contexts ───────────────────────────────────────
814
- const asset = (context, description, name, at) => create(ctx, "OD3_Assets", { context, description, file: file(name), user, tenant }, at);
815
- await asset(`schedule-media-${inheritedId}`, "Handbuch CNC-04", "handbuch-cnc04.txt", daysAgo(350));
816
- await asset(`schedule-step-media-${drainId}`, "Ablassschraube (Foto)", "ablassschraube.txt", daysAgo(340));
817
- await asset(`schedule-execution-${protocolId}`, "Foto nach Ölwechsel", "nach-oelwechsel.txt", daysAgo(90, 11));
818
- // On a run that is not migrated: must stay where it is.
819
- await asset(`schedule-execution-${terminatedId}`, "Foto abgebrochener Lauf", "abgebrochen.txt", daysAgo(60, 9));
820
- }
821
- // ── purge ──────────────────────────────────────────────────────────────────
822
- const SEEDED_CLASSES = [
823
- "OD3_Maintenance_Schedule_Execution_Step",
824
- "OD3_Maintenance_Schedule_Execution",
825
- "OD3_Maintenance_Schedule",
826
- "OD3_Maintenance_Schedule_Template",
827
- "OD3_Maintenance_Schedule_Step",
828
- "OD3_Maintenance_Media",
829
- "OD3_Maintenance_Ticket_Assignment",
830
- "OD3_Maintenance_Ticket_Material",
831
- "OD3_Maintenance_Ticket_Kanban_State_Current",
832
- "OD3_Maintenance_Ticket_Kanban_State",
833
- "OD3_Maintenance_Ticket_Issuecategory",
834
- "OD3_Maintenance_Ticket_Project",
835
- "OD3_Maintenance_Ticket_Source",
836
- "OD3_Maintenance_Ticket_Title",
837
- "OD3_Maintenance_Duedate",
838
- "OD3_Maintenance_Restriction",
839
- "OD3_Maintenance_Frequency",
840
- "OD3_Maintenance_Downtime",
841
- "OD3_Maintenance_Priority",
842
- "OD3_Maintenance_Message",
843
- "OD3_Maintenance_Ticket",
844
- "OD3_Maintenance_Ticket_FormConfig",
845
- "OD3_Maintenance_Item",
846
- "OD3_Maintenance_Project",
847
- "OD3_Maintenance_Issuecategory",
848
- "OD3_Maintenance_Kanban_State",
849
- ];
850
- /**
851
- * Delete everything in the v1 classes this seeder touches.
852
- *
853
- * Deliberately blunt: this is a dev-only reset, and the seeder's whole point is a
854
- * known starting state. It does **not** touch `OD3_Source`, `OD3_Assets`,
855
- * `OD3_Tenant` or `_User`, because those are shared with the rest of the stack.
856
- */
857
- async function purge() {
858
- for (const className of SEEDED_CLASSES) {
859
- let removed = 0;
860
- for (;;) {
861
- const page = await new node_1.default.Query(className).limit(200).find(env_js_1.MK);
862
- if (page.length === 0)
863
- break;
864
- await node_1.default.Object.destroyAll(page, {
865
- context: { skipChangelog: true },
866
- });
867
- removed += page.length;
868
- }
869
- if (removed)
870
- console.log(` purged ${removed.toString().padStart(4)} ${className}`);
871
- }
872
- // Shared classes: only rows carrying the seed marker. Not "everything in a
873
- // v1 context" — a dev database can hold v1 meta from before the seeder
874
- // existed, and a reset of test data must not take real data with it.
875
- const shared = [
876
- [
877
- "OD3_Meta_Config (seeded)",
878
- () => new node_1.default.Query("OD3_Meta_Config").equalTo("config.description", SEED_MARKER),
879
- ],
880
- [
881
- "OD3_Meta_Entry (seeded)",
882
- () => new node_1.default.Query("OD3_Meta_Entry").equalTo("config.description", SEED_MARKER),
883
- ],
884
- [
885
- "OD3_Contact (seeded)",
886
- () => new node_1.default.Query("OD3_Contact").equalTo("description", SEED_MARKER),
887
- ],
888
- ];
889
- for (const [label, build] of shared) {
890
- let removed = 0;
891
- for (;;) {
892
- const page = await build().limit(200).find(env_js_1.MK);
893
- if (page.length === 0)
894
- break;
895
- await node_1.default.Object.destroyAll(page, {
896
- context: { skipChangelog: true },
897
- });
898
- removed += page.length;
899
- }
900
- if (removed)
901
- console.log(` purged ${removed.toString().padStart(4)} ${label}`);
902
- }
903
- console.log(`\n (OD3_Source, OD3_Assets, OD3_Tenant and _User left alone — shared with the stack)\n`);
904
- }
905
- // ── main ───────────────────────────────────────────────────────────────────
906
- async function main() {
907
- let config;
908
- try {
909
- config = (0, env_js_1.readConfig)(process.argv.slice(2));
910
- }
911
- catch (error) {
912
- if (error instanceof env_js_1.MigrationConfigError) {
913
- console.error(`\n✗ ${error.message}\n`);
914
- return 2;
915
- }
916
- throw error;
917
- }
918
- (0, env_js_1.initParse)(config);
919
- console.log(`\nv1 test-data seeder (DEV ONLY)`);
920
- console.log(` server ${config.parseUrl}`);
921
- if (process.argv.includes("--purge")) {
922
- console.log(`\npurging v1 classes…\n`);
923
- await purge();
924
- return 0;
925
- }
926
- // Attach to whatever tenant/user the stack already has rather than inventing one.
927
- const tenants = await new node_1.default.Query("OD3_Tenant").ascending("createdAt").find(env_js_1.MK);
928
- const users = await new node_1.default.Query(node_1.default.User).ascending("createdAt").find(env_js_1.MK);
929
- if (tenants.length === 0 || users.length === 0 || !tenants[0].id || !users[0].id) {
930
- console.error(`\n✗ Need at least one OD3_Tenant and one _User to attach the test data to.\n` +
931
- ` Found ${tenants.length} tenant(s), ${users.length} user(s).\n`);
932
- return 2;
933
- }
934
- // Tenant 1 is the one the seeding user actually belongs to, not simply the
935
- // oldest. Everything seeded here gets tenant-role ACLs, and master data
936
- // (Status, Equipment) grants roles ONLY — no per-user grant — so data written
937
- // into a tenant the user is not a member of is invisible in the UI. That reads
938
- // exactly like a broken migration: tickets show up (they also grant their
939
- // creator) while their status and equipment render as blank or raw ids.
940
- //
941
- // The oldest-first ordering made this worse: the synthetic tenant below is
942
- // backdated, so on every run after the first it sorted ahead of the real one.
943
- const userTenantId = users[0].get("tenant")?.id;
944
- const tenantId = userTenantId && tenants.some((t) => t.id === userTenantId)
945
- ? userTenantId
946
- : tenants[0].id;
947
- let tenant2Id = tenants.find((t) => t.id !== tenantId)?.id ?? "";
948
- if (!tenant2Id) {
949
- // The multi-tenant cases need a second tenant; create one if the stack has
950
- // only the default.
951
- const second = await (0, rest_js_1.restCreateRaw)(config, "OD3_Tenant", { label: `Testmandant 2 (${SEED_MARKER})` }, daysAgo(600));
952
- tenant2Id = second.objectId;
953
- console.log(` created a second tenant for the multi-tenant cases: ${tenant2Id}`);
954
- }
955
- console.log(` tenant 1 ${tenantId}`);
956
- console.log(` tenant 2 ${tenant2Id}`);
957
- console.log(` user ${users[0].id}\n`);
958
- // Prefer a tenant-scoped role, so the assignment looks like real data.
959
- const roles = await new node_1.default.Query(node_1.default.Role).find(env_js_1.MK);
960
- const roleId = roles.find((r) => r.getName() === `od-tenant-user-${tenantId}`)?.id ??
961
- roles[0]?.id;
962
- const ctx = {
963
- config,
964
- tenantId,
965
- tenant2Id,
966
- userId: users[0].id,
967
- roleId,
968
- created: new Map(),
969
- };
970
- await seed(ctx);
971
- console.log(`created:`);
972
- for (const [className, count] of [...ctx.created].sort()) {
973
- console.log(` ${count.toString().padStart(4)} ${className}`);
974
- }
975
- console.log(`\n✓ seeded. Next:\n` +
976
- ` node dist/scripts/migration/run.js --dry-run\n`);
977
- return 0;
978
- }
979
- main().then((code) => process.exit(code), (error) => {
980
- console.error(error);
981
- process.exit(1);
982
- });