feat: 508971へ自分手配Process用の反映スクリプトを追加
This commit is contained in:
parent
3e51710d9f
commit
db25941158
@ -0,0 +1,72 @@
|
||||
// 健康診断管理 SiteId 508971: 手動登録済みProcess「自分手配」(Id:18)に対し、
|
||||
// Class003(検査機関)を「自分手配」(511924 ResultId 513480)にセットするDataChangesを追記する。
|
||||
// OnClickが存在すれば中断する安全策付き(既存の同種スクリプトと同じパターン)。
|
||||
"use strict";
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { findSiteDir, newModifyDir } = require("../../site-paths.js");
|
||||
|
||||
const PROJECT_NAME = "健康診断管理";
|
||||
const ENV = "production";
|
||||
const SITE_ID = 508971;
|
||||
const REQUEST_LABEL = "add-process-jibunanpai";
|
||||
const PROCESS_NAME = "自分手配";
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, "..", "..", "..", "..");
|
||||
const PROJECT_ROOT = path.join(REPO_ROOT, PROJECT_NAME);
|
||||
const CONFIGS_DIR = path.join(PROJECT_ROOT, "configs", ENV);
|
||||
|
||||
function loadServerConfig() {
|
||||
return JSON.parse(fs.readFileSync(path.join(REPO_ROOT, `config_${ENV}.json`), "utf-8"));
|
||||
}
|
||||
function loadLatest() {
|
||||
const siteDir = findSiteDir(CONFIGS_DIR, SITE_ID);
|
||||
const p = path.join(siteDir, "sitesettings", `site-${SITE_ID}_latest.json`);
|
||||
const raw = JSON.parse(fs.readFileSync(p, "utf-8"));
|
||||
return { current: raw.Response.Data, siteDir, rawText: fs.readFileSync(p, "utf-8") };
|
||||
}
|
||||
|
||||
const execute = process.argv.includes("--execute");
|
||||
const server = loadServerConfig();
|
||||
|
||||
(async () => {
|
||||
const { current, siteDir, rawText } = loadLatest();
|
||||
const settings = JSON.parse(JSON.stringify(current.SiteSettings));
|
||||
settings.Links = current.SiteSettings.Links || [];
|
||||
|
||||
const proc = settings.Processes.find((p) => p.Name === PROCESS_NAME);
|
||||
if (!proc) {
|
||||
console.error(`[エラー] Process「${PROCESS_NAME}」が見つかりません。先にPleasanter画面で手動登録してください。`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (proc.OnClick !== undefined) {
|
||||
console.error(`[エラー] Process「${PROCESS_NAME}」(Id:${proc.Id})にOnClickフィールドが存在します。中断します。`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (proc.CurrentStatus !== 250 || proc.ChangedStatus !== 400) {
|
||||
console.error(`[エラー] Status遷移が想定外です(CurrentStatus:${proc.CurrentStatus}, ChangedStatus:${proc.ChangedStatus})。250→400になっているか確認してください。`);
|
||||
process.exit(1);
|
||||
}
|
||||
proc.DataChanges = [
|
||||
{ Id: 1, Type: "InputValue", ColumnName: "Class003", Value: "513480", ValueFormulaNotUseDisplayName: false, ValueFormulaIsDisplayError: false },
|
||||
];
|
||||
|
||||
const body = {
|
||||
ApiVersion: 1.1, ApiKey: server.ApiKey, SiteId: SITE_ID,
|
||||
Title: current.Title, ReferenceType: current.ReferenceType,
|
||||
ParentId: current.ParentId, InheritPermission: current.InheritPermission,
|
||||
SiteSettings: settings,
|
||||
};
|
||||
|
||||
const modifyDir = newModifyDir(siteDir, REQUEST_LABEL);
|
||||
fs.writeFileSync(path.join(modifyDir, `before_site-${SITE_ID}_latest.json`), rawText, "utf-8");
|
||||
console.log(`Process「${PROCESS_NAME}」(Id:${proc.Id}) に Class003=513480(自分手配) のDataChangesを追加します。`);
|
||||
|
||||
if (!execute) {
|
||||
console.log("(--execute 未指定のためプレビューのみ)");
|
||||
return;
|
||||
}
|
||||
const url = `${server.BaseUrl}api/items/${SITE_ID}/updatesite`;
|
||||
const res = await fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body) });
|
||||
console.log(`[結果] HTTP ${res.status}:`, JSON.stringify(await res.json()));
|
||||
})();
|
||||
Loading…
Reference in New Issue
Block a user