@chevre/domain 26.0.0-alpha.24 → 26.0.0-alpha.25
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/acceptedOffer.d.ts +0 -7
- package/lib/chevre/repo/acceptedOffer.js +27 -27
- package/lib/chevre/repo/ownershipInfo.d.ts +1 -35
- package/lib/chevre/repo/ownershipInfo.js +55 -161
- package/lib/chevre/service/order/deleteOrder.js +0 -1
- package/lib/chevre/service/order/returnOrder.d.ts +0 -2
- package/lib/chevre/service/order/returnOrder.js +8 -40
- package/lib/chevre/service/order/sendOrder.d.ts +0 -2
- package/lib/chevre/service/order/sendOrder.js +41 -55
- package/lib/chevre/service/task/onAuthorizationCreated.js +2 -2
- package/lib/chevre/service/task/returnOrder.js +2 -5
- package/lib/chevre/service/task/sendOrder.js +2 -2
- package/package.json +1 -1
|
@@ -27,13 +27,6 @@ export declare class AcceptedOfferRepo extends AcceptedOfferInReserveRepo {
|
|
|
27
27
|
acceptedOffers: [IAcceptedOffer];
|
|
28
28
|
_id?: never;
|
|
29
29
|
})[]>;
|
|
30
|
-
aggreateOwnershipInfosByOrder(filter: {
|
|
31
|
-
orderNumber: {
|
|
32
|
-
$eq: string;
|
|
33
|
-
};
|
|
34
|
-
}): Promise<{
|
|
35
|
-
identifier: string;
|
|
36
|
-
}[]>;
|
|
37
30
|
/**
|
|
38
31
|
* 注文オファーを展開して検索する
|
|
39
32
|
* 注文番号指定で1注文ドキュメントから参照する想定
|
|
@@ -105,33 +105,33 @@ class AcceptedOfferRepo extends acceptedOfferInReserve_1.AcceptedOfferInReserveR
|
|
|
105
105
|
return orders;
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
async aggreateOwnershipInfosByOrder(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
108
|
+
// public async aggreateOwnershipInfosByOrder(
|
|
109
|
+
// filter: {
|
|
110
|
+
// orderNumber: { $eq: string };
|
|
111
|
+
// }
|
|
112
|
+
// ): Promise<{ identifier: string }[]> {
|
|
113
|
+
// const aggregate = this.orderModel.aggregate<{ identifier: string }>([
|
|
114
|
+
// { $match: { orderNumber: { $eq: filter.orderNumber.$eq } } },
|
|
115
|
+
// { $match: { typeOf: { $eq: factory.order.OrderType.Order } } },
|
|
116
|
+
// {
|
|
117
|
+
// $unwind: {
|
|
118
|
+
// path: '$acceptedOffers',
|
|
119
|
+
// includeArrayIndex: 'acceptedOfferIndex'
|
|
120
|
+
// }
|
|
121
|
+
// },
|
|
122
|
+
// {
|
|
123
|
+
// $project: {
|
|
124
|
+
// _id: 0,
|
|
125
|
+
// identifier: {
|
|
126
|
+
// $concat: ['$customer.id', '-', '$acceptedOffers.itemOffered.typeOf', '-', '$orderNumber', '-', { $toString: '$acceptedOfferIndex' }]
|
|
127
|
+
// }
|
|
128
|
+
// }
|
|
129
|
+
// }
|
|
130
|
+
// ]);
|
|
131
|
+
// return aggregate
|
|
132
|
+
// .option({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
133
|
+
// .exec();
|
|
134
|
+
// }
|
|
135
135
|
/**
|
|
136
136
|
* 注文オファーを展開して検索する
|
|
137
137
|
* 注文番号指定で1注文ドキュメントから参照する想定
|
|
@@ -12,43 +12,9 @@ export declare class OwnershipInfoRepo {
|
|
|
12
12
|
private readonly ownershipInfoModel;
|
|
13
13
|
constructor(connection: Connection);
|
|
14
14
|
static CREATE_MONGO_CONDITIONS(params: Pick<IFindParams, 'ownedFromGte' | 'ownedFromLte' | 'project'>): FilterQuery<IDocType>[];
|
|
15
|
-
/**
|
|
16
|
-
* なければ作成する
|
|
17
|
-
*/
|
|
18
|
-
createIfNotExistByIdentifier(ownershipInfo: Omit<IOwnershipInfoWithId, 'id'>): Promise<{
|
|
19
|
-
id: string;
|
|
20
|
-
}>;
|
|
21
15
|
/**
|
|
22
16
|
* 所有権を検索する
|
|
23
17
|
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 識別子から所有期限を変更する
|
|
27
|
-
* 存在しない場合undefinedを返す
|
|
28
|
-
*/
|
|
29
|
-
findByIdentifierAndUpdateOwnedThrough(params: {
|
|
30
|
-
project: {
|
|
31
|
-
id: string;
|
|
32
|
-
};
|
|
33
|
-
identifier: string;
|
|
34
|
-
ownedThrough: Date;
|
|
35
|
-
}): Promise<Pick<IOwnershipInfoWithId, 'id' | 'identifier'> | undefined>;
|
|
36
|
-
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<factory.ownershipInfo.IOwnershipInfo<factory.ownershipInfo.IGood>, "id"> & {
|
|
37
|
-
_id: string;
|
|
38
|
-
} & Required<{
|
|
39
|
-
_id: string;
|
|
40
|
-
}> & {
|
|
41
|
-
__v: number;
|
|
42
|
-
}, import("mongoose").QueryOptions<IDocType>, (import("mongoose").Document<unknown, Record<string, never>, IDocType, import("./mongoose/virtuals").IVirtuals, {}> & Omit<factory.ownershipInfo.IOwnershipInfo<factory.ownershipInfo.IGood>, "id"> & {
|
|
43
|
-
_id: string;
|
|
44
|
-
} & Required<{
|
|
45
|
-
_id: string;
|
|
46
|
-
}> & {
|
|
47
|
-
__v: number;
|
|
48
|
-
}) | null>;
|
|
49
|
-
unsetUnnecessaryFields(params: {
|
|
50
|
-
filter: any;
|
|
51
|
-
$unset: any;
|
|
52
|
-
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
18
|
+
findOwnershipInfos(params: IFindParams, inclusion?: (keyof IOwnershipInfoWithId)[]): Promise<IOwnershipInfoWithId[]>;
|
|
53
19
|
}
|
|
54
20
|
export {};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OwnershipInfoRepo = void 0;
|
|
4
|
-
|
|
4
|
+
// import { v4 } from 'uuid';
|
|
5
5
|
const ownershipInfo_1 = require("./mongoose/schemas/ownershipInfo");
|
|
6
|
-
const errorHandler_1 = require("../errorHandler");
|
|
7
|
-
const factory_1 = require("../factory");
|
|
8
6
|
const settings_1 = require("../settings");
|
|
9
7
|
/**
|
|
10
8
|
* 所有権リポジトリ
|
|
@@ -34,57 +32,63 @@ class OwnershipInfoRepo {
|
|
|
34
32
|
}
|
|
35
33
|
return andConditions;
|
|
36
34
|
}
|
|
37
|
-
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
async createIfNotExistByIdentifier(ownershipInfo) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
35
|
+
// /**
|
|
36
|
+
// * なければ作成する
|
|
37
|
+
// */
|
|
38
|
+
// public async createIfNotExistByIdentifier(ownershipInfo: Omit<IOwnershipInfoWithId, 'id'>): Promise<{ id: string }> {
|
|
39
|
+
// let doc: { id: string } | undefined | null;
|
|
40
|
+
// let duplicate = false;
|
|
41
|
+
// try {
|
|
42
|
+
// doc = await this.ownershipInfoModel.findOneAndUpdate(
|
|
43
|
+
// { identifier: { $eq: ownershipInfo.identifier } },
|
|
44
|
+
// {
|
|
45
|
+
// // insert時以外は何もしなくてもよい
|
|
46
|
+
// $setOnInsert: {
|
|
47
|
+
// ...ownershipInfo,
|
|
48
|
+
// _id: v4() // 新規作成時は所有権ID発行
|
|
49
|
+
// }
|
|
50
|
+
// },
|
|
51
|
+
// {
|
|
52
|
+
// new: true,
|
|
53
|
+
// upsert: true,
|
|
54
|
+
// projection: {
|
|
55
|
+
// _id: 0,
|
|
56
|
+
// id: { $toString: '$_id' }
|
|
57
|
+
// }
|
|
58
|
+
// }
|
|
59
|
+
// )
|
|
60
|
+
// .lean<{ id: string }>()
|
|
61
|
+
// .exec();
|
|
62
|
+
// } catch (error) {
|
|
63
|
+
// if (await isMongoDuplicateError(error)) {
|
|
64
|
+
// // すでに所有権が存在する場合ok
|
|
65
|
+
// duplicate = true;
|
|
66
|
+
// }
|
|
67
|
+
// if (!duplicate) {
|
|
68
|
+
// throw error;
|
|
69
|
+
// }
|
|
70
|
+
// }
|
|
71
|
+
// if (duplicate) {
|
|
72
|
+
// // 重複の場合、再度取得
|
|
73
|
+
// doc = await this.ownershipInfoModel.findOne(
|
|
74
|
+
// { identifier: { $eq: ownershipInfo.identifier } },
|
|
75
|
+
// {
|
|
76
|
+
// _id: 0,
|
|
77
|
+
// id: { $toString: '$_id' }
|
|
78
|
+
// }
|
|
79
|
+
// )
|
|
80
|
+
// .lean<{ id: string }>()
|
|
81
|
+
// .exec();
|
|
82
|
+
// }
|
|
83
|
+
// if (doc === undefined || doc === null) {
|
|
84
|
+
// throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
85
|
+
// }
|
|
86
|
+
// return { id: doc.id };
|
|
87
|
+
// }
|
|
84
88
|
/**
|
|
85
89
|
* 所有権を検索する
|
|
86
90
|
*/
|
|
87
|
-
async
|
|
91
|
+
async findOwnershipInfos(params, inclusion) {
|
|
88
92
|
const conditions = OwnershipInfoRepo.CREATE_MONGO_CONDITIONS(params);
|
|
89
93
|
let projection = {
|
|
90
94
|
_id: 0,
|
|
@@ -122,115 +126,5 @@ class OwnershipInfoRepo {
|
|
|
122
126
|
.lean() // lean(2024-08-19~)
|
|
123
127
|
.exec();
|
|
124
128
|
}
|
|
125
|
-
/**
|
|
126
|
-
* 識別子から所有期限を変更する
|
|
127
|
-
* 存在しない場合undefinedを返す
|
|
128
|
-
*/
|
|
129
|
-
async findByIdentifierAndUpdateOwnedThrough(params) {
|
|
130
|
-
return this.ownershipInfoModel.findOneAndUpdate({
|
|
131
|
-
'project.id': { $eq: params.project.id },
|
|
132
|
-
identifier: { $eq: String(params.identifier) }
|
|
133
|
-
}, { ownedThrough: params.ownedThrough }, {
|
|
134
|
-
new: true,
|
|
135
|
-
projection: {
|
|
136
|
-
_id: 0,
|
|
137
|
-
id: { $toString: '$_id' },
|
|
138
|
-
identifier: 1
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
.lean()
|
|
142
|
-
.exec()
|
|
143
|
-
.then((doc) => {
|
|
144
|
-
// 存在しない場合も正常にハンドルする
|
|
145
|
-
if (doc === null) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
return doc;
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
// /**
|
|
154
|
-
// * 所有期限切れの所有権を削除する
|
|
155
|
-
// */
|
|
156
|
-
// public async deleteExpiredOwnershipInfos(params: {
|
|
157
|
-
// ownedThroughLte: Date;
|
|
158
|
-
// }) {
|
|
159
|
-
// await this.ownershipInfoModel.deleteMany({
|
|
160
|
-
// // 所有期限切れのもの(ownedThroughは必ず存在する)
|
|
161
|
-
// ownedThrough: { $lte: params.ownedThroughLte }
|
|
162
|
-
// })
|
|
163
|
-
// .exec();
|
|
164
|
-
// }
|
|
165
|
-
// /**
|
|
166
|
-
// * 所有者を追加する
|
|
167
|
-
// */
|
|
168
|
-
// public async addOwnerIfNotExist(params: {
|
|
169
|
-
// /**
|
|
170
|
-
// * 所有権ID
|
|
171
|
-
// */
|
|
172
|
-
// id: string;
|
|
173
|
-
// ownedBy: factory.ownershipInfo.IOwner;
|
|
174
|
-
// }): Promise<void> {
|
|
175
|
-
// if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
176
|
-
// throw new factory.errors.ArgumentNull('ownedBy.id');
|
|
177
|
-
// }
|
|
178
|
-
// let newOwner: factory.ownershipInfo.IOwner | undefined;
|
|
179
|
-
// if (params.ownedBy.typeOf === factory.personType.Person) {
|
|
180
|
-
// newOwner = {
|
|
181
|
-
// id: params.ownedBy.id,
|
|
182
|
-
// typeOf: params.ownedBy.typeOf
|
|
183
|
-
// };
|
|
184
|
-
// }
|
|
185
|
-
// if (newOwner !== undefined) {
|
|
186
|
-
// const doc = await this.ownershipInfoModel.findOneAndUpdate(
|
|
187
|
-
// { _id: { $eq: params.id } },
|
|
188
|
-
// { $addToSet: { ownedBy: newOwner } },
|
|
189
|
-
// {
|
|
190
|
-
// new: true,
|
|
191
|
-
// projection: { _id: 1 }
|
|
192
|
-
// }
|
|
193
|
-
// )
|
|
194
|
-
// .exec();
|
|
195
|
-
// if (doc === null) {
|
|
196
|
-
// throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
197
|
-
// }
|
|
198
|
-
// }
|
|
199
|
-
// }
|
|
200
|
-
// /**
|
|
201
|
-
// * 所有者を削除する
|
|
202
|
-
// */
|
|
203
|
-
// public async removeOwnerIfExist(params: {
|
|
204
|
-
// /**
|
|
205
|
-
// * 所有権ID
|
|
206
|
-
// */
|
|
207
|
-
// id: string;
|
|
208
|
-
// ownedBy: { id: string };
|
|
209
|
-
// }): Promise<void> {
|
|
210
|
-
// if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
211
|
-
// throw new factory.errors.ArgumentNull('ownedBy.id');
|
|
212
|
-
// }
|
|
213
|
-
// const doc = await this.ownershipInfoModel.findOneAndUpdate(
|
|
214
|
-
// { _id: { $eq: params.id } },
|
|
215
|
-
// { $pull: { ownedBy: { id: params.ownedBy.id } } },
|
|
216
|
-
// {
|
|
217
|
-
// new: true,
|
|
218
|
-
// projection: { _id: 1 }
|
|
219
|
-
// }
|
|
220
|
-
// )
|
|
221
|
-
// .exec();
|
|
222
|
-
// if (doc === null) {
|
|
223
|
-
// throw new factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
224
|
-
// }
|
|
225
|
-
// }
|
|
226
|
-
getCursor(conditions, projection) {
|
|
227
|
-
return this.ownershipInfoModel.find(conditions, projection)
|
|
228
|
-
.sort({ ownedFrom: factory_1.factory.sortType.Ascending })
|
|
229
|
-
.cursor();
|
|
230
|
-
}
|
|
231
|
-
async unsetUnnecessaryFields(params) {
|
|
232
|
-
return this.ownershipInfoModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
233
|
-
.exec();
|
|
234
|
-
}
|
|
235
129
|
}
|
|
236
130
|
exports.OwnershipInfoRepo = OwnershipInfoRepo;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
|
|
2
2
|
import type { ActionRepo } from '../../repo/action';
|
|
3
3
|
import type { OrderRepo } from '../../repo/order';
|
|
4
|
-
import type { OwnershipInfoRepo } from '../../repo/ownershipInfo';
|
|
5
4
|
import type { SettingRepo } from '../../repo/setting';
|
|
6
5
|
import type { TaskRepo } from '../../repo/task';
|
|
7
6
|
import type { ReturnOrderRepo } from '../../repo/transaction/returnOrder';
|
|
@@ -20,7 +19,6 @@ declare function returnOrder(params: {
|
|
|
20
19
|
acceptedOffer: AcceptedOfferRepo;
|
|
21
20
|
action: ActionRepo;
|
|
22
21
|
order: OrderRepo;
|
|
23
|
-
ownershipInfo: OwnershipInfoRepo;
|
|
24
22
|
setting: SettingRepo;
|
|
25
23
|
task: TaskRepo;
|
|
26
24
|
returnOrder: ReturnOrderRepo;
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.returnOrder = returnOrder;
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
// import { createMaskedCustomer } from '../../factory/order';
|
|
9
8
|
const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
|
|
10
9
|
const factory_1 = require("../../factory");
|
|
11
10
|
const debug = (0, debug_1.default)('chevre-domain:service:order');
|
|
@@ -19,9 +18,7 @@ function createReturnPolicy(params) {
|
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
function returnOrder(params) {
|
|
22
|
-
return async (repos
|
|
23
|
-
// settings: Settings
|
|
24
|
-
) => {
|
|
21
|
+
return async (repos) => {
|
|
25
22
|
if (typeof params.useOnOrderStatusChanged !== 'boolean') {
|
|
26
23
|
throw new factory_1.factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
|
|
27
24
|
}
|
|
@@ -81,14 +78,15 @@ function returnOrder(params) {
|
|
|
81
78
|
recipient,
|
|
82
79
|
typeOf: factory_1.factory.actionType.ReturnAction
|
|
83
80
|
};
|
|
84
|
-
|
|
81
|
+
const returnedOwnershipInfos = [];
|
|
85
82
|
let returnedOrder;
|
|
86
83
|
const action = await repos.action.start(returnOrderActionAttributes);
|
|
87
84
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
// ひとまず所有権管理を廃止するため、所有権返却処理は不要(2026-08-10)
|
|
86
|
+
// returnedOwnershipInfos = await processReturnOrder(order, dateReturned)({
|
|
87
|
+
// acceptedOffer: repos.acceptedOffer,
|
|
88
|
+
// ownershipInfo: repos.ownershipInfo
|
|
89
|
+
// });
|
|
92
90
|
// 注文ステータス変更
|
|
93
91
|
returnedOrder = await repos.order.returnOrder({
|
|
94
92
|
project: { id: order.project.id },
|
|
@@ -130,37 +128,7 @@ function returnOrder(params) {
|
|
|
130
128
|
...returnOrderActionAttributes,
|
|
131
129
|
id: action.id
|
|
132
130
|
}
|
|
133
|
-
})(repos
|
|
134
|
-
// settings
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function processReturnOrder(order, dateReturned) {
|
|
140
|
-
return async (repos) => {
|
|
141
|
-
const returnedOwnershipInfos = [];
|
|
142
|
-
// 所有権の所有期間変更
|
|
143
|
-
// 注文オファーリポジトリから所有権識別子を検索する(2023-12-07~)
|
|
144
|
-
const ownershipInfos = await repos.acceptedOffer.aggreateOwnershipInfosByOrder({ orderNumber: { $eq: order.orderNumber } });
|
|
145
|
-
if (Array.isArray(ownershipInfos)) {
|
|
146
|
-
await Promise.all(ownershipInfos.map(async (ownershipInfo) => {
|
|
147
|
-
const ownershipInfoReturned = await repos.ownershipInfo.findByIdentifierAndUpdateOwnedThrough({
|
|
148
|
-
project: { id: order.project.id },
|
|
149
|
-
identifier: String(ownershipInfo.identifier),
|
|
150
|
-
ownedThrough: dateReturned
|
|
151
|
-
})
|
|
152
|
-
.then((ownershipInfoByDB) => {
|
|
153
|
-
// 存在しない場合は識別子のみ保管(customer.typeOfによって存在しないこともありうる)
|
|
154
|
-
if (ownershipInfoByDB === undefined) {
|
|
155
|
-
return ownershipInfo;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return ownershipInfoByDB;
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
returnedOwnershipInfos.push(ownershipInfoReturned);
|
|
162
|
-
}));
|
|
131
|
+
})(repos);
|
|
163
132
|
}
|
|
164
|
-
return returnedOwnershipInfos;
|
|
165
133
|
};
|
|
166
134
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AcceptedOfferRepo } from '../../repo/acceptedOffer';
|
|
2
2
|
import type { ActionRepo } from '../../repo/action';
|
|
3
3
|
import type { OrderRepo } from '../../repo/order';
|
|
4
|
-
import type { OwnershipInfoRepo } from '../../repo/ownershipInfo';
|
|
5
4
|
import type { SettingRepo } from '../../repo/setting';
|
|
6
5
|
import type { TaskRepo } from '../../repo/task';
|
|
7
6
|
import type { PlaceOrderRepo } from '../../repo/transaction/placeOrder';
|
|
@@ -10,7 +9,6 @@ interface ISendOrderRepos {
|
|
|
10
9
|
acceptedOffer: AcceptedOfferRepo;
|
|
11
10
|
action: ActionRepo;
|
|
12
11
|
order: OrderRepo;
|
|
13
|
-
ownershipInfo: OwnershipInfoRepo;
|
|
14
12
|
setting: SettingRepo;
|
|
15
13
|
task: TaskRepo;
|
|
16
14
|
placeOrder: PlaceOrderRepo;
|
|
@@ -5,33 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.sendOrder = sendOrder;
|
|
7
7
|
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
// import {
|
|
9
|
-
const factory_1 = require("../delivery/factory");
|
|
10
|
-
// import { findPlaceOrderTransaction } from './findPlaceOrderTransaction';
|
|
8
|
+
// import { createOwnershipInfosFromOrder } from '../delivery/factory';
|
|
11
9
|
const onOrderStatusChanged_1 = require("./onOrderStatusChanged");
|
|
12
|
-
const
|
|
10
|
+
const factory_1 = require("../../factory");
|
|
13
11
|
const debug = (0, debug_1.default)('chevre-domain:service:order');
|
|
14
12
|
/**
|
|
15
13
|
* 注文を配送する
|
|
16
14
|
*/
|
|
17
15
|
function sendOrder(params) {
|
|
18
|
-
return async (repos
|
|
19
|
-
// settings: Settings
|
|
20
|
-
) => {
|
|
16
|
+
return async (repos) => {
|
|
21
17
|
if (typeof params.useOnOrderStatusChanged !== 'boolean') {
|
|
22
|
-
throw new
|
|
18
|
+
throw new factory_1.factory.errors.Argument('useOnOrderStatusChanged', 'must be boolean');
|
|
23
19
|
}
|
|
24
20
|
if (typeof params.object.acceptedOffers?.limit !== 'number') {
|
|
25
|
-
throw new
|
|
21
|
+
throw new factory_1.factory.errors.Argument('object.acceptedOffers.limit', 'must be number');
|
|
26
22
|
}
|
|
27
23
|
if (typeof params.object.acceptedOffers?.page !== 'number') {
|
|
28
|
-
throw new
|
|
24
|
+
throw new factory_1.factory.errors.Argument('object.acceptedOffers.page', 'must be number');
|
|
29
25
|
}
|
|
30
26
|
if (params.object.acceptedOffers.limit <= 0) {
|
|
31
|
-
throw new
|
|
27
|
+
throw new factory_1.factory.errors.Argument('object.acceptedOffers.limit', 'must be greater than 1');
|
|
32
28
|
}
|
|
33
29
|
if (params.object.acceptedOffers.page <= 0) {
|
|
34
|
-
throw new
|
|
30
|
+
throw new factory_1.factory.errors.Argument('object.acceptedOffers.page', 'must be greater than 1');
|
|
35
31
|
}
|
|
36
32
|
try {
|
|
37
33
|
const orderNumber = params.object.orderNumber;
|
|
@@ -49,24 +45,16 @@ function sendOrder(params) {
|
|
|
49
45
|
});
|
|
50
46
|
// プロジェクト条件検証
|
|
51
47
|
if (order.project.id !== params.project.id) {
|
|
52
|
-
throw new
|
|
48
|
+
throw new factory_1.factory.errors.NotFound('Order');
|
|
53
49
|
}
|
|
54
50
|
// 確認番号検証
|
|
55
51
|
if (order.confirmationNumber !== confirmationNumber) {
|
|
56
|
-
throw new
|
|
52
|
+
throw new factory_1.factory.errors.NotFound('Order');
|
|
57
53
|
}
|
|
58
54
|
// const maskedCustomer = createMaskedCustomer(order, { noProfile: true });
|
|
59
55
|
const simpleOrder = {
|
|
60
56
|
typeOf: order.typeOf,
|
|
61
|
-
// seller: {
|
|
62
|
-
// id: order.seller.id,
|
|
63
|
-
// typeOf: order.seller.typeOf,
|
|
64
|
-
// name: order.seller.name
|
|
65
|
-
// }, // 廃止(2024-03-06~)
|
|
66
|
-
// customer: { typeOf: maskedCustomer.typeOf, id: maskedCustomer.id }, // 廃止(2024-03-06~)
|
|
67
57
|
orderNumber: order.orderNumber,
|
|
68
|
-
// price: order.price,
|
|
69
|
-
// priceCurrency: order.priceCurrency,
|
|
70
58
|
orderDate: order.orderDate
|
|
71
59
|
};
|
|
72
60
|
const { limit, page } = params.object.acceptedOffers;
|
|
@@ -77,24 +65,24 @@ function sendOrder(params) {
|
|
|
77
65
|
const sendOrderActionAttributes = {
|
|
78
66
|
agent: (typeof params.agent?.typeOf === 'string') ? params.agent : order.project,
|
|
79
67
|
object: sendOrderObject,
|
|
80
|
-
// potentialActions: {},
|
|
81
68
|
project: order.project,
|
|
82
69
|
recipient: { id: order.customer.id, typeOf: order.customer.typeOf },
|
|
83
|
-
typeOf:
|
|
70
|
+
typeOf: factory_1.factory.actionType.SendAction
|
|
84
71
|
};
|
|
85
72
|
const action = await repos.action.start(sendOrderActionAttributes);
|
|
86
|
-
let creatingOwnershipInfos = [];
|
|
87
|
-
|
|
73
|
+
// let creatingOwnershipInfos: IOwnershipInfo[] = [];
|
|
74
|
+
const createdOwnershipInfos = [];
|
|
88
75
|
let allOffersDelivered = false;
|
|
89
76
|
let acceptedOffers;
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
77
|
+
// 所有権管理はひとまず廃止(2026-08-10~)
|
|
78
|
+
// // 所有権生成を最小化(2024-03-01~)
|
|
79
|
+
// let createOwnerships = false;
|
|
80
|
+
// switch (order.customer.typeOf) {
|
|
81
|
+
// case factory.personType.Person:
|
|
82
|
+
// createOwnerships = true; // Personのみに限定(2026-03-15~)
|
|
83
|
+
// break;
|
|
84
|
+
// default:
|
|
85
|
+
// }
|
|
98
86
|
try {
|
|
99
87
|
const offerIndexBase = (limit * (page - 1));
|
|
100
88
|
const searchSlicedAcceptedOffersResult = await repos.acceptedOffer.searchSlicedAcceptedOffersByOrderNumber({
|
|
@@ -104,29 +92,27 @@ function sendOrder(params) {
|
|
|
104
92
|
});
|
|
105
93
|
acceptedOffers = searchSlicedAcceptedOffersResult.acceptedOffers;
|
|
106
94
|
debug('delivering...', order.orderNumber, params.object.acceptedOffers, 'offerIndexBase:', offerIndexBase);
|
|
107
|
-
//
|
|
108
|
-
if (createOwnerships) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
// const deliveredCount = limit * page;
|
|
124
|
-
// debug(deliveredCount, 'delivered.', order.orderNumber, params.object.acceptedOffers);
|
|
95
|
+
// 所有権管理はひとまず廃止(2026-08-10~)
|
|
96
|
+
// if (createOwnerships) {
|
|
97
|
+
// creatingOwnershipInfos = createOwnershipInfosFromOrder({
|
|
98
|
+
// order: { ...order, acceptedOffers },
|
|
99
|
+
// offerIndexBase
|
|
100
|
+
// });
|
|
101
|
+
// createdOwnershipInfos = await Promise.all(creatingOwnershipInfos.map(async (creatingOwnershipInfo) => {
|
|
102
|
+
// const { id } = await repos.ownershipInfo.createIfNotExistByIdentifier(creatingOwnershipInfo);
|
|
103
|
+
// return {
|
|
104
|
+
// id,
|
|
105
|
+
// ...(typeof creatingOwnershipInfo.identifier === 'string')
|
|
106
|
+
// ? { identifier: creatingOwnershipInfo.identifier }
|
|
107
|
+
// : undefined
|
|
108
|
+
// };
|
|
109
|
+
// }));
|
|
110
|
+
// }
|
|
125
111
|
if (acceptedOffers.length === 0) {
|
|
126
112
|
order = await repos.order.changeStatus({
|
|
127
113
|
project: { id: order.project.id },
|
|
128
114
|
orderNumber,
|
|
129
|
-
orderStatus:
|
|
115
|
+
orderStatus: factory_1.factory.orderStatus.OrderDelivered,
|
|
130
116
|
previousOrderStatus: params.object.previousOrderStatus
|
|
131
117
|
});
|
|
132
118
|
allOffersDelivered = true;
|
|
@@ -154,7 +140,7 @@ function sendOrder(params) {
|
|
|
154
140
|
orderNumber: order.orderNumber,
|
|
155
141
|
project: order.project,
|
|
156
142
|
typeOf: order.typeOf,
|
|
157
|
-
orderStatus:
|
|
143
|
+
orderStatus: factory_1.factory.orderStatus.OrderDelivered,
|
|
158
144
|
price: order.price,
|
|
159
145
|
priceCurrency: order.priceCurrency
|
|
160
146
|
}
|
|
@@ -180,7 +166,7 @@ function sendOrder(params) {
|
|
|
180
166
|
project: { id: params.project.id },
|
|
181
167
|
inclusion: ['orderStatus']
|
|
182
168
|
});
|
|
183
|
-
if (currentOrder?.orderStatus ===
|
|
169
|
+
if (currentOrder?.orderStatus === factory_1.factory.orderStatus.OrderReturned) {
|
|
184
170
|
throwsError = false;
|
|
185
171
|
}
|
|
186
172
|
if (throwsError) {
|
|
@@ -7,7 +7,7 @@ const action_1 = require("../../repo/action");
|
|
|
7
7
|
const assetTransaction_1 = require("../../repo/assetTransaction");
|
|
8
8
|
const authorization_1 = require("../../repo/authorization");
|
|
9
9
|
const order_1 = require("../../repo/order");
|
|
10
|
-
|
|
10
|
+
// import { OwnershipInfoRepo } from '../../repo/ownershipInfo';
|
|
11
11
|
const reservation_1 = require("../../repo/reservation");
|
|
12
12
|
const setting_1 = require("../../repo/setting");
|
|
13
13
|
const task_1 = require("../../repo/task");
|
|
@@ -23,7 +23,7 @@ function call(params) {
|
|
|
23
23
|
assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
|
|
24
24
|
code: new authorization_1.AuthorizationRepo(connection),
|
|
25
25
|
order: new order_1.OrderRepo(connection),
|
|
26
|
-
ownershipInfo: new
|
|
26
|
+
// ownershipInfo: new OwnershipInfoRepo(connection),
|
|
27
27
|
reservation: new reservation_1.ReservationRepo(connection),
|
|
28
28
|
setting: new setting_1.SettingRepo(connection),
|
|
29
29
|
task: new task_1.TaskRepo(connection)
|
|
@@ -4,7 +4,6 @@ exports.call = call;
|
|
|
4
4
|
const acceptedOffer_1 = require("../../repo/acceptedOffer");
|
|
5
5
|
const action_1 = require("../../repo/action");
|
|
6
6
|
const order_1 = require("../../repo/order");
|
|
7
|
-
const ownershipInfo_1 = require("../../repo/ownershipInfo");
|
|
8
7
|
const setting_1 = require("../../repo/setting");
|
|
9
8
|
const task_1 = require("../../repo/task");
|
|
10
9
|
const returnOrder_1 = require("../../repo/transaction/returnOrder");
|
|
@@ -22,12 +21,10 @@ function call(params) {
|
|
|
22
21
|
acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
|
|
23
22
|
action: new action_1.ActionRepo(connection),
|
|
24
23
|
order: new order_1.OrderRepo(connection),
|
|
25
|
-
ownershipInfo: new
|
|
24
|
+
// ownershipInfo: new OwnershipInfoRepo(connection),
|
|
26
25
|
setting: new setting_1.SettingRepo(connection),
|
|
27
26
|
task: new task_1.TaskRepo(connection),
|
|
28
27
|
returnOrder: new returnOrder_1.ReturnOrderRepo(connection)
|
|
29
|
-
}
|
|
30
|
-
// settings
|
|
31
|
-
);
|
|
28
|
+
});
|
|
32
29
|
};
|
|
33
30
|
}
|
|
@@ -5,7 +5,7 @@ const factory_1 = require("../../factory");
|
|
|
5
5
|
const acceptedOffer_1 = require("../../repo/acceptedOffer");
|
|
6
6
|
const action_1 = require("../../repo/action");
|
|
7
7
|
const order_1 = require("../../repo/order");
|
|
8
|
-
|
|
8
|
+
// import { OwnershipInfoRepo } from '../../repo/ownershipInfo';
|
|
9
9
|
const setting_1 = require("../../repo/setting");
|
|
10
10
|
const task_1 = require("../../repo/task");
|
|
11
11
|
const placeOrder_1 = require("../../repo/transaction/placeOrder");
|
|
@@ -32,7 +32,7 @@ function call(params) {
|
|
|
32
32
|
acceptedOffer: new acceptedOffer_1.AcceptedOfferRepo(connection),
|
|
33
33
|
action: new action_1.ActionRepo(connection),
|
|
34
34
|
order: new order_1.OrderRepo(connection),
|
|
35
|
-
ownershipInfo: new
|
|
35
|
+
// ownershipInfo: new OwnershipInfoRepo(connection),
|
|
36
36
|
setting: new setting_1.SettingRepo(connection),
|
|
37
37
|
task: new task_1.TaskRepo(connection),
|
|
38
38
|
placeOrder: new placeOrder_1.PlaceOrderRepo(connection)
|
package/package.json
CHANGED