diff --git a/src/apps/入金予定結果/index.tsx b/src/apps/入金予定結果/index.tsx index 0def89b..e0f39c9 100644 --- a/src/apps/入金予定結果/index.tsx +++ b/src/apps/入金予定結果/index.tsx @@ -6,7 +6,7 @@ import { makeRecordData } from "@/common/rest-api-client"; import { Message } from "@/exception"; import { EmailID, sendEmail } from "@/mypage/メール"; import { makeReceipt } from "@/mypage/領収証発行"; -import { BulkRequest } from "@/rest-api/bulk"; +import bulkRequest from "@/rest-api/bulk"; import { get定期申込予約 } from "@/rest-api/定期申込予約"; import { 入金予定結果, 入金予定結果フィールド名 } from "@/types/入金予定結果"; import { 定期申込予約フィールド名 } from "@/types/定期申込予約"; @@ -135,8 +135,7 @@ const setData = (event: any, targets: string[]) => { return String(month); })(); - const request = new BulkRequest(); - request.update({ + bulkRequest.update({ app: AppID.定期申込予約, id: record.first_payment_entry_record_no.value, record: makeRecordData({ @@ -148,7 +147,7 @@ const setData = (event: any, targets: string[]) => { [F.日割り分_月]: 日割り月, }), }); - await request.save(); + await bulkRequest.save(); }; kintone.events.on(KintoneEvent.追加.レコード追加画面を表示した後, (event) => { diff --git a/src/apps/各種申請/index.tsx b/src/apps/各種申請/index.tsx index bd7a97d..8c05c30 100644 --- a/src/apps/各種申請/index.tsx +++ b/src/apps/各種申請/index.tsx @@ -9,6 +9,7 @@ import { showLoadingDialog, } from "@/middleware/swal"; import { EmailID, sendEmail } from "@/mypage/メール"; +import bulkRequest from "@/rest-api/bulk"; import { get車室契約情報 } from "@/rest-api/車室契約情報"; import { get顧客マスタ } from "@/rest-api/顧客マスタ"; import { @@ -96,10 +97,8 @@ const getCallBack口座変更申請承認 = (record: 各種申請) => { }; const 解約申請承認 = async (record: 各種申請) => { - const 契約 = await get車室契約情報(record.契約情報.value); - // 車室契約情報への反映 - await client.record.updateRecord({ + bulkRequest.update({ app: AppID.車室契約情報, id: record.契約情報.value, record: makeRecordData({ @@ -107,12 +106,12 @@ const 解約申請承認 = async (record: 各種申請) => { }), }); - // 契約情報の同期処理 - await 契約状況同期(契約.駐車場名.value, Number(契約.車室番号.value)); - // 申請の完了 await 各種申請完了(record); + // データ保存 + await bulkRequest.save(); + // メールの送信 const email = await sendEmail(EmailID.解約承認, { application_no: record.申請番号.value, @@ -150,7 +149,7 @@ const 利用者情報変更申請承認 = async (record: 各種申請) => { 顧客コード: Number(record.顧客コード.value), }); if (customer === null) throw new Error("顧客不正"); - await client.record.updateRecord({ + bulkRequest.update({ app: AppID.顧客マスタ, id: customer.$id.value, record: makeRecordData({ @@ -170,6 +169,9 @@ const 利用者情報変更申請承認 = async (record: 各種申請) => { // 申請の完了 await 各種申請完了(record); + // データ保存 + await bulkRequest.save(); + // メールの送信 const email = await sendEmail(EmailID.利用者情報変更完了, { application_no: record.申請番号.value, @@ -203,7 +205,7 @@ const getCallBack利用者情報変更申請承認 = (record: 各種申請) => { const 車両番号_防犯登録番号変更申請承認 = async (record: 各種申請) => { // 車室契約情報アプリへの反映 const F = 車室契約情報フィールド名; - await client.record.updateRecord({ + bulkRequest.update({ app: AppID.車室契約情報, id: record.$id.value, record: makeRecordData({ @@ -217,6 +219,9 @@ const 車両番号_防犯登録番号変更申請承認 = async (record: 各種 // 申請の完了 await 各種申請完了(record); + // データ保存 + await bulkRequest.save(); + // メールの送信 const email = await sendEmail(EmailID.車両番号_防犯登録番号変更完了, { application_no: record.申請番号.value, diff --git a/src/apps/定期申込予約/自動承認.ts b/src/apps/定期申込予約/自動承認.ts index 478e14e..fe89a7a 100644 --- a/src/apps/定期申込予約/自動承認.ts +++ b/src/apps/定期申込予約/自動承認.ts @@ -2,7 +2,6 @@ import { AppID } from "@/common/appids"; import { makeRecordData } from "@/common/rest-api-client"; import { 契約状況同期 } from "@/logic/契約状況同期"; import { ShowConfirmDialog } from "@/middleware/swal"; -import { BulkRequest } from "@/rest-api/bulk"; import { getDetailUrl } from "@/rest-api/url"; import { get定期駐車場プランマスタ } from "@/rest-api/定期駐車場プランマスタ"; import { get自動承認グループ } from "@/rest-api/自動承認グループ"; @@ -27,6 +26,7 @@ import { 顧客マスタフィールド名 } from "@/types/顧客マスタ"; import { sprintf } from "sprintf"; import { CancelError, Message } from "@/exception"; import { dateParse, now } from "@/common/datetime"; +import bulkRequest from "@/rest-api/bulk"; export class 申込 { private 定期申込予約: 定期申込予約; @@ -43,8 +43,6 @@ export class 申込 { private 作成後契約: 車室契約情報 | null = null; - private requests: BulkRequest = new BulkRequest(); - constructor(定期申込予約: 定期申込予約) { this.定期申込予約 = 定期申込予約; } @@ -194,7 +192,7 @@ export class 申込 { const F = 顧客マスタフィールド名; const 顧客コード = await getNext顧客コード(); - this.requests.create({ + bulkRequest.create({ app: AppID.顧客マスタ, record: makeRecordData({ [F.顧客コード]: String(顧客コード), @@ -217,7 +215,7 @@ export class 申込 { if (!this.定期申込予約) throw new Error("定期申込予約不正"); const F = 車室契約情報フィールド名; - this.requests.create( + bulkRequest.create( { app: AppID.車室契約情報, record: makeRecordData({ @@ -238,7 +236,7 @@ export class 申込 { private async 申込情報完了() { if (this.プラン === null) throw new Error(); const F = 定期申込予約フィールド名; - this.requests.update({ + bulkRequest.update({ app: AppID.定期申込予約, id: this.定期申込予約.$id.value, record: makeRecordData({ @@ -256,7 +254,7 @@ export class 申込 { } private async save() { - this.requests.debug(); - await this.requests.save(); + bulkRequest.debug(); + await bulkRequest.save(); } } diff --git a/src/apps/定期駐車場マスタ/index.tsx b/src/apps/定期駐車場マスタ/index.tsx index 9c8cb65..f9d3c96 100644 --- a/src/apps/定期駐車場マスタ/index.tsx +++ b/src/apps/定期駐車場マスタ/index.tsx @@ -3,6 +3,7 @@ import { setHeaderButton } from "@/common/header-button"; import { KintoneEvent } from "@/common/kintone-event"; import { 契約状況同期 } from "@/logic/契約状況同期"; import { ShowConfirmDialog, SuccessDialog } from "@/middleware/swal"; +import bulkRequest from "@/rest-api/bulk"; import { 定期駐車場マスタ } from "@/types/定期駐車場マスタ"; (() => { @@ -21,6 +22,8 @@ import { 定期駐車場マスタ } from "@/types/定期駐車場マスタ"; await 契約状況同期(record.駐車場名.value); + await bulkRequest.save(); + await SuccessDialog.fire(); location.reload(); diff --git a/src/logic/契約状況同期.ts b/src/logic/契約状況同期.ts index 4e8edf1..71e9bfb 100644 --- a/src/logic/契約状況同期.ts +++ b/src/logic/契約状況同期.ts @@ -1,7 +1,7 @@ import { AppID } from "@/common/appids"; import { now } from "@/common/datetime"; import { makeRecordData } from "@/common/rest-api-client"; -import { BulkRequest } from "@/rest-api/bulk"; +import bulkRequest from "@/rest-api/bulk"; import { get車室契約情報一覧 } from "@/rest-api/車室契約情報"; import { get車室情報一覧 } from "@/rest-api/車室情報2"; import { 状態Dropdown, 車室情報2フィールド名 } from "@/types/車室情報2"; @@ -11,8 +11,6 @@ export const 契約状況同期 = async (駐車場名: string, 車室番号?: nu }; const 車室情報契約項目同期 = async (駐車場名: string, 車室番号?: number) => { - const requests = new BulkRequest(); - const 契約一覧 = await get車室契約情報一覧({ 駐車場名, 車室番号, @@ -27,7 +25,7 @@ const 車室情報契約項目同期 = async (駐車場名: string, 車室番号 車室一覧.forEach((車室) => { const 契約 = 契約一覧.find((c) => c.車室番号.value === 車室.車室番号.value); - requests.update({ + bulkRequest.update({ app: AppID.車室情報2, id: 車室.$id.value, record: makeRecordData({ @@ -38,9 +36,4 @@ const 車室情報契約項目同期 = async (駐車場名: string, 車室番号 }), }); }); - // 保存 - if (!requests.isSaved()) { - requests.debug(); - await requests.save(); - } }; diff --git a/src/rest-api/bulk.ts b/src/rest-api/bulk.ts index e66d74b..b8b728d 100644 --- a/src/rest-api/bulk.ts +++ b/src/rest-api/bulk.ts @@ -1,6 +1,5 @@ import { AppID } from "@/common/appids"; import { Field } from "@/common/rest-api-client"; -import { delay } from "@/common/timer"; import { KintoneRestAPIClient } from "@kintone/rest-api-client"; import { chunk } from "lodash"; @@ -20,7 +19,7 @@ type Payload = { record: Field; }; -type BulkRequestResponse = { id?: string; revision?: string }; +export type BulkRequestResponse = { id?: string; revision?: string }; export type RequestParam = { method: "POST" | "PUT"; @@ -29,6 +28,7 @@ export type RequestParam = { }; type Callback = (result: BulkRequestResponse) => Promise; +export type BulkRequestCallback = Callback; export class BulkRequest { private client: KintoneRestAPIClient; @@ -99,9 +99,13 @@ export class BulkRequest { clear() { this.requests = []; + this.callbacks = []; } debug() { console.log("BulkRequest debug", this, this.requests); } } + +const bulkRequest = new BulkRequest(); +export default bulkRequest; diff --git a/src/rest-api/車室契約情報.ts b/src/rest-api/車室契約情報.ts index d502f72..df76625 100644 --- a/src/rest-api/車室契約情報.ts +++ b/src/rest-api/車室契約情報.ts @@ -1,16 +1,18 @@ import { AppID } from "@/common/appids"; -import { formatDateStr, now } from "@/common/datetime"; +import { formatDateStr } from "@/common/datetime"; import { 車室契約情報, 車室契約情報フィールド名 } from "@/types/車室契約情報"; import { KintoneRestAPIClient } from "@kintone/rest-api-client"; import { QueryBuilder } from "./query"; const client = new KintoneRestAPIClient(); +const app = AppID.車室契約情報; + export const get車室契約情報 = async ( レコード番号: number | string ): Promise<車室契約情報> => { const { record } = await client.record.getRecord<車室契約情報>({ - app: AppID.車室契約情報, + app, id: レコード番号, }); @@ -41,7 +43,7 @@ export const get車室契約情報一覧 = async ({ } const record = await client.record.getAllRecords<車室契約情報>({ - app: AppID.車室契約情報, + app, condition: builder.build(), }); diff --git a/src/rest-api/車室情報2.ts b/src/rest-api/車室情報2.ts index f8f0d00..aafadde 100644 --- a/src/rest-api/車室情報2.ts +++ b/src/rest-api/車室情報2.ts @@ -1,11 +1,12 @@ import { AppID } from "@/common/appids"; import { 車室情報2, 車室情報2フィールド名 } from "@/types/車室情報2"; import { KintoneRestAPIClient } from "@kintone/rest-api-client"; -import { sprintf } from "sprintf"; import { QueryBuilder } from "./query"; const client = new KintoneRestAPIClient(); +const app = AppID.車室情報2; + type get車室情報一覧オプション = { 駐車場名?: string; 車室番号?: number | string; @@ -23,7 +24,7 @@ export const get車室情報一覧 = async ({ } const { records } = await client.record.getRecords<車室情報2>({ - app: AppID.車室情報2, + app, query: builder.build(), });