@steedos/migrate 2.4.0-beta.9 → 2.4.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.
@@ -2,7 +2,7 @@
2
2
  * @Author: sunhaolin@hotoa.com
3
3
  * @Date: 2023-01-10 17:18:23
4
4
  * @LastEditors: sunhaolin@hotoa.com
5
- * @LastEditTime: 2023-01-14 10:29:56
5
+ * @LastEditTime: 2023-02-11 10:49:47
6
6
  * @Description:
7
7
  */
8
8
  'use strict'
@@ -23,7 +23,12 @@ module.exports.up = async function (next) {
23
23
  console.log('[migration] add-instance-tasks is running...')
24
24
  await instanceColl.find({}).forEach(async function (insDoc) {
25
25
  var docs = [];
26
- insDoc.traces.forEach(function (tDoc) {
26
+ var latestApproveIndexMap = {}
27
+ insDoc.traces.forEach(function (tDoc, tIdx) {
28
+ if (tIdx == 0 && (!insDoc.distribute_from_instance && !insDoc.forward_from_instance)) {
29
+ // 只有分发或转发的申请单,开始节点生成instance_tasks
30
+ return
31
+ }
27
32
  if (tDoc.approves) {
28
33
  tDoc.approves.forEach(function (aDoc) {
29
34
  if (aDoc.type == 'distribute' || aDoc.judge == 'relocated' || aDoc.judge == 'terminated' || aDoc.judge == 'reassigned') {
@@ -50,10 +55,19 @@ module.exports.up = async function (next) {
50
55
  aDoc['is_archived'] = insDoc.is_archived;
51
56
  aDoc['category'] = insDoc.category;
52
57
  docs.push(aDoc)
58
+ if (aDoc.is_finished) { //记录下需要设置is_latest_approve的游标,如有重复审批则更新为最新的
59
+ latestApproveIndexMap[aDoc.handler] = docs.length - 1
60
+ }
53
61
  })
54
62
  }
55
63
  })
56
64
 
65
+ for (const handler in latestApproveIndexMap) {
66
+ if (Object.hasOwnProperty.call(latestApproveIndexMap, handler)) {
67
+ docs[latestApproveIndexMap[handler]].is_latest_approve = true
68
+ }
69
+ }
70
+
57
71
  if (docs.length > 0) {
58
72
  try {
59
73
  await tasksColl.insertMany(docs);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/migrate",
3
- "version": "2.4.0-beta.9",
3
+ "version": "2.4.0",
4
4
  "description": "Migration scripts for steedos",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -12,5 +12,5 @@
12
12
  "publishConfig": {
13
13
  "access": "public"
14
14
  },
15
- "gitHead": "7f75a50d8d5ac875eb577d586981ba654a5180ff"
15
+ "gitHead": "70a4e7417d8d86c47cf5c7e3bbe0e89f2cee4222"
16
16
  }