From aec9655fdc764ef98a6b88fafe242f4ad4561baa Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Fri, 1 Dec 2023 18:57:33 +0900 Subject: [PATCH] =?UTF-8?q?=E9=81=B8=E8=80=83=E3=82=A2=E3=83=97=E3=83=AA?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/定期予約選考/index.ts | 56 +++++++++++++++++++++++++++- src/mypage/index.ts | 2 + src/mypage/lib.ts | 13 +++++-- src/mypage/定期予約選考.ts | 6 +++ src/types/定期予約選考.ts | 9 +++-- 5 files changed, 78 insertions(+), 8 deletions(-) diff --git a/src/apps/定期予約選考/index.ts b/src/apps/定期予約選考/index.ts index fba603e..05e9de5 100644 --- a/src/apps/定期予約選考/index.ts +++ b/src/apps/定期予約選考/index.ts @@ -1,7 +1,7 @@ import { AppID } from "@/common/appids"; import { setHeaderButton } from "@/common/header-button"; import { makeRecordData } from "@/common/rest-api-client"; -import { noticeToCandidates } from "@/mypage/定期予約選考"; +import { fillCandidates, noticeToCandidates } from "@/mypage/定期予約選考"; import { 定期予約選考, 定期予約選考フィールド名, @@ -10,6 +10,46 @@ import { import { 定期申込予約フィールド名, 状態Dropdown } from "@/types/定期申込予約"; import { KintoneRestAPIClient } from "@kintone/rest-api-client"; +// 検索用文字列をセットする +const setSearchCondition = (currentRecord: 定期予約選考) => { + const candidates = currentRecord.申込者一覧.value + .filter((row) => !!row.value.申込者一覧_申込レコード番号.value) + .map((row) => { + return "c" + row.value.申込者一覧_申込レコード番号.value + "c"; + }); + const entries = currentRecord.契約希望者一覧.value + .filter((row) => !!row.value.契約希望者一覧_申込レコード番号.value) + .map((row) => { + return "e" + row.value.契約希望者一覧_申込レコード番号.value + "e"; + }); + const results = currentRecord.選考結果一覧.value + .filter((row) => !!row.value.選考結果一覧_申込番号.value) + .map((row) => { + return "r" + row.value.選考結果一覧_申込レコード番号.value + "r"; + }); + + currentRecord.検索用_申込一覧_レコード番号.value = candidates.join(","); + currentRecord.検索用_契約希望者_レコード番号.value = entries.join(","); + currentRecord.検索用_選考結果_レコード番号.value = results.join(","); +}; + +const getCallBackHandleFillcandidates = (currentRecord: 定期予約選考) => { + return async () => { + const confirm = window.confirm("候補者を設定しますか?"); + if (!confirm || !currentRecord) return; + + const result = await fillCandidates( + Number(currentRecord.レコード番号.value) + ); + if (result) { + window.alert("設定しました"); + location.reload(); + } else { + window.alert("失敗しました"); + } + }; +}; + const getCallBackHandleNoticeTocandidates = (currentRecord: 定期予約選考) => { return async () => { const confirm = window.confirm("対象者へメール送信しますか?"); @@ -33,7 +73,6 @@ const getCallBackHandleFinish = (currentRecord: 定期予約選考) => { if (!confirm || !currentRecord) return; const client = new KintoneRestAPIClient(); - // 選考のステータスを終了にする const param = { app: AppID.定期予約選考, @@ -80,6 +119,12 @@ const getCallBackHandleFinish = (currentRecord: 定期予約選考) => { const currentRecord: 定期予約選考 = event.record; // 各種ボタンの設置 + if (currentRecord.選考ステータス.value === 選考ステータスDropdown.起票) { + setHeaderButton( + "候補者設定", + getCallBackHandleFillcandidates(currentRecord) + ); + } if ( currentRecord.選考ステータス.value === 選考ステータスDropdown.通知者選択中 ) { @@ -94,4 +139,11 @@ const getCallBackHandleFinish = (currentRecord: 定期予約選考) => { setHeaderButton("当選者確定", getCallBackHandleFinish(currentRecord)); } }); + + kintone.events.on("app.record.edit.submit", (event) => { + const currentRecord: 定期予約選考 = event.record; + setSearchCondition(currentRecord); + + return event; + }); })(); diff --git a/src/mypage/index.ts b/src/mypage/index.ts index ec66e8c..2cba3a3 100644 --- a/src/mypage/index.ts +++ b/src/mypage/index.ts @@ -1,5 +1,7 @@ export const MyPageApiID = { メール送信依頼: "email/send", + 定期選考候補者設定: "season-ticket-contract-selection/fill-candidates", 定期選考一斉通知: "season-ticket-contract-selection/notice-to-candidates", + 領収証発行: "receipt/create", } as const; export type MyPageApiID = (typeof MyPageApiID)[keyof typeof MyPageApiID]; diff --git a/src/mypage/lib.ts b/src/mypage/lib.ts index 08de796..2280c33 100644 --- a/src/mypage/lib.ts +++ b/src/mypage/lib.ts @@ -18,17 +18,24 @@ export const send = async (apiId: MyPageApiID, data: object) => { }; console.info("MyPageAPICall", url, data); - const res: MyPageApiResponse = await kintone.proxy( + const res: any = await kintone.proxy( url, "POST", { "Content-Type": "application/json" }, sendData ); - if (res?.result === "SUCCESS") { + const status = res[1]; + if (status !== 200) { + console.error("http status not 200", res); + return false; + } + const obj = JSON.parse(res[0]); + + if (obj.result === "SUCCESS") { return true; } else { - console.error(res); + console.error("処理失敗", res); return false; } }; diff --git a/src/mypage/定期予約選考.ts b/src/mypage/定期予約選考.ts index 117622b..b1dd146 100644 --- a/src/mypage/定期予約選考.ts +++ b/src/mypage/定期予約選考.ts @@ -1,6 +1,12 @@ import { MyPageApiID } from "."; import { send } from "./lib"; +export const fillCandidates = (recordNo: number) => { + const sendData = { + record_no: recordNo, + }; + return send(MyPageApiID.定期選考候補者設定, sendData); +}; export const noticeToCandidates = (recordNo: number) => { const sendData = { record_no: recordNo, diff --git a/src/types/定期予約選考.ts b/src/types/定期予約選考.ts index 72488c6..15c3447 100644 --- a/src/types/定期予約選考.ts +++ b/src/types/定期予約選考.ts @@ -3,6 +3,9 @@ import { AppRecord } from "."; const F = { 選考ステータス: "選考ステータス", + 検索用_申込一覧_レコード番号: "検索用_申込一覧_レコード番号", + 検索用_契約希望者_レコード番号: "検索用_契約希望者_レコード番号", + 検索用_選考結果_レコード番号: "検索用_選考結果_レコード番号", } as const; export const 選考ステータスDropdown = { @@ -19,13 +22,13 @@ export type 選考ステータスDropdown = export const 定期予約選考フィールド名 = F; export type 定期予約選考 = AppRecord & { 利用開始日: KintoneRecordField.Date; - 検索用_契約希望者_レコード番号: KintoneRecordField.SingleLineText; + [F.検索用_契約希望者_レコード番号]: KintoneRecordField.SingleLineText; 自動選考メッセージ: KintoneRecordField.MultiLineText; [F.選考ステータス]: KintoneRecordField.Dropdown; 選考締切日: KintoneRecordField.Date; - 検索用_申込一覧_レコード番号: KintoneRecordField.SingleLineText; + [F.検索用_申込一覧_レコード番号]: KintoneRecordField.SingleLineText; 駐車場名: KintoneRecordField.SingleLineText; - 検索用_選考結果_レコード番号: KintoneRecordField.SingleLineText; + [F.検索用_選考結果_レコード番号]: KintoneRecordField.SingleLineText; 申込者一覧: KintoneRecordField.Subtable<{ 申込者一覧_申込レコード番号: KintoneRecordField.Number; 申込者一覧_メールアドレス: KintoneRecordField.SingleLineText;