@chevre/domain 25.0.0-alpha.11 → 25.0.0-alpha.13
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/lib/chevre/repo/mongoose/schemas/order.js +1 -1
- package/lib/chevre/repo/orderInTransaction.d.ts +2 -1
- package/lib/chevre/repo/orderInTransaction.js +41 -22
- package/lib/chevre/service/transaction/placeOrder/start/factory.d.ts +4 -0
- package/lib/chevre/service/transaction/placeOrder/start.d.ts +7 -1
- package/lib/chevre/service/transaction/placeOrder/start.js +24 -1
- package/lib/chevre/service/transaction/placeOrder.d.ts +1 -2
- package/lib/chevre/service/transaction/placeOrder.js +1 -3
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ const schemaDefinition = {
|
|
|
26
26
|
orderDate: { type: Date, required: true },
|
|
27
27
|
dateReturned: Date,
|
|
28
28
|
orderedItem: [mongoose_1.SchemaTypes.Mixed],
|
|
29
|
-
identifier: String, // 注文取引IDとして再定義(2026-06-22~)
|
|
29
|
+
identifier: { type: String, required: true }, // 注文取引IDとして再定義(2026-06-22~)
|
|
30
30
|
// 以下廃止(2026-06-13~)
|
|
31
31
|
// identifier: SchemaTypes.Mixed, // 廃止するためにMixed化(2026-06-12~)
|
|
32
32
|
// isGift: Boolean,
|
|
@@ -10,6 +10,7 @@ type IOrderInTransaction = Pick<factory.order.IOrder, 'orderNumber' | 'project'
|
|
|
10
10
|
identifier: string;
|
|
11
11
|
acceptedOffers: factory.order.IAcceptedOffer[];
|
|
12
12
|
customer?: factory.order.ICustomer;
|
|
13
|
+
seller?: factory.order.ISeller;
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* typeOf: Orderへドキュメント変換時の編集フィールド
|
|
@@ -57,7 +58,7 @@ export type IMinimizedAcceptedOffer = Pick<factory.order.IOptimizedAcceptedOffer
|
|
|
57
58
|
export declare class OrderInTransactionRepo extends AcceptedOfferInReserveRepo {
|
|
58
59
|
private readonly orderModel;
|
|
59
60
|
constructor(connection: Connection);
|
|
60
|
-
createPlaceOrderIfNotExists(params: Pick<IOrderInTransaction, 'orderNumber' | 'project' | 'identifier' | 'broker'>): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
61
|
+
createPlaceOrderIfNotExists(params: Pick<IOrderInTransaction, 'orderNumber' | 'project' | 'identifier' | 'broker' | 'seller' | 'customer'>): Promise<import("mongoose").UpdateWriteOpResult | undefined>;
|
|
61
62
|
/**
|
|
62
63
|
* 取引進行中の注文からacceptedOffersを検索する
|
|
63
64
|
* 予約取引から予約ごとの価格仕様も参照する
|
|
@@ -17,13 +17,15 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
17
17
|
this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
|
|
18
18
|
}
|
|
19
19
|
async createPlaceOrderIfNotExists(params) {
|
|
20
|
-
const { orderNumber, project, identifier, broker } = params;
|
|
20
|
+
const { orderNumber, project, identifier, broker, seller, customer } = params;
|
|
21
21
|
const setOnInsert = {
|
|
22
22
|
typeOf: factory_1.factory.transactionType.PlaceOrder,
|
|
23
23
|
orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
24
24
|
orderNumber,
|
|
25
25
|
project,
|
|
26
26
|
identifier, // 取引ID(2026-06-22~)
|
|
27
|
+
...((seller !== undefined) && { seller }),
|
|
28
|
+
...((customer !== undefined) && { customer }),
|
|
27
29
|
...((broker !== undefined) && { broker })
|
|
28
30
|
};
|
|
29
31
|
try {
|
|
@@ -113,21 +115,23 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
113
115
|
if (!Array.isArray(params.acceptedOffers) || params.acceptedOffers.length === 0) {
|
|
114
116
|
return;
|
|
115
117
|
}
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
118
|
+
const { orderNumber, project, identifier } = params;
|
|
119
|
+
await this.createPlaceOrderIfNotExists({ orderNumber, project, identifier });
|
|
120
|
+
// const setOnInsert: IInitalOrderInTransaction = {
|
|
121
|
+
// typeOf: factory.transactionType.PlaceOrder,
|
|
122
|
+
// orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
123
|
+
// orderNumber: params.orderNumber,
|
|
124
|
+
// project: params.project,
|
|
125
|
+
// identifier: params.identifier // 取引ID(2026-06-22~)
|
|
126
|
+
// };
|
|
127
|
+
const result = await this.orderModel.updateOne({
|
|
124
128
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
125
129
|
orderNumber: { $eq: params.orderNumber },
|
|
126
130
|
// プロジェクトでもフィルター(注文番号重複バグがあったため)(2026-02-21~)
|
|
127
131
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
128
132
|
'project.id': { $eq: params.project.id }
|
|
129
133
|
}, {
|
|
130
|
-
$setOnInsert: setOnInsert,
|
|
134
|
+
// $setOnInsert: setOnInsert, // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
131
135
|
$push: {
|
|
132
136
|
acceptedOffers: {
|
|
133
137
|
$each: params.acceptedOffers
|
|
@@ -138,8 +142,15 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
138
142
|
broker: { id: params.broker.id, typeOf: params.broker.typeOf }
|
|
139
143
|
}) // set broker(2026-06-21~)
|
|
140
144
|
}
|
|
141
|
-
}, {
|
|
145
|
+
}, {
|
|
146
|
+
// upsert: true // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
147
|
+
})
|
|
142
148
|
.exec();
|
|
149
|
+
if (result.matchedCount !== 1) {
|
|
150
|
+
console.error(params, result);
|
|
151
|
+
throw new factory_1.factory.errors.Internal(`orderInTransaction not found`);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
143
154
|
}
|
|
144
155
|
/**
|
|
145
156
|
* serialNumberからオファーを除外する
|
|
@@ -179,7 +190,7 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
179
190
|
}
|
|
180
191
|
}
|
|
181
192
|
async setCustomer(params) {
|
|
182
|
-
const { customer, orderNumber, project } = params;
|
|
193
|
+
const { customer, orderNumber, project, identifier } = params;
|
|
183
194
|
const filter = {
|
|
184
195
|
typeOf: { $eq: factory_1.factory.transactionType.PlaceOrder },
|
|
185
196
|
orderNumber: { $eq: orderNumber },
|
|
@@ -187,19 +198,27 @@ class OrderInTransactionRepo extends acceptedOfferInReserve_1.AcceptedOfferInRes
|
|
|
187
198
|
// 万が一異なるプロジェクトで同じ注文番号でオファーを受け入れようとしても、DBにインデックスによってDuplicateKey
|
|
188
199
|
'project.id': { $eq: project.id }
|
|
189
200
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
201
|
+
await this.createPlaceOrderIfNotExists({ orderNumber, project, identifier });
|
|
202
|
+
// const setOnInsert: IInitalOrderInTransaction = {
|
|
203
|
+
// typeOf: factory.transactionType.PlaceOrder,
|
|
204
|
+
// orderDate: new Date(), // orderDate required(2024-12-09~)
|
|
205
|
+
// orderNumber,
|
|
206
|
+
// project,
|
|
207
|
+
// identifier: params.identifier // 取引ID(2026-06-22~)
|
|
208
|
+
// };
|
|
197
209
|
const setKeys = { customer };
|
|
198
|
-
|
|
199
|
-
$setOnInsert: setOnInsert,
|
|
210
|
+
const result = await this.orderModel.updateOne(filter, {
|
|
211
|
+
// $setOnInsert: setOnInsert, // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
200
212
|
$set: setKeys
|
|
201
|
-
}, {
|
|
213
|
+
}, {
|
|
214
|
+
// upsert: true // createPlaceOrderIfNotExistsへ移行(2026-06-24~)
|
|
215
|
+
})
|
|
202
216
|
.exec();
|
|
217
|
+
if (result.matchedCount !== 1) {
|
|
218
|
+
console.error(params, result);
|
|
219
|
+
throw new factory_1.factory.errors.Internal(`orderInTransaction not found`);
|
|
220
|
+
}
|
|
221
|
+
return result;
|
|
203
222
|
}
|
|
204
223
|
/**
|
|
205
224
|
* 注文ドキュメントからcustomer属性を参照する
|
|
@@ -13,6 +13,10 @@ type IStartPlaceOrderParams = factory.transaction.placeOrder.IStartParamsWithout
|
|
|
13
13
|
*/
|
|
14
14
|
clientUser: factory.transaction.placeOrder.IClientUserBeforeStart;
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* 注文ドキュメントに保管する代理人
|
|
18
|
+
*/
|
|
19
|
+
broker?: factory.order.IBroker;
|
|
16
20
|
};
|
|
17
21
|
declare function createStartParams(params: IStartPlaceOrderParams, expiresInSeconds: number, passport: IVerifiedPassport | undefined, seller: Pick<factory.seller.ISeller, 'id' | 'name' | 'typeOf' | 'project' | 'additionalProperty'>, customerType?: string): factory.transaction.placeOrder.IStartParams;
|
|
18
22
|
export { AGENT_IDENTIFIER_NAME_PASSPORT, createStartParams, IStartPlaceOrderParams };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { IssuerRepo } from '../../../repo/issuer';
|
|
2
2
|
import type { MemberRepo } from '../../../repo/member';
|
|
3
3
|
import type { MemberProgramRepo } from '../../../repo/memberProgram';
|
|
4
|
+
import type { OrderInTransactionRepo } from '../../../repo/orderInTransaction';
|
|
5
|
+
import type { OrderNumberRepo } from '../../../repo/orderNumber';
|
|
4
6
|
import type { PassportRepo } from '../../../repo/passport';
|
|
7
|
+
import type { ProjectRepo } from '../../../repo/project';
|
|
5
8
|
import type { ProjectMakesOfferRepo } from '../../../repo/projectMakesOffer';
|
|
6
9
|
import type { SellerRepo } from '../../../repo/seller';
|
|
7
10
|
import type { IStartedPlaceOrder, PlaceOrderRepo } from '../../../repo/transaction/placeOrder';
|
|
@@ -14,10 +17,13 @@ interface IStartOperationRepos {
|
|
|
14
17
|
projectMakesOffer: ProjectMakesOfferRepo;
|
|
15
18
|
seller: SellerRepo;
|
|
16
19
|
placeOrder: PlaceOrderRepo;
|
|
20
|
+
orderInTransaction: OrderInTransactionRepo;
|
|
21
|
+
project: ProjectRepo;
|
|
22
|
+
orderNumber: OrderNumberRepo;
|
|
17
23
|
}
|
|
18
24
|
type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
|
|
19
25
|
interface IStartOptions {
|
|
20
|
-
|
|
26
|
+
createOrderDocument: boolean;
|
|
21
27
|
}
|
|
22
28
|
/**
|
|
23
29
|
* 取引開始
|
|
@@ -4,6 +4,7 @@ exports.start = start;
|
|
|
4
4
|
const factory_1 = require("../../../factory");
|
|
5
5
|
const factory_2 = require("./start/factory");
|
|
6
6
|
const validateStartRequest_1 = require("./start/validateStartRequest");
|
|
7
|
+
const issueOrderNumberIfNotExist_1 = require("./issueOrderNumberIfNotExist");
|
|
7
8
|
/**
|
|
8
9
|
* 取引開始
|
|
9
10
|
*/
|
|
@@ -25,7 +26,7 @@ function start(params, options) {
|
|
|
25
26
|
const startParams = (0, factory_2.createStartParams)(params, expiresInSeconds, passport, seller, customerType);
|
|
26
27
|
let transaction;
|
|
27
28
|
// lock passport(2024-07-05~)
|
|
28
|
-
if (
|
|
29
|
+
if (passport !== undefined) {
|
|
29
30
|
try {
|
|
30
31
|
await repos.passport.lock(passport);
|
|
31
32
|
}
|
|
@@ -51,6 +52,28 @@ function start(params, options) {
|
|
|
51
52
|
if (transaction === undefined) {
|
|
52
53
|
transaction = await repos.placeOrder.startPlaceOrder(startParams);
|
|
53
54
|
}
|
|
55
|
+
// support createOrderDocument(2026-06-23~)
|
|
56
|
+
if (options.createOrderDocument) {
|
|
57
|
+
const orderNumber = await (0, issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist)({
|
|
58
|
+
project: { id: params.project.id },
|
|
59
|
+
id: transaction.id,
|
|
60
|
+
object: { orderDate: new Date() }
|
|
61
|
+
})(repos);
|
|
62
|
+
await repos.orderInTransaction.createPlaceOrderIfNotExists({
|
|
63
|
+
orderNumber,
|
|
64
|
+
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
65
|
+
identifier: transaction.id,
|
|
66
|
+
seller: {
|
|
67
|
+
id: seller.id,
|
|
68
|
+
name: (typeof seller.name === 'string') ? seller.name : String(seller.name?.ja),
|
|
69
|
+
typeOf: seller.typeOf,
|
|
70
|
+
additionalProperty: (Array.isArray(seller.additionalProperty)) ? seller.additionalProperty : [] // 追加特性を追加(2023-08-08~)
|
|
71
|
+
},
|
|
72
|
+
...((typeof params.object.customer?.typeOf === 'string') && { customer: params.object.customer }),
|
|
73
|
+
...((typeof params.broker?.typeOf === 'string') && { broker: params.broker })
|
|
74
|
+
});
|
|
75
|
+
// console.log('createPlaceOrderResult:', createPlaceOrderResult);
|
|
76
|
+
}
|
|
54
77
|
return transaction;
|
|
55
78
|
};
|
|
56
79
|
}
|
|
@@ -5,5 +5,4 @@ import { confirm } from './placeOrder/confirm';
|
|
|
5
5
|
import { exportTasksById } from './placeOrder/exportTasksById';
|
|
6
6
|
import { start, IStartPlaceOrderParams } from './placeOrder/start';
|
|
7
7
|
import { updateAgent } from './placeOrder/updateAgent';
|
|
8
|
-
|
|
9
|
-
export { confirm, start, IStartPlaceOrderParams, exportTasksById, updateAgent, issueOrderNumberIfNotExist };
|
|
8
|
+
export { confirm, start, IStartPlaceOrderParams, exportTasksById, updateAgent };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.updateAgent = exports.exportTasksById = exports.start = exports.confirm = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* 注文取引サービス
|
|
6
6
|
*/
|
|
@@ -12,5 +12,3 @@ const start_1 = require("./placeOrder/start");
|
|
|
12
12
|
Object.defineProperty(exports, "start", { enumerable: true, get: function () { return start_1.start; } });
|
|
13
13
|
const updateAgent_1 = require("./placeOrder/updateAgent");
|
|
14
14
|
Object.defineProperty(exports, "updateAgent", { enumerable: true, get: function () { return updateAgent_1.updateAgent; } });
|
|
15
|
-
const issueOrderNumberIfNotExist_1 = require("./placeOrder/issueOrderNumberIfNotExist");
|
|
16
|
-
Object.defineProperty(exports, "issueOrderNumberIfNotExist", { enumerable: true, get: function () { return issueOrderNumberIfNotExist_1.issueOrderNumberIfNotExist; } });
|
package/package.json
CHANGED