@things-factory/worklist 10.1.269 → 10.1.271
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.
- package/dist-client/components/activity-instance-ribon.js +3 -2
- package/dist-client/components/activity-instance-ribon.js.map +1 -1
- package/dist-client/components/activity-thread-ribon.js +3 -2
- package/dist-client/components/activity-thread-ribon.js.map +1 -1
- package/dist-client/components/activity-thread-timeline.js +3 -1
- package/dist-client/components/activity-thread-timeline.js.map +1 -1
- package/dist-client/components/decision-content.js +1 -1
- package/dist-client/components/decision-content.js.map +1 -1
- package/dist-client/components/ribon-description.d.ts +13 -0
- package/dist-client/components/ribon-description.js +14 -0
- package/dist-client/components/ribon-description.js.map +1 -0
- package/dist-client/components/source-link.d.ts +1 -1
- package/dist-client/pages/activity-thread/activity-thread-view-page.js +3 -0
- package/dist-client/pages/activity-thread/activity-thread-view-page.js.map +1 -1
- package/dist-client/route.d.ts +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/activity-approval/_abort.js +2 -0
- package/dist-server/controllers/activity-approval/_abort.js.map +1 -1
- package/dist-server/controllers/activity-approval/claim.js +6 -1
- package/dist-server/controllers/activity-approval/claim.js.map +1 -1
- package/dist-server/controllers/activity-installation/activity-installation-controller.js +5 -0
- package/dist-server/controllers/activity-installation/activity-installation-controller.js.map +1 -1
- package/dist-server/controllers/activity-instance/complete.d.ts +6 -1
- package/dist-server/controllers/activity-instance/complete.js +6 -1
- package/dist-server/controllers/activity-instance/complete.js.map +1 -1
- package/dist-server/controllers/common.js +2 -0
- package/dist-server/controllers/common.js.map +1 -1
- package/dist-server/index.d.ts +1 -0
- package/dist-server/index.js +5 -1
- package/dist-server/index.js.map +1 -1
- package/dist-server/service/activity/finished-case.d.ts +28 -0
- package/dist-server/service/activity/finished-case.js +38 -0
- package/dist-server/service/activity/finished-case.js.map +1 -0
- package/dist-server/service/approval-notice/approval-notice.d.ts +12 -0
- package/dist-server/service/approval-notice/approval-notice.js +19 -0
- package/dist-server/service/approval-notice/approval-notice.js.map +1 -1
- package/dist-server/service/index.d.ts +2 -2
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -12
- package/tests/approval-notice-db.test.ts +3 -1
- package/tests/delegate-approval.test.ts +3 -1
- package/translations/en.json +2 -1
- package/translations/es.json +2 -1
- package/translations/ja.json +2 -1
- package/translations/ko.json +6 -5
- package/translations/ms.json +2 -1
- package/translations/zh.json +2 -1
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._abort = _abort;
|
|
4
4
|
const activity_thread_js_1 = require("../../service/activity-thread/activity-thread.js");
|
|
5
5
|
const opinion_js_1 = require("./opinion.js");
|
|
6
|
+
const approval_notice_js_1 = require("../../service/approval-notice/approval-notice.js");
|
|
6
7
|
const activity_approval_js_1 = require("../../service/activity-approval/activity-approval.js");
|
|
7
8
|
async function _abort({ activityApproval, comment }, context) {
|
|
8
9
|
const { user, tx } = context.state;
|
|
@@ -24,6 +25,7 @@ async function _abort({ activityApproval, comment }, context) {
|
|
|
24
25
|
terminatedAt: new Date(),
|
|
25
26
|
terminator: user
|
|
26
27
|
});
|
|
28
|
+
await (0, approval_notice_js_1.closeApprovalNotices)(tx, [activityApproval]);
|
|
27
29
|
return result;
|
|
28
30
|
}
|
|
29
31
|
//# sourceMappingURL=_abort.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_abort.js","sourceRoot":"","sources":["../../../server/controllers/activity-approval/_abort.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"_abort.js","sourceRoot":"","sources":["../../../server/controllers/activity-approval/_abort.ts"],"names":[],"mappings":";;AAKA,wBA4BC;AAjCD,yFAAuG;AACvG,6CAA6C;AAC7C,yFAAuF;AACvF,+FAAiH;AAE1G,KAAK,UAAU,MAAM,CAC1B,EAAE,gBAAgB,EAAE,OAAO,EAA2D,EACtF,OAAwB;IAExB,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAElC,IAAI,MAAM,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uCAAgB,CAAC,CAAC,IAAI,CAAC;QACzD,GAAG,gBAAgB;QACnB,QAAQ,EAAE,+CAAwB,CAAC,OAAO;QAC1C,GAAG,IAAA,2BAAc,EAAC,OAAO,CAAC;QAC1B,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAI,IAAI,EAAE;QACxB,UAAU,EAAE,IAAI;KACjB,CAAC,CAAA;IAEF,MAAM,EAAE,CAAC,aAAa,CAAC,mCAAc,CAAC,CAAC,IAAI,CAAC;QAC1C,GAAG,gBAAgB,CAAC,cAAc;QAClC,WAAW,EAAE,OAAO;QACpB,MAAM,EAAE,OAAO;QACf,KAAK,EAAE,yCAAoB,CAAC,OAAO;QACnC,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAI,IAAI,EAAE;QACxB,UAAU,EAAE,IAAI;KACjB,CAAC,CAAA;IAEF,MAAM,IAAA,yCAAoB,EAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAClD,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { ActivityThread, ActivityThreadStatus } from '../../service/activity-thread/activity-thread.js'\nimport { stampedComment } from './opinion.js'\nimport { closeApprovalNotices } from '../../service/approval-notice/approval-notice.js'\nimport { ActivityApproval, ActivityApprovalJudgment } from '../../service/activity-approval/activity-approval.js'\n\nexport async function _abort(\n { activityApproval, comment }: { activityApproval: ActivityApproval; comment: string },\n context: ResolverContext\n): Promise<ActivityApproval> {\n const { user, tx } = context.state\n\n var result = await tx.getRepository(ActivityApproval).save({\n ...activityApproval,\n judgment: ActivityApprovalJudgment.Aborted,\n ...stampedComment(comment),\n transaction: 'abort',\n updater: user,\n terminatedAt: new Date(),\n terminator: user\n })\n\n await tx.getRepository(ActivityThread).save({\n ...activityApproval.activityThread,\n transaction: 'abort',\n reason: comment,\n state: ActivityThreadStatus.Aborted,\n updater: user,\n terminatedAt: new Date(),\n terminator: user\n })\n\n await closeApprovalNotices(tx, [activityApproval])\n return result\n}\n"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.claimPendingApproval = claimPendingApproval;
|
|
4
4
|
const activity_approval_js_1 = require("../../service/activity-approval/activity-approval.js");
|
|
5
|
+
const approval_notice_js_1 = require("../../service/approval-notice/approval-notice.js");
|
|
5
6
|
/**
|
|
6
7
|
* 이 결재를 내가 잡는다 — **대기 중인 것만, 한 번만.**
|
|
7
8
|
*
|
|
@@ -72,6 +73,10 @@ async function claimPendingApproval(tx, approval, judgment) {
|
|
|
72
73
|
* Elsewhere the same `?? 0` was a defect — a missing count drawn as 「0 waiting」 — so the two
|
|
73
74
|
* are worth telling apart rather than tidying into one habit.
|
|
74
75
|
*/
|
|
75
|
-
|
|
76
|
+
const claimed = (result.affected ?? 0) > 0;
|
|
77
|
+
/* the turn is no one's any more - its notices leave the screens (ADR-0164 amendment 1) */
|
|
78
|
+
if (claimed)
|
|
79
|
+
await (0, approval_notice_js_1.closeApprovalNotices)(tx, [approval]);
|
|
80
|
+
return claimed;
|
|
76
81
|
}
|
|
77
82
|
//# sourceMappingURL=claim.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claim.js","sourceRoot":"","sources":["../../../server/controllers/activity-approval/claim.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"claim.js","sourceRoot":"","sources":["../../../server/controllers/activity-approval/claim.ts"],"names":[],"mappings":";;AA4CA,oDAyCC;AAnFD,+FAAiH;AACjH,yFAAuF;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACI,KAAK,UAAU,oBAAoB,CACxC,EAAiB,EACjB,QAA0B,EAC1B,QAAkC;IAElC;;;;OAIG;IACH,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAA;IACxF,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,EAAE;SACpB,kBAAkB,EAAE;SACpB,MAAM,CAAC,uCAAgB,CAAC;SACxB,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;SACjB,KAAK,CAAC,UAAU,EAAE,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC;QACvC;;;WAGG;SACF,QAAQ,CAAC,2CAA2C,EAAE,EAAE,OAAO,EAAE,+CAAwB,CAAC,OAAO,EAAE,CAAC;SACpG,OAAO,EAAE,CAAA;IAEZ;;;;;;;;;;OAUG;IACH,MAAM,OAAO,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,CAAC,CAAA;IAC1C,0FAA0F;IAC1F,IAAI,OAAO;QAAE,MAAM,IAAA,yCAAoB,EAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IACvD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { EntityManager } from 'typeorm'\n\nimport { ActivityApproval, ActivityApprovalJudgment } from '../../service/activity-approval/activity-approval.js'\nimport { closeApprovalNotices } from '../../service/approval-notice/approval-notice.js'\n\n/**\n * 이 결재를 내가 잡는다 — **대기 중인 것만, 한 번만.**\n *\n * ── 왜 필요한가 ────────────────────────────────────────────────────────────\n * 승인·반려·위임이 다 같은 모양으로 시작한다. 읽고 → 「대기 중인가」 보고 → 저장한다. 그 사이에 아무\n * 잠금이 없다.\n *\n * 역할로 걸린 결재는 **여러 명이 같은 건을 본다.** 대기 목록에 뜬 것을 두 사람이 누르는 것은 공유\n * 대기열의 평범한 실패 방식이다. 지금은 둘 다 검사를 통과하고 **둘 다 다음 결재자를 만든다** — 같은\n * 차례의 결재가 두 벌 서서 결재선이 갈라진다. 오류는 안 난다.\n *\n * ── 검사와 쓰기를 한 문장으로 ──────────────────────────────────────────────\n * `WHERE judgment = ''` 를 갱신에 붙인다. 늦게 온 쪽은 0줄을 고치고, 그것으로 「남이 먼저 처리했다」를\n * 안다.\n *\n * 두 트랜잭션이 겹치면 뒤엣것이 행 잠금 앞에서 멈춰 섰다가, 앞엣것이 커밋한 뒤 조건을 **다시 보고**\n * 0줄을 얻는다. 세 드라이버 다 그렇게 동작한다 — postgres 는 잠금이 풀린 뒤 조건을 다시 보고, mysql\n * InnoDB 는 갱신 시 최신 커밋본을 읽고, sqlite 는 쓰기를 아예 직렬화한다.\n *\n * ── 잡고 나면 그 행은 이 트랜잭션 것이다 ───────────────────────────────────\n * 잡는 순간 행 잠금을 쥐므로, 나머지는 평범하게 저장해도 된다. 그래서 여기서는 **판정 하나만** 원자적으로\n * 바꾼다 — 지키려는 규칙이 「대기 중인 것만 처리할 수 있다」 하나이기 때문이다.\n *\n * ── 왜 `@VersionColumn` 이 아닌가 ──────────────────────────────────────────\n * 버전 칸은 컬럼을 늘려 마이그레이션이 필요하고, 이 규칙과 무관한 저장(의견 수정)까지 충돌시킨다.\n * 이미 코드에 있는 검사를 그대로 갱신 문장으로 옮기는 편이 정확하고, 스키마를 안 건드려 배포해도\n * 기존 데이터에 영향이 없다. (2026-08-31, 사용자 결정)\n *\n * ── 잡은 뒤의 저장은 안전하다 ─────────────────────────────────────────────\n * 부르는 쪽은 잡기 뒤에 `save({ ...approval, judgment, comment, … })` 로 나머지를 쓴다. 손에 든\n * `approval` 은 잡기 **전에** 읽은 것이라 판정이 낡았는데, 그 저장이 판정을 다시 명시하므로 되돌리지\n * 않는다. 그리고 잡는 순간 행 잠금을 쥐었으므로 그 사이에 남이 끼어들 수 없다.\n *\n * 한 문장으로 합치지 않은 이유는 관계 칸 때문이다 — `updater`·`terminator`·`originalApproval` 이\n * 엔티티 객체이고, `save()` 는 이것을 FK 로 풀어 주지만 `UpdateQueryBuilder.set()` 은 버전에 따라\n * 다르다. 풀리지 않으면 「누가 처리했나」가 비고 **오류는 안 난다.**\n *\n * @returns 잡았으면 참. 거짓이면 **남이 먼저 처리했다** — 부르는 쪽이 던져서 트랜잭션을 물려야 한다.\n */\nexport async function claimPendingApproval(\n tx: EntityManager,\n approval: ActivityApproval,\n judgment: ActivityApprovalJudgment\n): Promise<boolean> {\n /*\n * 대기로 잡으면 조건이 통과하는데 판정이 그대로라 **두 번째 호출도 통과한다.** 잡는 뜻이 없어진다.\n *\n * `Pending` 은 빈 문자열이라 이 한 줄에 함께 걸린다 — 타입 검사도 그렇게 좁혀 준다.\n */\n if (!judgment) {\n throw new Error('claimPendingApproval: a claim must move the judgment out of pending')\n }\n\n const result = await tx\n .createQueryBuilder()\n .update(ActivityApproval)\n .set({ judgment })\n .where('id = :id', { id: approval.id })\n /*\n * 대기 중은 빈 문자열이다(`ActivityApprovalJudgment.Pending`). `IS NULL` 도 함께 보는 이유는 기본값이\n * 안 들어간 옛 행이 있을 수 있어서다 — 그런 행을 못 잡으면 그 결재는 영영 처리되지 않는다.\n */\n .andWhere('(judgment = :pending OR judgment IS NULL)', { pending: ActivityApprovalJudgment.Pending })\n .execute()\n\n /*\n * `?? 0` here is deliberate, and it is the opposite of the same expression elsewhere.\n *\n * A missing row count means we do not know whether this claim took. For a conditional update\n * that hands one person an approval, not knowing has to read as \"did not get it\": refusing a\n * claim costs a retry, while granting one on an unknown result lets two people judge the same\n * request. The unknown value maps to the conservative answer on purpose.\n *\n * Elsewhere the same `?? 0` was a defect — a missing count drawn as 「0 waiting」 — so the two\n * are worth telling apart rather than tidying into one habit.\n */\n const claimed = (result.affected ?? 0) > 0\n /* the turn is no one's any more - its notices leave the screens (ADR-0164 amendment 1) */\n if (claimed) await closeApprovalNotices(tx, [approval])\n return claimed\n}\n"]}
|
|
@@ -7,6 +7,7 @@ const activity_js_1 = require("../../service/activity/activity.js");
|
|
|
7
7
|
const registry_conflict_js_1 = require("./registry-conflict.js");
|
|
8
8
|
const decision_key_declaration_js_1 = require("../../service/activity/decision-key-declaration.js");
|
|
9
9
|
const installable_to_activity_js_1 = require("./installable-to-activity.js");
|
|
10
|
+
const finished_case_js_1 = require("../../service/activity/finished-case.js");
|
|
10
11
|
/**
|
|
11
12
|
* 등록된 양식을 **도메인에 실제로 세운다.**
|
|
12
13
|
*
|
|
@@ -57,6 +58,10 @@ class ActivityInstallations {
|
|
|
57
58
|
static installActivityTemplate(template) {
|
|
58
59
|
(0, registry_conflict_js_1.assertNotDeclaredIntended)(template.name, ActivityInstallations.intended);
|
|
59
60
|
(0, registry_conflict_js_1.assertDoorSlugIsFree)(template.name, decision_key_declaration_js_1.doorSlug, ActivityInstallations.templates);
|
|
61
|
+
/* Said, not refused: activities registered before the rule still install; their module's test holds them to it. */
|
|
62
|
+
const empty = (0, finished_case_js_1.finishedCaseShowsNothing)(template);
|
|
63
|
+
if (empty)
|
|
64
|
+
console.warn(`[worklist] ${empty} (finished-case.ts)`);
|
|
60
65
|
ActivityInstallations.templates[template.name] = template;
|
|
61
66
|
}
|
|
62
67
|
/**
|
package/dist-server/controllers/activity-installation/activity-installation-controller.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity-installation-controller.js","sourceRoot":"","sources":["../../../server/controllers/activity-installation/activity-installation-controller.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"activity-installation-controller.js","sourceRoot":"","sources":["../../../server/controllers/activity-installation/activity-installation-controller.ts"],"names":[],"mappings":";;;AA+BA,0CAiCC;AA9DD,iDAA6D;AAE7D,oEAA6E;AAG7E,iEAAmH;AACnH,oGAA6E;AAC7E,6EAAoF;AACpF,8EAAkF;AAElF;;;;;;;;;;;;;;;;;;GAkBG;AACI,KAAK,UAAU,eAAe,CACnC,IAAY,EACZ,MAAc,EACd,UAAmD,EAAE;IAErD,MAAM,QAAQ,GAAG,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAEhD,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd;;WAEG;QACH,MAAM,IAAI,KA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epository } from '@things-factory/shell'\n\nimport { Activity, ActivityStatus } from '../../service/activity/activity.js'\nimport { InstallableActivity } from '../../service/installable-activity/installable-activity.js'\nimport { ActivityReadiness } from '../../service/installable-activity/activity-readiness.js'\nimport { assertDoorSlugIsFree, assertNotAlreadyInstalled, assertNotDeclaredIntended } from './registry-conflict.js'\nimport { doorSlug } from '../../service/activity/decision-key-declaration.js'\nimport { activityDefaultsFrom, activityRowFrom } from './installable-to-activity.js'\nimport { finishedCaseShowsNothing } from '../../service/activity/finished-case.js'\n\n/**\n * 등록된 양식을 **도메인에 실제로 세운다.**\n *\n * ── 왜 함수로 내놓나 ───────────────────────────────────────────────────────\n * 앞서는 이 일이 화면 뮤테이션 안에만 있었다. 그래서 양식을 세우는 길이 **사람이 화면에서 누르는 것\n * 하나뿐**이었고, 새로 배포하거나 도메인을 하나 더 만들 때마다 그 클릭을 기억해야 했다. 기억하지\n * 못하면 그 기능이 오류 보고 없이 없다.\n *\n * 앱이 「내 기능이 서려면 이 양식이 있어야 한다」를 아는 경우가 있다. 그런 앱은 기동할 때 스스로\n * 세울 수 있어야 한다. 언제 세울지는 앱이 정하고, 세우는 방법은 여기가 한 벌만 갖는다.\n *\n * ── 있는 것을 덮되 결재선은 건드리지 않는다 ────────────────────────────────\n * 이미 있으면 양식의 선언(모델 · 보는 화면 · 시작 방식)으로 덮는다. 버전이 오르면 그 값이 따라와야\n * 하기 때문이다.\n *\n * 그런데 **결재선은 양식의 것이 아니라 그 현장의 것**이다. 누가 결재하는지는 공장이 정한다. 그래서\n * 양식에 결재선 선언이 없으면 이미 있는 결재선이 그대로 남는다 — 버전을 올릴 때마다 결재자가 지워지면\n * 그 뒤로 상신이 곧 완료가 된다.\n */\nexport async function installActivity(\n name: string,\n domain: Domain,\n options: { manager?: EntityManager; user?: any } = {}\n): Promise<Activity> {\n const template = ActivityInstallations.get(name)\n\n if (!template) {\n /*\n * 없는 이름을 세울 수는 없다. 조용히 넘기면 부르는 쪽은 세운 줄 알고, 그 기능은 없는 채로 선다.\n */\n throw new Error(\n `installActivity: there is no installable activity named \"${name}\". ` +\n `known: ${ActivityInstallations.list()\n .map(one => one.name)\n .join(', ')}`\n )\n }\n\n const { manager, user } = options\n const repository = getRepository(Activity, manager)\n\n const existing = await repository.findOneBy({ domain: { id: domain.id }, name })\n\n return await repository.save({\n ...(existing ?? {}),\n ...activityRowFrom(template),\n ...activityDefaultsFrom(template, existing),\n state: ActivityStatus.Released,\n domain,\n creator: existing ? (existing as any).creator : user,\n updater: user\n } as Activity)\n}\n\n/**\n * Work a module has identified as a person's decision and **has not built.**\n *\n * Deliberately not an InstallableActivity. A template with no callback can be installed and\n * issued, and then someone approves a request and nothing happens — on the twin side that means a\n * person presses approve and no equipment moves. So these live in their own registry: the catalog\n * reads them, `installActivity` cannot reach them.\n *\n * They belong on the screen because the catalog is the plan of record. The question \"what is left\"\n * should be answered where people look, not in one person's head.\n */\nexport type IntendedActivity = {\n /** What the activity's `name` will be once it exists. */\n key: string\n /** What the catalog shows. The activity's own name is usually not a sentence a person reads. */\n label: string\n category?: string\n /** What this work is, for the person who will receive it. Draft wording is fine. */\n guide?: string[]\n readiness: ActivityReadiness\n}\n\nexport class ActivityInstallations {\n static templates: { [name: string]: InstallableActivity } = {}\n\n /** Keyed separately from `templates`, so nothing here can be installed by mistake. */\n static intended: { [key: string]: IntendedActivity } = {}\n\n static installActivityTemplate(template: InstallableActivity) {\n assertNotDeclaredIntended(template.name, ActivityInstallations.intended)\n assertDoorSlugIsFree(template.name, doorSlug, ActivityInstallations.templates)\n /* Said, not refused: activities registered before the rule still install; their module's test holds them to it. */\n const empty = finishedCaseShowsNothing(template as any)\n if (empty) console.warn(`[worklist] ${empty} (finished-case.ts)`)\n\n ActivityInstallations.templates[template.name] = template\n }\n\n /**\n * Declare work that should reach someone's worklist and does not yet.\n *\n * A module calls this for each item it has identified. When the real thing is built, delete the\n * call and register the template instead — the catalog row moves from 예정 to 동작 확인됨 on its\n * own.\n */\n static declareIntendedActivity(intended: IntendedActivity) {\n assertNotAlreadyInstalled(intended.key, ActivityInstallations.templates)\n\n ActivityInstallations.intended[intended.key] = intended\n }\n\n static get(name: string): InstallableActivity {\n return ActivityInstallations.templates[name]\n }\n\n static list(): InstallableActivity[] {\n return Object.values(ActivityInstallations.templates)\n }\n\n static listIntended(): IntendedActivity[] {\n return Object.values(ActivityInstallations.intended)\n }\n\n /**\n * 액티비티인스턴스의 변화가 발생했을 때, 호출되는 콜백함수\n * @param name 액티비티인스턴스가 속한 액티비티명\n * @param activityInstance 해당 액티비티인스턴스\n * @param activityThreads 액티비티인스턴스의 변화를 일으킨 원인이 되는 액티비티쓰레드들\n * @param context 서비스 컨텍스트 : domain, user, translation, ..\n * @returns\n */\n static async callback(name: string, activityInstance: any, activityThreads: any[], context: ResolverContext) {\n const installableActivity = ActivityInstallations.templates[name]\n if (!installableActivity) {\n return\n }\n\n const { callback } = installableActivity\n\n callback && (await callback(activityInstance, { causedBy: activityThreads }, context))\n }\n}\n"]}
|
|
@@ -6,8 +6,13 @@ import { ActivityInstance } from '../../service/activity-instance/activity-insta
|
|
|
6
6
|
*
|
|
7
7
|
* For the module that issued the case and judges its work (an application's own to-do); a person ends their own
|
|
8
8
|
* thread through the thread's `end`.
|
|
9
|
+
*
|
|
10
|
+
* `output` is what was done, in the activity's declared output fields - the finished case shows it, as it shows what a
|
|
11
|
+
* person wrote when they end their own thread. A module that closed its to-do with only a reason left the finished
|
|
12
|
+
* screen with nothing to show of how it ended (2026-11-11, 문의 할 일).
|
|
9
13
|
*/
|
|
10
|
-
export declare function complete({ id, reason }: {
|
|
14
|
+
export declare function complete({ id, reason, output }: {
|
|
11
15
|
id: string;
|
|
12
16
|
reason?: string;
|
|
17
|
+
output?: Record<string, any>;
|
|
13
18
|
}, context: ResolverContext): Promise<ActivityInstance>;
|
|
@@ -12,8 +12,12 @@ const common_js_1 = require("../common.js");
|
|
|
12
12
|
*
|
|
13
13
|
* For the module that issued the case and judges its work (an application's own to-do); a person ends their own
|
|
14
14
|
* thread through the thread's `end`.
|
|
15
|
+
*
|
|
16
|
+
* `output` is what was done, in the activity's declared output fields - the finished case shows it, as it shows what a
|
|
17
|
+
* person wrote when they end their own thread. A module that closed its to-do with only a reason left the finished
|
|
18
|
+
* screen with nothing to show of how it ended (2026-11-11, 문의 할 일).
|
|
15
19
|
*/
|
|
16
|
-
async function complete({ id, reason }, context) {
|
|
20
|
+
async function complete({ id, reason, output }, context) {
|
|
17
21
|
const { domain, user, tx } = context.state;
|
|
18
22
|
const repository = tx.getRepository(activity_instance_js_1.ActivityInstance);
|
|
19
23
|
const activityInstance = await repository.findOne({
|
|
@@ -35,6 +39,7 @@ async function complete({ id, reason }, context) {
|
|
|
35
39
|
await threads.save({
|
|
36
40
|
...thread,
|
|
37
41
|
reason,
|
|
42
|
+
...(output ? { output: { ...(thread.output ?? {}), ...output } } : {}),
|
|
38
43
|
state: activity_thread_js_1.ActivityThreadStatus.Ended,
|
|
39
44
|
transaction: 'end',
|
|
40
45
|
startedAt: thread.startedAt ?? now,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"complete.js","sourceRoot":"","sources":["../../../server/controllers/activity-instance/complete.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"complete.js","sourceRoot":"","sources":["../../../server/controllers/activity-instance/complete.ts"],"names":[],"mappings":";;AAkBA,4BAkDC;AApED,qCAA4B;AAE5B,yFAAuG;AACvG,+FAA+G;AAC/G,4CAAwD;AAExD;;;;;;;;;;;GAWG;AACI,KAAK,UAAU,QAAQ,CAC5B,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAiE,EACrF,OAAwB;IAExB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAC1C,MAAM,UAAU,GAAG,EAAE,CAAC,aAAa,CAAC,uCAAgB,CAAC,CAAA;IAErD,MAAM,gBAAgB,GAAG,MAAM,UAAU,CAAC,OAAO,C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A,YAAE,EAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YACxF,MAAM,OAAO,CAAC,IAAI,CAAC;gBACjB,GAAG,MAAM;gBACT,MAAM;gBACN,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACtE,KAAK,EAAE,yCAAoB,CAAC,KAAK;gBACjC,WAAW,EAAE,KAAK;gBAClB,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,GAAG;gBAClC,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,GAAG;aAClB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC;QAC3B,GAAG,gBAAgB;QACnB,eAAe,EAAE,SAAS;QAC1B,MAAM;QACN,GAAG,CAAC,MAAM,IAAA,qCAAyB,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;QACjD,SAAS,EAAE,gBAAgB,CAAC,SAAS,IAAI,GAAG;QAC5C,WAAW,EAAE,KAAK;QAClB,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,GAAG;QACjB,UAAU,EAAE,IAAI;KACV,CAAC,CAAA;AACX,CAAC","sourcesContent":["import { In } from 'typeorm'\n\nimport { ActivityThread, ActivityThreadStatus } from '../../service/activity-thread/activity-thread.js'\nimport { ActivityInstance, ActivityInstanceStatus } from '../../service/activity-instance/activity-instance.js'\nimport { evalActivityInstanceState } from '../common.js'\n\n/**\n * Ends a case whose work is done - every thread still open ends as done, then the case ends. The counterpart of\n * `abort` for a to-do the records show finished: a case handed to several people, or to whoever holds a role, is\n * done for all of them when its work is done, and its history says ended, not aborted.\n *\n * For the module that issued the case and judges its work (an application's own to-do); a person ends their own\n * thread through the thread's `end`.\n *\n * `output` is what was done, in the activity's declared output fields - the finished case shows it, as it shows what a\n * person wrote when they end their own thread. A module that closed its to-do with only a reason left the finished\n * screen with nothing to show of how it ended (2026-11-11, 문의 할 일).\n */\nexport async function complete(\n { id, reason, output }: { id: string; reason?: string; output?: Record<string, any> },\n context: ResolverContext\n): Promise<ActivityInstance> {\n const { domain, user, tx } = context.state\n const repository = tx.getRepository(ActivityInstance)\n\n const activityInstance = await repository.findOne({\n where: { domain: { id: domain.id }, id },\n relations: ['domain', 'activity', 'activityThreads', 'assigneeRoles', 'supervisoryRole', 'updater', 'creator', 'starter', 'terminator']\n })\n\n if (!activityInstance) {\n throw new Error(context.t('error.activity-instance not found', { activityInstance: id }))\n }\n\n if (activityInstance.state == ActivityInstanceStatus.Aborted || activityInstance.state == ActivityInstanceStatus.Ended) {\n throw new Error(context.t(`error.activity-instance is already terminated`, { id, state: activityInstance.state }))\n }\n\n const TERMINATED = [ActivityThreadStatus.Aborted, ActivityThreadStatus.Ended]\n const open = (activityInstance.activityThreads ?? []).filter(thread => !TERMINATED.includes(thread.state))\n const now = new Date()\n if (open.length) {\n const threads = tx.getRepository(ActivityThread)\n for (const thread of await threads.find({ where: { id: In(open.map(one => one.id)) } })) {\n await threads.save({\n ...thread,\n reason,\n ...(output ? { output: { ...(thread.output ?? {}), ...output } } : {}),\n state: ActivityThreadStatus.Ended,\n transaction: 'end',\n startedAt: thread.startedAt ?? now,\n updater: user,\n terminatedAt: now\n })\n }\n }\n\n return await repository.save({\n ...activityInstance,\n activityThreads: undefined,\n reason,\n ...(await evalActivityInstanceState(id, context)),\n startedAt: activityInstance.startedAt ?? now,\n transaction: 'end',\n updater: user,\n terminatedAt: now,\n terminator: user\n } as any)\n}\n"]}
|
|
@@ -21,6 +21,7 @@ const activity_approval_js_1 = require("../service/activity-approval/activity-ap
|
|
|
21
21
|
const activity_installation_controller_js_1 = require("./activity-installation/activity-installation-controller.js");
|
|
22
22
|
const assignee_pool_js_1 = require("../service/activity-instance/assignee-pool.js");
|
|
23
23
|
const assignee_input_js_1 = require("./activity-instance/assignee-input.js");
|
|
24
|
+
const approval_notice_js_1 = require("../service/approval-notice/approval-notice.js");
|
|
24
25
|
async function updateActivityInstanceState(id, { causedBy }, context) {
|
|
25
26
|
const { tx } = context.state;
|
|
26
27
|
var activityInstance = await tx.getRepository(activity_instance_js_1.ActivityInstance).findOne({
|
|
@@ -87,6 +88,7 @@ async function closePendingReferences(instanceId, context) {
|
|
|
87
88
|
transaction: 'close',
|
|
88
89
|
terminatedAt: at
|
|
89
90
|
})));
|
|
91
|
+
await (0, approval_notice_js_1.closeApprovalNotices)(tx, open);
|
|
90
92
|
}
|
|
91
93
|
async function evalActivityInstanceState(id, context) {
|
|
92
94
|
const { tx, user } = context.state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../server/controllers/common.ts"],"names":[],"mappings":";;AAkBA,kEA0CC;AAuCD,8DAsEC;AAED,gFAUC;AAcD,0EAYC;AA2BD,kEA6BC;AAED,sEAoCC;AAED,oFAkBC;AAED,oFA6BC;AAED,sEAoBC;AAED,wEA2CC;AAED,wDAYC;AAjbD,qCAA4B;AAE5B,yDAAsD;AAEtD,+DAA0G;AAE1G,iEAAoF;AACpF,4FAA4G;AAC5G,sFAAoG;AACpG,4FAA8G;AAC9G,qHAAmG;AACnG,oFAAsF;AACtF,6EAA+E;AAMxE,KAAK,UAAU,2BAA2B,CAC/C,EAAU,EACV,EAAE,QAAQ,EAAuC,EACjD,OAAwB;IAExB,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAE5B,IAAI,gBAAgB,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uCAAgB,CAAC,CAAC,OAAO,CAAC;QACtE,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,SAAS,EAAE;YACT,QAAQ;YACR,UAAU;YACV,iBAAiB;YACjB,eAAe;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mC,EAAE,KAA6B;IACvG,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAM;IACR,CAAC;IAED,OAAO,UAAU,EAAE,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACjC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QACrE,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC","sourcesContent":["import { In } from 'typeorm'\n\nimport { Role, User } from '@things-factory/auth-base'\n\nimport { Department, Employee, ApprovalLineItem, OrgMemberTargetType } from '@things-factory/organization'\nimport { ActivitySearchKeyItem } from '../service/activity/activity-search-key-item-type.js'\nimport { AssigneeItem, MultipleInstanceType } from '../service/activity/activity.js'\nimport { ActivityInstance, ActivityInstanceStatus } from '../service/activity-instance/activity-instance.js'\nimport { ActivityThread, ActivityThreadStatus } from '../service/activity-thread/activity-thread.js'\nimport { ActivityApproval, ActivityApprovalJudgment } from '../service/activity-approval/activity-approval.js'\nimport { ActivityInstallations } from './activity-installation/activity-installation-controller.js'\nimport { poolIdsOf, poolMembers } from '../service/activity-instance/assignee-pool.js'\nimport { ROLE_IS_NOT_AN_ASSIGNEE } from './activity-instance/assignee-input.js'\n\nexport type UpdateActivityInstanceStateAddendum = {\n causedBy?: ActivityThread[]\n}\n\nexport async function updateActivityInstanceState(\n id: string,\n { causedBy }: UpdateActivityInstanceStateAddendum,\n context: ResolverContext\n) {\n const { tx } = context.state\n\n var activityInstance = await tx.getRepository(ActivityInstance).findOne({\n where: { id },\n relations: [\n 'domain',\n 'activity',\n 'activityThreads',\n 'assigneeRoles',\n 'supervisoryRole',\n 'updater',\n 'creator',\n 'starter',\n 'terminator'\n ]\n })\n\n activityInstance.transaction = 'thread' /* activity thread에 의해서 변경된 것임을 의미 */\n Object.assign(activityInstance, await evalActivityInstanceState(id, context))\n\n /*\n * **건이 끝나면 참조도 닫는다.**\n *\n * 참조는 결재하지 않으므로 승인·반려로 끝나지 않는다. 닫아 주지 않으면 그 행이 `Pending` 으로 남아\n * 참조 목록에 영원히 나온다 — 오늘 결재자 쪽에서 고친 것과 같은 부류를, 참조를 넣으면서 새로 만들 뻔했다.\n *\n * 중단은 이미 닫힌다(§`activity-thread/_abort.ts` 가 대기 행을 `aborted` 로 닫는다). 여기서 닫는 것은\n * **정상 종료**다.\n */\n if (activityInstance.state === ActivityInstanceStatus.Ended) {\n await closePendingReferences(id, context)\n }\n\n /* callback에서 업무적인 처리도 하고, activityInstance를 일부(주로 input) 수정할 수 있는 기회도 제공. */\n await ActivityInstallations.callback(activityInstance.activity.name, activityInstance, causedBy, context)\n\n await tx.getRepository(ActivityInstance).save(activityInstance)\n}\n\n/**\n * 이 건의 아직 안 닫힌 참조들을 닫는다 — **판정한 것이 아니라 건이 끝난 것이다.**\n *\n * 의견을 냈는지는 `comment` 가 말한다. 비어 있으면 「통지받았고 말하지 않았다」이고, **그것은 동의가\n * 아니다** — 나중에 결재 이력을 읽는 사람이 침묵을 동의로 읽으면 안 된다.\n *\n * `terminator` 를 적지 않는다. 그 사람이 끝낸 것이 아니라 건이 끝난 것이다.\n */\nasync function closePendingReferences(instanceId: string, context: ResolverContext): Promise<void> {\n const { tx } = context.state\n\n const threads = await tx.getRepository(ActivityThread).find({\n where: { activityInstance: { id: instanceId } }\n })\n if (!threads.length) return\n\n const repo = tx.getRepository(ActivityApproval)\n const open = await repo.find({\n where: threads.map(t => ({\n activityThread: { id: t.id },\n participation: 'reference',\n judgment: ActivityApprovalJudgment.Pending\n }))\n })\n if (!open.length) return\n\n const at = new Date()\n await repo.save(\n open.map(row => ({\n ...row,\n judgment: ActivityApprovalJudgment.Closed,\n transaction: 'close',\n terminatedAt: at\n })) as any\n )\n}\n\nexport async function evalActivityInstanceState(\n id: string,\n context: ResolverContext\n): Promise<Partial<ActivityInstance>> {\n const { tx, user } = context.state\n\n const activityInstance = await tx.getRepository(ActivityInstance).findOne({\n where: { id },\n relations: ['activityThreads', 'activity']\n })\n const { threadsMin, activityThreads, state, dueAt } = activityInstance\n\n const validThreads = activityThreads.filter(thread => thread.isValid())\n const pendingStartedThreads = activityThreads.filter(thread => thread.isPendingStarted())\n const pendingEndedThreads = activityThreads.filter(thread => thread.isPendingEnded())\n\n switch (true) {\n case state === ActivityInstanceStatus.Draft:\n case state === ActivityInstanceStatus.Ended:\n case state === ActivityInstanceStatus.Aborted:\n return {}\n case validThreads.length === 0:\n return {\n state: ActivityInstanceStatus.Issued\n }\n case threadsMin > validThreads.length:\n return {\n state: ActivityInstanceStatus.Unassigned\n }\n case pendingStartedThreads.length > 0:\n return {\n state: ActivityInstanceStatus.Assigned,\n assignedAt: new Date()\n }\n case pendingEndedThreads.length > 0:\n var started = !dueAt || dueAt.getTime() > Date.now()\n var changed =\n (started && state !== ActivityInstanceStatus.Started) || (!started && state !== ActivityInstanceStatus.Pending)\n\n return !changed\n ? null\n : started\n ? {\n state: ActivityInstanceStatus.Started,\n startedAt: new Date(),\n starter: user\n }\n : {\n state: ActivityInstanceStatus.Pending\n }\n default:\n return {\n state: activityThreads.some(thread => thread.state == ActivityThreadStatus.Aborted)\n ? ActivityInstanceStatus.Aborted\n : ActivityInstanceStatus.Ended,\n reason: '',\n output: [MultipleInstanceType.Parallel, MultipleInstanceType.Sequential].includes(\n activityInstance.activity.multiple\n )\n ? activityThreads\n .filter(thread => thread.state === ActivityThreadStatus.Ended)\n .reduce((sum, thread) => {\n sum[thread.assigneeId] = thread.output\n return sum\n }, {} as any)\n : activityThreads[0].output,\n terminatedAt: new Date(),\n terminator: user\n }\n }\n}\n\nexport async function createActivityThreadWithUnassigned(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread> {\n const result = await saveWaitingThread(transaction, activityInstance, context)\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: [result] }, context)\n\n return result\n}\n\n/**\n * Someone of the pool has just taken a thread of this case - by pick, or by claiming the waiting thread. Is\n * the case still short of people (fewer threads someone holds than `threadsMin`)? Then the rest of the pool\n * is left one waiting thread to take; once it has enough, none.\n *\n * The waiting thread is what puts the case on the pool's to-do lists (my-open-threads.ts). Left behind after\n * the case had its people, it kept the case on the list of everyone in the pool; gone while the case still\n * waited, nobody else in the pool saw it any more.\n *\n * `threads` are the case's threads as they stand once the taker holds theirs, read under the hold on the case.\n * The case's state is not worked out here - the taker does that once, after writing its own thread.\n */\nexport async function leaveTheRestOfThePoolOneWaiting(\n transaction: string,\n activityInstance: ActivityInstance,\n threads: ActivityThread[],\n context: ResolverContext\n): Promise<void> {\n const held = threads.filter(thread => thread.isValid()).length\n const waiting = threads.some(thread => thread.state === ActivityThreadStatus.Unassigned)\n\n if (held < activityInstance.threadsMin && !waiting) {\n await saveWaitingThread(transaction, activityInstance, context)\n }\n}\n\nasync function saveWaitingThread(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n return await threadRepo.save({\n version: 1,\n domain,\n state: ActivityThreadStatus.Unassigned,\n activityInstance,\n transaction,\n output: activityInstance.output,\n dueAt: activityInstance.dueAt,\n assignedAt: now,\n creator: user,\n updater: user,\n createdAt: now\n })\n}\n\nexport async function createActivityThreadForUser(\n transaction: string,\n activityInstance: ActivityInstance,\n assignee: User,\n context: ResolverContext\n): Promise<ActivityThread> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n const result = await threadRepo.save({\n version: 1,\n domain,\n assignee,\n state: ActivityThreadStatus.Assigned,\n activityInstance,\n transaction,\n output: activityInstance.output,\n dueAt: activityInstance.dueAt,\n assignedAt: now,\n creator: user,\n updater: user,\n createdAt: now\n })\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: [result] }, context)\n\n return result\n}\n\nexport async function createActivityThreadsForUsers(\n transaction: string,\n activityInstance: ActivityInstance,\n assignees: User[],\n context: ResolverContext\n): Promise<ActivityThread[]> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n const distinct = assignees.filter((assignee, idx) => {\n return assignee && !assignees.slice(0, idx).find(x => x.id == assignee.id)\n })\n\n const result = await threadRepo.save(\n distinct.map(assignee => {\n return {\n version: 1,\n assignee,\n state: ActivityThreadStatus.Assigned,\n activityInstance,\n domain,\n transaction,\n output: activityInstance.output,\n creator: user,\n updater: user,\n dueAt: activityInstance.dueAt,\n assignedAt: now\n } as any\n })\n )\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: result }, context)\n\n return result\n}\n\nexport async function createActivityThreadsForAllRoleUsers(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread[]> {\n const { tx } = context.state\n\n /* Everyone the pool reaches - any one of its roles, each person once (assignee-pool.ts). */\n const poolIds = poolIdsOf(activityInstance)\n const roles = poolIds.length ? await tx.getRepository(Role).find({ where: { id: In(poolIds) }, relations: ['users'] }) : []\n const assignees = poolMembers(roles)\n\n if (assignees.length === 0) {\n throw new Error(context.t('error.no user holds the assignee roles', { roles: roles.map(role => role.name).join(', ') }))\n }\n\n // create activity-thread for all of users having given role\n return await createActivityThreadsForUsers(transaction, activityInstance, assignees, context)\n}\n\nexport async function getSystemUserFromMyDepartmentManager(context: ResolverContext): Promise<User> {\n const { domain, user, tx } = context.state\n\n const employee = await tx.getRepository(Employee).findOneBy({\n domain: { id: domain.id },\n user: { id: user.id }\n })\n\n if (!employee || !employee.departmentId) {\n return\n }\n\n const department = await tx.getRepository(Department).findOne({\n where: {\n id: employee.departmentId\n }\n })\n\n if (!department || !department.managerId) return\n\n const manager = await tx.getRepository(Employee).findOne({\n where: {\n domain: { id: domain.id },\n id: department.managerId\n },\n relations: ['user']\n })\n\n return manager?.user\n}\n\nexport async function getSystemUserFromMySupervosor(context: ResolverContext): Promise<User> {\n const { domain, user, tx } = context.state\n\n const employee = await tx.getRepository(Employee).findOneBy({\n domain: { id: domain.id },\n user: { id: user.id }\n })\n\n if (!employee || !employee.supervisorId) {\n return\n }\n\n const supervisor = await tx.getRepository(Employee).findOne({\n where: {\n id: employee.supervisorId\n },\n relations: ['user']\n })\n\n return supervisor?.user\n}\n\nexport async function getSystemUserFromOrgMemberItem(\n item: AssigneeItem | ApprovalLineItem,\n context: ResolverContext\n): Promise<User> {\n const { domain, user, tx } = context.state\n\n const { type, approver, assignee, value } = item as AssigneeItem & ApprovalLineItem\n const id = approver?.id || assignee?.id || value\n\n if (type == OrgMemberTargetType.Employee) {\n /* This domain's only - an id from another tenant made that tenant's person an approver here. */\n const employee =\n id && (await tx.getRepository(Employee).findOne({ where: { domain: { id: domain.id }, id }, relations: ['user'] }))\n\n if (!employee || !employee.user) {\n return\n }\n return employee.user\n } else if (type == OrgMemberTargetType.Department) {\n const department =\n id && (await tx.getRepository(Department).findOne({ where: { domain: { id: domain.id }, id }, relations: ['manager'] }))\n\n if (!department || !department.manager) {\n return\n }\n return await tx.getRepository(User).findOneBy({ id: department.manager.userId })\n } else if (type == OrgMemberTargetType.Role) {\n /*\n * A role is not one person. This answered the role's first user - an unordered relation, so an\n * arbitrary one - and issue() gave that person work meant for the whole role. Each caller decides\n * what a role means there before asking this: the approval line seats the role (create-approval.ts),\n * assignees refuse it (assignee-input.ts). Reaching here is a caller that skipped that step.\n */\n throw Object.assign(new Error(context.t('error.activity-instance a role is not an assignee')), {\n code: ROLE_IS_NOT_AN_ASSIGNEE\n })\n } else if (type == OrgMemberTargetType.Myself) {\n return user\n } else if (type == OrgMemberTargetType.MyDepartment) {\n return await getSystemUserFromMyDepartmentManager(context)\n } else if (type == OrgMemberTargetType.MySupervisor) {\n return await getSystemUserFromMySupervosor(context)\n }\n}\n\nexport function fillActivitySearchKeys(searchKeys: ActivitySearchKeyItem[], input: { [key: string]: any }) {\n if (!input || typeof input !== 'object') {\n return\n }\n\n return searchKeys?.reduce((sum, key, index) => {\n const value = input[key.inputKey]\n if (value != null) {\n sum[`key0${index + 1}`] = value instanceof Array ? value[0] : value\n }\n return sum\n }, {})\n}\n"]}
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../server/controllers/common.ts"],"names":[],"mappings":";;AAmBA,kEA0CC;AAwCD,8DAsEC;AAED,gFAUC;AAcD,0EAYC;AA2BD,kEA6BC;AAED,sEAoCC;AAED,oFAkBC;AAED,oFA6BC;AAED,sEAoBC;AAED,wEA2CC;AAED,wDAYC;AAnbD,qCAA4B;AAE5B,yDAAsD;AAEtD,+DAA0G;AAE1G,iEAAoF;AACpF,4FAA4G;AAC5G,sFAAoG;AACpG,4FAA8G;AAC9G,qHAAmG;AACnG,oFAAsF;AACtF,6EAA+E;AAC/E,sFAAoF;AAM7E,KAAK,UAAU,2BAA2B,CAC/C,EAAU,EACV,EAAE,QAAQ,EAAuC,EACjD,OAAwB;IAExB,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAE5B,IAAI,gBAAgB,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uCAAgB,CAAC,CAAC,OAAO,CAAC;QACtE,KAAK,EAAE,EAAE,EAAE,EAAE;QACb,SAAS,EAAE;YACT,QAAQ;YACR,UAAU;YACV,iBAAiB;YACjB,eAAe;YACf,iBAAiB;YACjB,SAAS;YACT,SAAS;YACT,SAAS;YACT,YAAY;SACb;KACF,CAAC,CAAA;IAEF,gBAAgB,CAAC,WAAW,GAAG,QAAQ,CAAA,CAAC,qCAAqC;IAC7E,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE,MAAM,yBAA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M,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QACjC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;QACrE,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC,EAAE,EAAE,CAAC,CAAA;AACR,CAAC","sourcesContent":["import { In } from 'typeorm'\n\nimport { Role, User } from '@things-factory/auth-base'\n\nimport { Department, Employee, ApprovalLineItem, OrgMemberTargetType } from '@things-factory/organization'\nimport { ActivitySearchKeyItem } from '../service/activity/activity-search-key-item-type.js'\nimport { AssigneeItem, MultipleInstanceType } from '../service/activity/activity.js'\nimport { ActivityInstance, ActivityInstanceStatus } from '../service/activity-instance/activity-instance.js'\nimport { ActivityThread, ActivityThreadStatus } from '../service/activity-thread/activity-thread.js'\nimport { ActivityApproval, ActivityApprovalJudgment } from '../service/activity-approval/activity-approval.js'\nimport { ActivityInstallations } from './activity-installation/activity-installation-controller.js'\nimport { poolIdsOf, poolMembers } from '../service/activity-instance/assignee-pool.js'\nimport { ROLE_IS_NOT_AN_ASSIGNEE } from './activity-instance/assignee-input.js'\nimport { closeApprovalNotices } from '../service/approval-notice/approval-notice.js'\n\nexport type UpdateActivityInstanceStateAddendum = {\n causedBy?: ActivityThread[]\n}\n\nexport async function updateActivityInstanceState(\n id: string,\n { causedBy }: UpdateActivityInstanceStateAddendum,\n context: ResolverContext\n) {\n const { tx } = context.state\n\n var activityInstance = await tx.getRepository(ActivityInstance).findOne({\n where: { id },\n relations: [\n 'domain',\n 'activity',\n 'activityThreads',\n 'assigneeRoles',\n 'supervisoryRole',\n 'updater',\n 'creator',\n 'starter',\n 'terminator'\n ]\n })\n\n activityInstance.transaction = 'thread' /* activity thread에 의해서 변경된 것임을 의미 */\n Object.assign(activityInstance, await evalActivityInstanceState(id, context))\n\n /*\n * **건이 끝나면 참조도 닫는다.**\n *\n * 참조는 결재하지 않으므로 승인·반려로 끝나지 않는다. 닫아 주지 않으면 그 행이 `Pending` 으로 남아\n * 참조 목록에 영원히 나온다 — 오늘 결재자 쪽에서 고친 것과 같은 부류를, 참조를 넣으면서 새로 만들 뻔했다.\n *\n * 중단은 이미 닫힌다(§`activity-thread/_abort.ts` 가 대기 행을 `aborted` 로 닫는다). 여기서 닫는 것은\n * **정상 종료**다.\n */\n if (activityInstance.state === ActivityInstanceStatus.Ended) {\n await closePendingReferences(id, context)\n }\n\n /* callback에서 업무적인 처리도 하고, activityInstance를 일부(주로 input) 수정할 수 있는 기회도 제공. */\n await ActivityInstallations.callback(activityInstance.activity.name, activityInstance, causedBy, context)\n\n await tx.getRepository(ActivityInstance).save(activityInstance)\n}\n\n/**\n * 이 건의 아직 안 닫힌 참조들을 닫는다 — **판정한 것이 아니라 건이 끝난 것이다.**\n *\n * 의견을 냈는지는 `comment` 가 말한다. 비어 있으면 「통지받았고 말하지 않았다」이고, **그것은 동의가\n * 아니다** — 나중에 결재 이력을 읽는 사람이 침묵을 동의로 읽으면 안 된다.\n *\n * `terminator` 를 적지 않는다. 그 사람이 끝낸 것이 아니라 건이 끝난 것이다.\n */\nasync function closePendingReferences(instanceId: string, context: ResolverContext): Promise<void> {\n const { tx } = context.state\n\n const threads = await tx.getRepository(ActivityThread).find({\n where: { activityInstance: { id: instanceId } }\n })\n if (!threads.length) return\n\n const repo = tx.getRepository(ActivityApproval)\n const open = await repo.find({\n where: threads.map(t => ({\n activityThread: { id: t.id },\n participation: 'reference',\n judgment: ActivityApprovalJudgment.Pending\n }))\n })\n if (!open.length) return\n\n const at = new Date()\n await repo.save(\n open.map(row => ({\n ...row,\n judgment: ActivityApprovalJudgment.Closed,\n transaction: 'close',\n terminatedAt: at\n })) as any\n )\n await closeApprovalNotices(tx, open)\n}\n\nexport async function evalActivityInstanceState(\n id: string,\n context: ResolverContext\n): Promise<Partial<ActivityInstance>> {\n const { tx, user } = context.state\n\n const activityInstance = await tx.getRepository(ActivityInstance).findOne({\n where: { id },\n relations: ['activityThreads', 'activity']\n })\n const { threadsMin, activityThreads, state, dueAt } = activityInstance\n\n const validThreads = activityThreads.filter(thread => thread.isValid())\n const pendingStartedThreads = activityThreads.filter(thread => thread.isPendingStarted())\n const pendingEndedThreads = activityThreads.filter(thread => thread.isPendingEnded())\n\n switch (true) {\n case state === ActivityInstanceStatus.Draft:\n case state === ActivityInstanceStatus.Ended:\n case state === ActivityInstanceStatus.Aborted:\n return {}\n case validThreads.length === 0:\n return {\n state: ActivityInstanceStatus.Issued\n }\n case threadsMin > validThreads.length:\n return {\n state: ActivityInstanceStatus.Unassigned\n }\n case pendingStartedThreads.length > 0:\n return {\n state: ActivityInstanceStatus.Assigned,\n assignedAt: new Date()\n }\n case pendingEndedThreads.length > 0:\n var started = !dueAt || dueAt.getTime() > Date.now()\n var changed =\n (started && state !== ActivityInstanceStatus.Started) || (!started && state !== ActivityInstanceStatus.Pending)\n\n return !changed\n ? null\n : started\n ? {\n state: ActivityInstanceStatus.Started,\n startedAt: new Date(),\n starter: user\n }\n : {\n state: ActivityInstanceStatus.Pending\n }\n default:\n return {\n state: activityThreads.some(thread => thread.state == ActivityThreadStatus.Aborted)\n ? ActivityInstanceStatus.Aborted\n : ActivityInstanceStatus.Ended,\n reason: '',\n output: [MultipleInstanceType.Parallel, MultipleInstanceType.Sequential].includes(\n activityInstance.activity.multiple\n )\n ? activityThreads\n .filter(thread => thread.state === ActivityThreadStatus.Ended)\n .reduce((sum, thread) => {\n sum[thread.assigneeId] = thread.output\n return sum\n }, {} as any)\n : activityThreads[0].output,\n terminatedAt: new Date(),\n terminator: user\n }\n }\n}\n\nexport async function createActivityThreadWithUnassigned(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread> {\n const result = await saveWaitingThread(transaction, activityInstance, context)\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: [result] }, context)\n\n return result\n}\n\n/**\n * Someone of the pool has just taken a thread of this case - by pick, or by claiming the waiting thread. Is\n * the case still short of people (fewer threads someone holds than `threadsMin`)? Then the rest of the pool\n * is left one waiting thread to take; once it has enough, none.\n *\n * The waiting thread is what puts the case on the pool's to-do lists (my-open-threads.ts). Left behind after\n * the case had its people, it kept the case on the list of everyone in the pool; gone while the case still\n * waited, nobody else in the pool saw it any more.\n *\n * `threads` are the case's threads as they stand once the taker holds theirs, read under the hold on the case.\n * The case's state is not worked out here - the taker does that once, after writing its own thread.\n */\nexport async function leaveTheRestOfThePoolOneWaiting(\n transaction: string,\n activityInstance: ActivityInstance,\n threads: ActivityThread[],\n context: ResolverContext\n): Promise<void> {\n const held = threads.filter(thread => thread.isValid()).length\n const waiting = threads.some(thread => thread.state === ActivityThreadStatus.Unassigned)\n\n if (held < activityInstance.threadsMin && !waiting) {\n await saveWaitingThread(transaction, activityInstance, context)\n }\n}\n\nasync function saveWaitingThread(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n return await threadRepo.save({\n version: 1,\n domain,\n state: ActivityThreadStatus.Unassigned,\n activityInstance,\n transaction,\n output: activityInstance.output,\n dueAt: activityInstance.dueAt,\n assignedAt: now,\n creator: user,\n updater: user,\n createdAt: now\n })\n}\n\nexport async function createActivityThreadForUser(\n transaction: string,\n activityInstance: ActivityInstance,\n assignee: User,\n context: ResolverContext\n): Promise<ActivityThread> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n const result = await threadRepo.save({\n version: 1,\n domain,\n assignee,\n state: ActivityThreadStatus.Assigned,\n activityInstance,\n transaction,\n output: activityInstance.output,\n dueAt: activityInstance.dueAt,\n assignedAt: now,\n creator: user,\n updater: user,\n createdAt: now\n })\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: [result] }, context)\n\n return result\n}\n\nexport async function createActivityThreadsForUsers(\n transaction: string,\n activityInstance: ActivityInstance,\n assignees: User[],\n context: ResolverContext\n): Promise<ActivityThread[]> {\n const { domain, user, tx } = context.state\n\n const threadRepo = tx.getRepository(ActivityThread)\n const now = new Date()\n\n const distinct = assignees.filter((assignee, idx) => {\n return assignee && !assignees.slice(0, idx).find(x => x.id == assignee.id)\n })\n\n const result = await threadRepo.save(\n distinct.map(assignee => {\n return {\n version: 1,\n assignee,\n state: ActivityThreadStatus.Assigned,\n activityInstance,\n domain,\n transaction,\n output: activityInstance.output,\n creator: user,\n updater: user,\n dueAt: activityInstance.dueAt,\n assignedAt: now\n } as any\n })\n )\n\n await updateActivityInstanceState(activityInstance.id, { causedBy: result }, context)\n\n return result\n}\n\nexport async function createActivityThreadsForAllRoleUsers(\n transaction: string,\n activityInstance: ActivityInstance,\n context: ResolverContext\n): Promise<ActivityThread[]> {\n const { tx } = context.state\n\n /* Everyone the pool reaches - any one of its roles, each person once (assignee-pool.ts). */\n const poolIds = poolIdsOf(activityInstance)\n const roles = poolIds.length ? await tx.getRepository(Role).find({ where: { id: In(poolIds) }, relations: ['users'] }) : []\n const assignees = poolMembers(roles)\n\n if (assignees.length === 0) {\n throw new Error(context.t('error.no user holds the assignee roles', { roles: roles.map(role => role.name).join(', ') }))\n }\n\n // create activity-thread for all of users having given role\n return await createActivityThreadsForUsers(transaction, activityInstance, assignees, context)\n}\n\nexport async function getSystemUserFromMyDepartmentManager(context: ResolverContext): Promise<User> {\n const { domain, user, tx } = context.state\n\n const employee = await tx.getRepository(Employee).findOneBy({\n domain: { id: domain.id },\n user: { id: user.id }\n })\n\n if (!employee || !employee.departmentId) {\n return\n }\n\n const department = await tx.getRepository(Department).findOne({\n where: {\n id: employee.departmentId\n }\n })\n\n if (!department || !department.managerId) return\n\n const manager = await tx.getRepository(Employee).findOne({\n where: {\n domain: { id: domain.id },\n id: department.managerId\n },\n relations: ['user']\n })\n\n return manager?.user\n}\n\nexport async function getSystemUserFromMySupervosor(context: ResolverContext): Promise<User> {\n const { domain, user, tx } = context.state\n\n const employee = await tx.getRepository(Employee).findOneBy({\n domain: { id: domain.id },\n user: { id: user.id }\n })\n\n if (!employee || !employee.supervisorId) {\n return\n }\n\n const supervisor = await tx.getRepository(Employee).findOne({\n where: {\n id: employee.supervisorId\n },\n relations: ['user']\n })\n\n return supervisor?.user\n}\n\nexport async function getSystemUserFromOrgMemberItem(\n item: AssigneeItem | ApprovalLineItem,\n context: ResolverContext\n): Promise<User> {\n const { domain, user, tx } = context.state\n\n const { type, approver, assignee, value } = item as AssigneeItem & ApprovalLineItem\n const id = approver?.id || assignee?.id || value\n\n if (type == OrgMemberTargetType.Employee) {\n /* This domain's only - an id from another tenant made that tenant's person an approver here. */\n const employee =\n id && (await tx.getRepository(Employee).findOne({ where: { domain: { id: domain.id }, id }, relations: ['user'] }))\n\n if (!employee || !employee.user) {\n return\n }\n return employee.user\n } else if (type == OrgMemberTargetType.Department) {\n const department =\n id && (await tx.getRepository(Department).findOne({ where: { domain: { id: domain.id }, id }, relations: ['manager'] }))\n\n if (!department || !department.manager) {\n return\n }\n return await tx.getRepository(User).findOneBy({ id: department.manager.userId })\n } else if (type == OrgMemberTargetType.Role) {\n /*\n * A role is not one person. This answered the role's first user - an unordered relation, so an\n * arbitrary one - and issue() gave that person work meant for the whole role. Each caller decides\n * what a role means there before asking this: the approval line seats the role (create-approval.ts),\n * assignees refuse it (assignee-input.ts). Reaching here is a caller that skipped that step.\n */\n throw Object.assign(new Error(context.t('error.activity-instance a role is not an assignee')), {\n code: ROLE_IS_NOT_AN_ASSIGNEE\n })\n } else if (type == OrgMemberTargetType.Myself) {\n return user\n } else if (type == OrgMemberTargetType.MyDepartment) {\n return await getSystemUserFromMyDepartmentManager(context)\n } else if (type == OrgMemberTargetType.MySupervisor) {\n return await getSystemUserFromMySupervosor(context)\n }\n}\n\nexport function fillActivitySearchKeys(searchKeys: ActivitySearchKeyItem[], input: { [key: string]: any }) {\n if (!input || typeof input !== 'object') {\n return\n }\n\n return searchKeys?.reduce((sum, key, index) => {\n const value = input[key.inputKey]\n if (value != null) {\n sum[`key0${index + 1}`] = value instanceof Array ? value[0] : value\n }\n return sum\n }, {})\n}\n"]}
|
package/dist-server/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export * from './controllers/index.js';
|
|
|
3
3
|
export * from './service/index.js';
|
|
4
4
|
export { freezeDecisionSentences, DecisionSentenceMissing } from '../shared/decision-sentences.js';
|
|
5
5
|
export { freezeDecisionSentencesFor } from './service/activity/freeze-decision-sentences-for.js';
|
|
6
|
+
export { assertFinishedCaseShows, finishedCaseShowsNothing, outputFieldsOf } from './service/activity/finished-case.js';
|
|
6
7
|
export type { DecisionSentenceKey, Translate as DecisionSentenceTranslate } from '../shared/decision-sentences.js';
|
package/dist-server/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.freezeDecisionSentencesFor = exports.DecisionSentenceMissing = exports.freezeDecisionSentences = void 0;
|
|
3
|
+
exports.outputFieldsOf = exports.finishedCaseShowsNothing = exports.assertFinishedCaseShows = exports.freezeDecisionSentencesFor = exports.DecisionSentenceMissing = exports.freezeDecisionSentences = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
require("./routes.js");
|
|
6
6
|
tslib_1.__exportStar(require("./controllers/index.js"), exports);
|
|
@@ -11,6 +11,10 @@ Object.defineProperty(exports, "freezeDecisionSentences", { enumerable: true, ge
|
|
|
11
11
|
Object.defineProperty(exports, "DecisionSentenceMissing", { enumerable: true, get: function () { return decision_sentences_js_1.DecisionSentenceMissing; } });
|
|
12
12
|
var freeze_decision_sentences_for_js_1 = require("./service/activity/freeze-decision-sentences-for.js");
|
|
13
13
|
Object.defineProperty(exports, "freezeDecisionSentencesFor", { enumerable: true, get: function () { return freeze_decision_sentences_for_js_1.freezeDecisionSentencesFor; } });
|
|
14
|
+
var finished_case_js_1 = require("./service/activity/finished-case.js");
|
|
15
|
+
Object.defineProperty(exports, "assertFinishedCaseShows", { enumerable: true, get: function () { return finished_case_js_1.assertFinishedCaseShows; } });
|
|
16
|
+
Object.defineProperty(exports, "finishedCaseShowsNothing", { enumerable: true, get: function () { return finished_case_js_1.finishedCaseShowsNothing; } });
|
|
17
|
+
Object.defineProperty(exports, "outputFieldsOf", { enumerable: true, get: function () { return finished_case_js_1.outputFieldsOf; } });
|
|
14
18
|
const auth_base_1 = require("@things-factory/auth-base");
|
|
15
19
|
const role_tasks_js_1 = require("./role-tasks.js");
|
|
16
20
|
for (const task of role_tasks_js_1.ROLE_TASKS)
|
package/dist-server/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;AAAA,uBAAoB;AAEpB,iEAAsC;AACtC,6DAAkC;AAElC,sGAAsG;AACtG,yEAAkG;AAAzF,gIAAA,uBAAuB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AACzD,wGAAgG;AAAvF,8IAAA,0BAA0B,OAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../server/index.ts"],"names":[],"mappings":";;;;AAAA,uBAAoB;AAEpB,iEAAsC;AACtC,6DAAkC;AAElC,sGAAsG;AACtG,yEAAkG;AAAzF,gIAAA,uBAAuB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AACzD,wGAAgG;AAAvF,8IAAA,0BAA0B,OAAA;AACnC,wEAAuH;AAA9G,2HAAA,uBAAuB,OAAA;AAAE,4HAAA,wBAAwB,OAAA;AAAE,kHAAA,cAAc,OAAA;AAG1E,yDAA4D;AAC5D,mDAA4C;AAE5C,KAAK,MAAM,IAAI,IAAI,0BAAU;IAAE,IAAA,4BAAgB,EAAC,IAAI,CAAC,CAAA","sourcesContent":["import './routes.js'\n\nexport * from './controllers/index.js'\nexport * from './service/index.js'\n\n/* Freezing an approval's value sentences — the same reading of the input the decision screen uses. */\nexport { freezeDecisionSentences, DecisionSentenceMissing } from '../shared/decision-sentences.js'\nexport { freezeDecisionSentencesFor } from './service/activity/freeze-decision-sentences-for.js'\nexport { assertFinishedCaseShows, finishedCaseShowsNothing, outputFieldsOf } from './service/activity/finished-case.js'\nexport type { DecisionSentenceKey, Translate as DecisionSentenceTranslate } from '../shared/decision-sentences.js'\n\nimport { registerRoleTask } from '@things-factory/auth-base'\nimport { ROLE_TASKS } from './role-tasks.js'\n\nfor (const task of ROLE_TASKS) registerRoleTask(task)\n"]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether a finished case of an activity shows anything - what was asked and what was done.
|
|
3
|
+
*
|
|
4
|
+
* The finished screen (activity-thread-view) draws, in order: the activity's own view when it names one (viewType with a
|
|
5
|
+
* viewSource), else the declared decision over the input (decisionKeys), the input fields a person can read, and the
|
|
6
|
+
* output fields what was done was written into. A module's own to-do that kept only a hidden key in its input (an
|
|
7
|
+
* inquiry id, a week), declared no decision and no output, and named no view, finished as an empty screen: the state, the
|
|
8
|
+
* times and nothing of what it was or how it ended (2026-11-11, 문의 할 일 and five more like it).
|
|
9
|
+
*
|
|
10
|
+
* Kept free of imports so the test runner can hold it.
|
|
11
|
+
*/
|
|
12
|
+
type Declared = {
|
|
13
|
+
name?: string;
|
|
14
|
+
viewType?: string;
|
|
15
|
+
viewSource?: string;
|
|
16
|
+
decisionKeys?: unknown[];
|
|
17
|
+
model?: {
|
|
18
|
+
hidden?: boolean;
|
|
19
|
+
inout?: string;
|
|
20
|
+
}[];
|
|
21
|
+
};
|
|
22
|
+
/** Why a finished case of this activity would show nothing - undefined when it shows something. */
|
|
23
|
+
export declare function finishedCaseShowsNothing(activity: Declared): string | undefined;
|
|
24
|
+
/** For a module's own test: its activities' finished cases show what was asked and what was done. */
|
|
25
|
+
export declare function assertFinishedCaseShows(activity: Declared): void;
|
|
26
|
+
/** The output fields an activity declares - where `complete` writes what was done. */
|
|
27
|
+
export declare function outputFieldsOf(activity: Declared): string[];
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a finished case of an activity shows anything - what was asked and what was done.
|
|
4
|
+
*
|
|
5
|
+
* The finished screen (activity-thread-view) draws, in order: the activity's own view when it names one (viewType with a
|
|
6
|
+
* viewSource), else the declared decision over the input (decisionKeys), the input fields a person can read, and the
|
|
7
|
+
* output fields what was done was written into. A module's own to-do that kept only a hidden key in its input (an
|
|
8
|
+
* inquiry id, a week), declared no decision and no output, and named no view, finished as an empty screen: the state, the
|
|
9
|
+
* times and nothing of what it was or how it ended (2026-11-11, 문의 할 일 and five more like it).
|
|
10
|
+
*
|
|
11
|
+
* Kept free of imports so the test runner can hold it.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.finishedCaseShowsNothing = finishedCaseShowsNothing;
|
|
15
|
+
exports.assertFinishedCaseShows = assertFinishedCaseShows;
|
|
16
|
+
exports.outputFieldsOf = outputFieldsOf;
|
|
17
|
+
const MODULE_VIEWS = ['custom-element', 'template', 'board', 'page', 'external'];
|
|
18
|
+
/** Why a finished case of this activity would show nothing - undefined when it shows something. */
|
|
19
|
+
function finishedCaseShowsNothing(activity) {
|
|
20
|
+
if (activity.viewType && MODULE_VIEWS.includes(activity.viewType) && activity.viewSource)
|
|
21
|
+
return undefined;
|
|
22
|
+
if ((activity.decisionKeys ?? []).length)
|
|
23
|
+
return undefined;
|
|
24
|
+
if ((activity.model ?? []).some(field => !field.hidden && ['in', 'out', 'inout'].includes(String(field.inout))))
|
|
25
|
+
return undefined;
|
|
26
|
+
return `"${activity.name}" finishes as an empty screen: it names no view, declares no decision, and has no visible input or output field`;
|
|
27
|
+
}
|
|
28
|
+
/** For a module's own test: its activities' finished cases show what was asked and what was done. */
|
|
29
|
+
function assertFinishedCaseShows(activity) {
|
|
30
|
+
const empty = finishedCaseShowsNothing(activity);
|
|
31
|
+
if (empty)
|
|
32
|
+
throw new Error(empty);
|
|
33
|
+
}
|
|
34
|
+
/** The output fields an activity declares - where `complete` writes what was done. */
|
|
35
|
+
function outputFieldsOf(activity) {
|
|
36
|
+
return (activity.model ?? []).filter(field => ['out', 'inout'].includes(String(field.inout))).map(field => field.name);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=finished-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finished-case.js","sourceRoot":"","sources":["../../../server/service/activity/finished-case.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAaH,4DAMC;AAGD,0DAGC;AAGD,wCAEC;AA5BD,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,CAAA;AAUhF,mGAAmG;AACnG,SAAgB,wBAAwB,CAAC,QAAkB;IACzD,IAAI,QAAQ,CAAC,QAAQ,IAAI,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,UAAU;QAAE,OAAO,SAAS,CAAA;IAC1G,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM;QAAE,OAAO,SAAS,CAAA;IAC1D,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,SAAS,CAAA;IAEjI,OAAO,IAAI,QAAQ,CAAC,IAAI,iHAAiH,CAAA;AAC3I,CAAC;AAED,qGAAqG;AACrG,SAAgB,uBAAuB,CAAC,QAAkB;IACxD,MAAM,KAAK,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAA;IAChD,IAAI,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAA;AACnC,CAAC;AAED,sFAAsF;AACtF,SAAgB,cAAc,CAAC,QAAkB;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAE,KAAa,CAAC,IAAI,CAAC,CAAA;AACjI,CAAC","sourcesContent":["/**\n * Whether a finished case of an activity shows anything - what was asked and what was done.\n *\n * The finished screen (activity-thread-view) draws, in order: the activity's own view when it names one (viewType with a\n * viewSource), else the declared decision over the input (decisionKeys), the input fields a person can read, and the\n * output fields what was done was written into. A module's own to-do that kept only a hidden key in its input (an\n * inquiry id, a week), declared no decision and no output, and named no view, finished as an empty screen: the state, the\n * times and nothing of what it was or how it ended (2026-11-11, 문의 할 일 and five more like it).\n *\n * Kept free of imports so the test runner can hold it.\n */\n\nconst MODULE_VIEWS = ['custom-element', 'template', 'board', 'page', 'external']\n\ntype Declared = {\n name?: string\n viewType?: string\n viewSource?: string\n decisionKeys?: unknown[]\n model?: { hidden?: boolean; inout?: string }[]\n}\n\n/** Why a finished case of this activity would show nothing - undefined when it shows something. */\nexport function finishedCaseShowsNothing(activity: Declared): string | undefined {\n if (activity.viewType && MODULE_VIEWS.includes(activity.viewType) && activity.viewSource) return undefined\n if ((activity.decisionKeys ?? []).length) return undefined\n if ((activity.model ?? []).some(field => !field.hidden && ['in', 'out', 'inout'].includes(String(field.inout)))) return undefined\n\n return `\"${activity.name}\" finishes as an empty screen: it names no view, declares no decision, and has no visible input or output field`\n}\n\n/** For a module's own test: its activities' finished cases show what was asked and what was done. */\nexport function assertFinishedCaseShows(activity: Declared): void {\n const empty = finishedCaseShowsNothing(activity)\n if (empty) throw new Error(empty)\n}\n\n/** The output fields an activity declares - where `complete` writes what was done. */\nexport function outputFieldsOf(activity: Declared): string[] {\n return (activity.model ?? []).filter(field => ['out', 'inout'].includes(String(field.inout))).map(field => (field as any).name)\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EntityManager } from 'typeorm';
|
|
1
2
|
import { type ApprovalNoticeKind } from './approval-notice-rules.js';
|
|
2
3
|
/**
|
|
3
4
|
* Tells of what just happened to approval `approvalId`, once the transaction has committed.
|
|
@@ -9,3 +10,14 @@ export declare function noticeApproval(context: ResolverContext, { kind, approva
|
|
|
9
10
|
kind: ApprovalNoticeKind;
|
|
10
11
|
approvalId: string;
|
|
11
12
|
}): Promise<void>;
|
|
13
|
+
/** What a turn notice tells of - the approval row whose turn it is. */
|
|
14
|
+
export declare const approvalNoticeKey: (approvalId: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Closes the turn notices of approval rows that are no longer waiting - judged, handed on, withdrawn or closed with
|
|
17
|
+
* their case (ADR-0164 amendment 1): everyone the turn was told to, a role's holders too, reads it as read and no screen
|
|
18
|
+
* shows it. In the transaction that moved the rows, so a refused move closes nothing.
|
|
19
|
+
*/
|
|
20
|
+
export declare function closeApprovalNotices(tx: EntityManager, rows: readonly {
|
|
21
|
+
id: string;
|
|
22
|
+
domainId?: string;
|
|
23
|
+
}[]): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.approvalNoticeKey = void 0;
|
|
3
4
|
exports.noticeApproval = noticeApproval;
|
|
5
|
+
exports.closeApprovalNotices = closeApprovalNotices;
|
|
4
6
|
/*
|
|
5
7
|
* The approval notice (ADR-0164) - the one place the worklist tells people of an approval's turn and judgment.
|
|
6
8
|
*
|
|
@@ -57,6 +59,8 @@ async function noticeApproval(context, { kind, approvalId }) {
|
|
|
57
59
|
words: lng => (0, approval_notice_rules_js_1.noticeWords)(translatorOf(lng), facts),
|
|
58
60
|
address,
|
|
59
61
|
link: (0, notification_1.noticeLinkOf)(context, address),
|
|
62
|
+
/* a turn is closed once its row is judged (`closeApprovalNotices`); a judgment told is read by its person */
|
|
63
|
+
key: (0, approval_notice_rules_js_1.isTurnNotice)(kind) ? (0, exports.approvalNoticeKey)(approval.id) : `approval-thread:${thread.id}`,
|
|
60
64
|
label: `approval notice ${kind} of ${approval.id}`
|
|
61
65
|
}, result => (0, notification_1.keepNoticeDelivery)(activity_approval_js_1.ActivityApproval, approval.id, 'notices', (0, notification_1.noticeDeliveryOf)(kind, result, receivers.length)));
|
|
62
66
|
}
|
|
@@ -64,6 +68,21 @@ async function noticeApproval(context, { kind, approvalId }) {
|
|
|
64
68
|
env_1.logger.error(`[worklist] approval notice ${kind} of ${approvalId} could not be made`, error);
|
|
65
69
|
}
|
|
66
70
|
}
|
|
71
|
+
/** What a turn notice tells of - the approval row whose turn it is. */
|
|
72
|
+
const approvalNoticeKey = (approvalId) => `approval:${approvalId}`;
|
|
73
|
+
exports.approvalNoticeKey = approvalNoticeKey;
|
|
74
|
+
/**
|
|
75
|
+
* Closes the turn notices of approval rows that are no longer waiting - judged, handed on, withdrawn or closed with
|
|
76
|
+
* their case (ADR-0164 amendment 1): everyone the turn was told to, a role's holders too, reads it as read and no screen
|
|
77
|
+
* shows it. In the transaction that moved the rows, so a refused move closes nothing.
|
|
78
|
+
*/
|
|
79
|
+
async function closeApprovalNotices(tx, rows) {
|
|
80
|
+
for (const row of rows) {
|
|
81
|
+
if (!row.domainId)
|
|
82
|
+
continue;
|
|
83
|
+
await (0, notification_1.closeNotices)(tx, { id: row.domainId }, 'approval', (0, exports.approvalNoticeKey)(row.id));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
67
86
|
/** Only a person who can sign in is told. */
|
|
68
87
|
function active(person) {
|
|
69
88
|
return person && person.status === auth_base_1.UserStatus.ACTIVATED ? { id: person.id, name: person.name, email: person.email, locale: person.locale } : null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approval-notice.js","sourceRoot":"","sources":["../../../server/service/approval-notice/approval-notice.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approval-notice.js","sourceRoot":"","sources":["../../../server/service/approval-notice/approval-notice.ts"],"names":[],"mappings":";;;AAkCA,wCA4CC;AAUD,oDAKC;AA7FD;;;;;;;GAOG;AACH,yDAA4D;AAC5D,6CAA4C;AAC5C,qEAAoE;AACpE,+DAAwI;AAGxI,oFAA4E;AAC5E,4EAAmE;AACnE,yEAUmC;AAEnC;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,OAAwB,EAAE,EAAE,IAAI,EAAE,UAAU,EAAoD;IACnI,IAAI,CAAC;QACH,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QAElC,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,uCAAgB,CAAC,CAAC,OAAO,CAAC;YAChE,KAAK,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE;YACzB,SAAS,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,iCAAiC,CAAC;SAC9I,CAAC,CAAA;QACF,MAAM,MAAM,GAAG,QAAQ,EAAE,cAAc,CAAA;QACvC,MAAM,QAAQ,GAAG,MAAM,EAAE,gBAAgB,CAAA;QACzC,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ;YAAE,OAAM;QAE7C,MAAM,SAAS,GAAG,IAAA,0CAAe,EAAC;YAChC,IAAI;YACJ,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAA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,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACnJ,CAAC;AAED,wFAAwF;AACxF,SAAS,YAAY,CAAC,GAAW;IAC/B,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,GAAG,CAAC,CAAA;IAC9B,MAAM,OAAO,GAAG,IAAA,0BAAa,EAAC,IAAI,CAAC,CAAA;IACnC,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAA;AAC7F,CAAC","sourcesContent":["/*\n * The approval notice (ADR-0164) - the one place the worklist tells people of an approval's turn and judgment.\n *\n * The four places an approval moves call `noticeApproval`: createApproval (a turn or a reference), delegate (a\n * handed seat), approve with no one after (approved) and reject (rejected). Applications call nothing; a case that\n * goes through the approval line is told of. Sending is notification's (`sendNoticeWhenCommitted`); what it sent is kept\n * on the approval row (`notices`).\n */\nimport { User, UserStatus } from '@things-factory/auth-base'\nimport { logger } from '@things-factory/env'\nimport { translatorFor } from '@things-factory/i18n-base/translator'\nimport { closeNotices, keepNoticeDelivery, noticeDeliveryOf, noticeLinkOf, sendNoticeWhenCommitted } from '@things-factory/notification'\nimport type { EntityManager } from 'typeorm'\n\nimport { ActivityApproval } from '../activity-approval/activity-approval.js'\nimport { poolMembers } from '../activity-instance/assignee-pool.js'\nimport {\n approvalStep,\n isTurnNotice,\n noticeAddress,\n noticeReceivers,\n noticeWords,\n type ApprovalNoticeKind,\n type NoticeFacts,\n type NoticePerson,\n type Translate\n} from './approval-notice-rules.js'\n\n/**\n * Tells of what just happened to approval `approvalId`, once the transaction has committed.\n *\n * Who and what are settled here, inside the transaction, from rows it can see. Nothing here throws: a notice that\n * cannot be made is reported and the approval stands.\n */\nexport async function noticeApproval(context: ResolverContext, { kind, approvalId }: { kind: ApprovalNoticeKind; approvalId: string }): Promise<void> {\n try {\n const { user, tx } = context.state\n\n const approval = await tx.getRepository(ActivityApproval).findOne({\n where: { id: approvalId },\n relations: ['approver', 'approverRole', 'approverRole.users', 'activityThread', 'activityThread.assignee', 'activityThread.activityInstance']\n })\n const thread = approval?.activityThread\n const instance = thread?.activityInstance\n if (!approval || !thread || !instance) return\n\n const receivers = noticeReceivers({\n kind,\n approver: active(approval.approver),\n roleHolders: poolMembers(approval.approverRole ? [approval.approverRole] : []).map(active).filter(Boolean),\n requester: active(thread.assignee),\n actorId: user?.id\n })\n if (!receivers.length) return\n\n const facts: NoticeFacts = {\n kind,\n name: instance.name || '',\n requester: thread.assignee?.name,\n actor: user?.name,\n ...(isTurnNotice(kind) ? approvalStep(instance.approvalLine, approval.order) : {})\n }\n const address = noticeAddress(kind, { approvalId: approval.id, threadId: thread.id })\n\n sendNoticeWhenCommitted(context, {\n type: 'approval',\n level: kind === 'rejected' ? 'warn' : 'info',\n receivers,\n words: lng => noticeWords(translatorOf(lng), facts),\n address,\n link: noticeLinkOf(context, address),\n /* a turn is closed once its row is judged (`closeApprovalNotices`); a judgment told is read by its person */\n key: isTurnNotice(kind) ? approvalNoticeKey(approval.id) : `approval-thread:${thread.id}`,\n label: `approval notice ${kind} of ${approval.id}`\n }, result => keepNoticeDelivery(ActivityApproval, approval.id, 'notices', noticeDeliveryOf(kind, result, receivers.length)))\n } catch (error) {\n logger.error(`[worklist] approval notice ${kind} of ${approvalId} could not be made`, error)\n }\n}\n\n/** What a turn notice tells of - the approval row whose turn it is. */\nexport const approvalNoticeKey = (approvalId: string) => `approval:${approvalId}`\n\n/**\n * Closes the turn notices of approval rows that are no longer waiting - judged, handed on, withdrawn or closed with\n * their case (ADR-0164 amendment 1): everyone the turn was told to, a role's holders too, reads it as read and no screen\n * shows it. In the transaction that moved the rows, so a refused move closes nothing.\n */\nexport async function closeApprovalNotices(tx: EntityManager, rows: readonly { id: string; domainId?: string }[]): Promise<void> {\n for (const row of rows) {\n if (!row.domainId) continue\n await closeNotices(tx, { id: row.domainId }, 'approval', approvalNoticeKey(row.id))\n }\n}\n\n/** Only a person who can sign in is told. */\nfunction active(person?: User | null): NoticePerson | null {\n return person && person.status === UserStatus.ACTIVATED ? { id: person.id, name: person.name, email: person.email, locale: person.locale } : null\n}\n\n/** A sentence missing in the person's language is said in English, never as its key. */\nfunction translatorOf(lng: string): Translate {\n const own = translatorFor(lng)\n const english = translatorFor('en')\n return (key, options = {}) => own(key, { ...options, defaultValue: english(key, options) })\n}\n"]}
|