@chevre/domain 26.0.0-alpha.23 → 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/authorization.js +15 -15
- package/lib/chevre/repo/mongoose/schemas/action.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/actionRecipe.js +7 -0
- package/lib/chevre/repo/mongoose/schemas/aggregation.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/assetTransaction.js +10 -0
- package/lib/chevre/repo/mongoose/schemas/authorization.js +25 -18
- package/lib/chevre/repo/mongoose/schemas/message.js +8 -1
- package/lib/chevre/repo/mongoose/schemas/ownershipInfo.js +1 -146
- package/lib/chevre/repo/mongoose/schemas/ticket.js +8 -1
- package/lib/chevre/repo/ownershipInfo.d.ts +6 -108
- package/lib/chevre/repo/ownershipInfo.js +59 -395
- package/lib/chevre/repo/task.d.ts +25 -4
- package/lib/chevre/repo/task.js +1 -0
- 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 +2 -2
|
@@ -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
|
* 所有権リポジトリ
|
|
@@ -15,169 +13,10 @@ class OwnershipInfoRepo {
|
|
|
15
13
|
this.ownershipInfoModel = connection.model(ownershipInfo_1.modelName, (0, ownershipInfo_1.createSchema)());
|
|
16
14
|
}
|
|
17
15
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
18
|
-
const andConditions = [];
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
if (typeof params.project.id.$eq === 'string') {
|
|
23
|
-
andConditions.push({
|
|
24
|
-
'project.id': {
|
|
25
|
-
$eq: params.project.id.$eq
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const typeOfGoodIdentifierEq = params.typeOfGood?.identifier?.$eq;
|
|
32
|
-
if (typeof typeOfGoodIdentifierEq === 'string') {
|
|
33
|
-
andConditions.push({
|
|
34
|
-
'typeOfGood.identifier': {
|
|
35
|
-
$exists: true,
|
|
36
|
-
$eq: typeOfGoodIdentifierEq
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
const typeOfGoodIssuedThroughIdEq = params.typeOfGood?.issuedThrough?.id?.$eq;
|
|
41
|
-
if (typeof typeOfGoodIssuedThroughIdEq === 'string') {
|
|
42
|
-
andConditions.push({
|
|
43
|
-
'typeOfGood.issuedThrough.id': {
|
|
44
|
-
$exists: true,
|
|
45
|
-
$eq: typeOfGoodIssuedThroughIdEq
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
const typeOfGoodIssuedThroughTypeOfEq = params.typeOfGood?.issuedThrough?.typeOf?.$eq;
|
|
50
|
-
if (typeof typeOfGoodIssuedThroughTypeOfEq === 'string') {
|
|
51
|
-
andConditions.push({
|
|
52
|
-
'typeOfGood.issuedThrough.typeOf': {
|
|
53
|
-
$exists: true,
|
|
54
|
-
$eq: typeOfGoodIssuedThroughTypeOfEq
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
const typeOfGoodTypeOf = params.typeOfGood?.typeOf;
|
|
59
|
-
if (typeof typeOfGoodTypeOf === 'string') {
|
|
60
|
-
andConditions.push({
|
|
61
|
-
'typeOfGood.typeOf': {
|
|
62
|
-
$exists: true,
|
|
63
|
-
$eq: typeOfGoodTypeOf
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const typeOfGoodTypeOfEq = typeOfGoodTypeOf?.$eq;
|
|
69
|
-
if (typeof typeOfGoodTypeOfEq === 'string') {
|
|
70
|
-
andConditions.push({
|
|
71
|
-
'typeOfGood.typeOf': {
|
|
72
|
-
$exists: true,
|
|
73
|
-
$eq: typeOfGoodTypeOfEq
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
const typeOfGoodTypeOfIn = typeOfGoodTypeOf?.$in;
|
|
78
|
-
if (Array.isArray(typeOfGoodTypeOfIn)) {
|
|
79
|
-
andConditions.push({
|
|
80
|
-
'typeOfGood.typeOf': {
|
|
81
|
-
$exists: true,
|
|
82
|
-
$in: typeOfGoodTypeOfIn
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// 互換性維持対応
|
|
88
|
-
// if (params.typeOfGood === undefined || params.typeOfGood === null) {
|
|
89
|
-
// params.typeOfGood = {};
|
|
90
|
-
// }
|
|
91
|
-
// if (typeof (<any>params.typeOfGood).id === 'string') {
|
|
92
|
-
// params.typeOfGood.id = { $eq: (<any>params.typeOfGood).id };
|
|
93
|
-
// }
|
|
94
|
-
// if (Array.isArray((<any>params.typeOfGood).ids)) {
|
|
95
|
-
// params.typeOfGood.id = { $in: (<any>params.typeOfGood).ids };
|
|
96
|
-
// }
|
|
97
|
-
const typeOfGoodIdEq = params.typeOfGood?.id?.$eq;
|
|
98
|
-
if (typeof typeOfGoodIdEq === 'string') {
|
|
99
|
-
andConditions.push({
|
|
100
|
-
'typeOfGood.id': {
|
|
101
|
-
$exists: true,
|
|
102
|
-
$eq: typeOfGoodIdEq
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const typeOfGoodIdIn = params.typeOfGood?.id?.$in;
|
|
107
|
-
if (Array.isArray(typeOfGoodIdIn)) {
|
|
108
|
-
andConditions.push({
|
|
109
|
-
'typeOfGood.id': {
|
|
110
|
-
$exists: true,
|
|
111
|
-
$in: typeOfGoodIdIn
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
/* istanbul ignore else */
|
|
116
|
-
if (Array.isArray(params.ids)) {
|
|
117
|
-
andConditions.push({
|
|
118
|
-
_id: { $in: params.ids }
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/* istanbul ignore else */
|
|
122
|
-
if (Array.isArray(params.identifiers)) {
|
|
123
|
-
andConditions.push({
|
|
124
|
-
identifier: {
|
|
125
|
-
$exists: true,
|
|
126
|
-
$in: params.identifiers
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
const ownedByTypeOfEq = params.ownedBy?.typeOf?.$eq;
|
|
131
|
-
if (typeof ownedByTypeOfEq === 'string') {
|
|
132
|
-
andConditions.push({
|
|
133
|
-
'ownedBy.typeOf': {
|
|
134
|
-
$exists: true,
|
|
135
|
-
$eq: ownedByTypeOfEq
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
/* istanbul ignore else */
|
|
140
|
-
const ownedById = params.ownedBy?.id;
|
|
141
|
-
if (typeof ownedById === 'string') {
|
|
142
|
-
andConditions.push({
|
|
143
|
-
'ownedBy.id': {
|
|
144
|
-
$exists: true,
|
|
145
|
-
$eq: ownedById
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
const ownedByIdIn = ownedById?.$in;
|
|
151
|
-
if (Array.isArray(ownedByIdIn)) {
|
|
152
|
-
andConditions.push({
|
|
153
|
-
'ownedBy.id': {
|
|
154
|
-
$exists: true,
|
|
155
|
-
$in: ownedByIdIn
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
// discontinue(2024-12-26~)
|
|
161
|
-
// const ownedByMembershipNumberIn = params.ownedBy?.memberOf?.membershipNumber?.$in;
|
|
162
|
-
// if (Array.isArray(ownedByMembershipNumberIn)) {
|
|
163
|
-
// andConditions.push({
|
|
164
|
-
// 'ownedBy.memberOf.membershipNumber': {
|
|
165
|
-
// $exists: true,
|
|
166
|
-
// $in: ownedByMembershipNumberIn
|
|
167
|
-
// }
|
|
168
|
-
// });
|
|
169
|
-
// }
|
|
170
|
-
/* istanbul ignore else */
|
|
171
|
-
if (params.ownedFrom instanceof Date) {
|
|
172
|
-
andConditions.push({
|
|
173
|
-
ownedThrough: { $gte: params.ownedFrom }
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
/* istanbul ignore else */
|
|
177
|
-
if (params.ownedThrough instanceof Date) {
|
|
178
|
-
andConditions.push({
|
|
179
|
-
ownedFrom: { $lte: params.ownedThrough }
|
|
180
|
-
});
|
|
16
|
+
const andConditions = [];
|
|
17
|
+
const projectIdEq = params.project?.id?.$eq;
|
|
18
|
+
if (typeof projectIdEq === 'string') {
|
|
19
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
181
20
|
}
|
|
182
21
|
const ownedFromGte = params.ownedFromGte;
|
|
183
22
|
if (ownedFromGte instanceof Date) {
|
|
@@ -191,105 +30,65 @@ class OwnershipInfoRepo {
|
|
|
191
30
|
ownedFrom: { $lte: ownedFromLte }
|
|
192
31
|
});
|
|
193
32
|
}
|
|
194
|
-
const acquiredFromIdIn = params.acquiredFrom?.id?.$in;
|
|
195
|
-
if (Array.isArray(acquiredFromIdIn)) {
|
|
196
|
-
andConditions.push({
|
|
197
|
-
'acquiredFrom.id': {
|
|
198
|
-
$exists: true,
|
|
199
|
-
$in: acquiredFromIdIn
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
33
|
return andConditions;
|
|
204
34
|
}
|
|
205
|
-
/**
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
async createIfNotExistByIdentifier(ownershipInfo) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
async projectFieldsById(params, inclusion) {
|
|
259
|
-
let projection = {
|
|
260
|
-
_id: 0,
|
|
261
|
-
id: { $toString: '$_id' },
|
|
262
|
-
project: 1,
|
|
263
|
-
typeOf: 1,
|
|
264
|
-
identifier: 1,
|
|
265
|
-
ownedBy: 1,
|
|
266
|
-
acquiredFrom: 1,
|
|
267
|
-
ownedFrom: 1,
|
|
268
|
-
ownedThrough: 1,
|
|
269
|
-
typeOfGood: 1
|
|
270
|
-
};
|
|
271
|
-
const positiveProjectionFields = (Array.isArray(inclusion))
|
|
272
|
-
? inclusion.filter((key) => key !== 'id' && String(key) !== '_id')
|
|
273
|
-
: undefined;
|
|
274
|
-
if (Array.isArray(positiveProjectionFields)) {
|
|
275
|
-
projection = {
|
|
276
|
-
_id: 0,
|
|
277
|
-
id: { $toString: '$_id' },
|
|
278
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
const doc = await this.ownershipInfoModel.findOne({ _id: { $eq: params.id } }, projection)
|
|
282
|
-
.lean() // lean(2024-08-15~)
|
|
283
|
-
.exec();
|
|
284
|
-
if (doc === null) {
|
|
285
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
286
|
-
}
|
|
287
|
-
return doc;
|
|
288
|
-
}
|
|
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
|
+
// }
|
|
289
88
|
/**
|
|
290
89
|
* 所有権を検索する
|
|
291
90
|
*/
|
|
292
|
-
async
|
|
91
|
+
async findOwnershipInfos(params, inclusion) {
|
|
293
92
|
const conditions = OwnershipInfoRepo.CREATE_MONGO_CONDITIONS(params);
|
|
294
93
|
let projection = {
|
|
295
94
|
_id: 0,
|
|
@@ -327,140 +126,5 @@ class OwnershipInfoRepo {
|
|
|
327
126
|
.lean() // lean(2024-08-19~)
|
|
328
127
|
.exec();
|
|
329
128
|
}
|
|
330
|
-
/**
|
|
331
|
-
* 識別子から所有期限を変更する
|
|
332
|
-
* 存在しない場合undefinedを返す
|
|
333
|
-
*/
|
|
334
|
-
async findByIdentifierAndUpdateOwnedThrough(params) {
|
|
335
|
-
return this.ownershipInfoModel.findOneAndUpdate({
|
|
336
|
-
'project.id': { $eq: params.project.id },
|
|
337
|
-
identifier: { $eq: String(params.identifier) }
|
|
338
|
-
}, { ownedThrough: params.ownedThrough }, {
|
|
339
|
-
new: true,
|
|
340
|
-
projection: {
|
|
341
|
-
_id: 0,
|
|
342
|
-
id: { $toString: '$_id' },
|
|
343
|
-
identifier: 1
|
|
344
|
-
}
|
|
345
|
-
})
|
|
346
|
-
.lean()
|
|
347
|
-
.exec()
|
|
348
|
-
.then((doc) => {
|
|
349
|
-
// 存在しない場合も正常にハンドルする
|
|
350
|
-
if (doc === null) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
return doc;
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* 所有者の所有権を全て削除する
|
|
360
|
-
*/
|
|
361
|
-
async deleteByOwnedById(params) {
|
|
362
|
-
return this.ownershipInfoModel.deleteMany({
|
|
363
|
-
'project.id': { $eq: params.project.id },
|
|
364
|
-
'ownedBy.id': { $exists: true, $eq: params.ownedBy.id }
|
|
365
|
-
})
|
|
366
|
-
.exec()
|
|
367
|
-
.then((deleteOneResult) => {
|
|
368
|
-
return {
|
|
369
|
-
// n: deleteOneResult?.n,
|
|
370
|
-
// ok: deleteOneResult?.ok,
|
|
371
|
-
deletedCount: deleteOneResult?.deletedCount
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* 特定所有者の特定所有権を削除する
|
|
377
|
-
*/
|
|
378
|
-
async deleteByIdAndOwnedById(params) {
|
|
379
|
-
return this.ownershipInfoModel.deleteOne({
|
|
380
|
-
_id: { $eq: params.id },
|
|
381
|
-
'project.id': { $eq: params.project.id },
|
|
382
|
-
'ownedBy.id': { $exists: true, $eq: params.ownedBy.id }
|
|
383
|
-
})
|
|
384
|
-
.exec()
|
|
385
|
-
.then((deleteOneResult) => {
|
|
386
|
-
return {
|
|
387
|
-
// n: deleteOneResult?.n,
|
|
388
|
-
// ok: deleteOneResult?.ok,
|
|
389
|
-
deletedCount: deleteOneResult?.deletedCount
|
|
390
|
-
};
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* 識別子から所有期限切れの所有権を削除する
|
|
395
|
-
*/
|
|
396
|
-
async deleteExpiredByIdentifiers(params) {
|
|
397
|
-
await this.ownershipInfoModel.deleteMany({
|
|
398
|
-
'project.id': { $eq: params.project.id },
|
|
399
|
-
identifier: { $in: params.identifiers },
|
|
400
|
-
// 所有期限切れのもの(ownedThroughは必ず存在する)
|
|
401
|
-
ownedThrough: { $lte: params.ownedThrough.$lte }
|
|
402
|
-
})
|
|
403
|
-
.exec();
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* 所有期限切れの所有権を削除する
|
|
407
|
-
*/
|
|
408
|
-
async deleteExpiredOwnershipInfos(params) {
|
|
409
|
-
await this.ownershipInfoModel.deleteMany({
|
|
410
|
-
// 所有期限切れのもの(ownedThroughは必ず存在する)
|
|
411
|
-
ownedThrough: { $lte: params.ownedThroughLte }
|
|
412
|
-
})
|
|
413
|
-
.exec();
|
|
414
|
-
}
|
|
415
|
-
getCursor(conditions, projection) {
|
|
416
|
-
return this.ownershipInfoModel.find(conditions, projection)
|
|
417
|
-
.sort({ ownedFrom: factory_1.factory.sortType.Ascending })
|
|
418
|
-
.cursor();
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* 所有者を追加する
|
|
422
|
-
*/
|
|
423
|
-
async addOwnerIfNotExist(params) {
|
|
424
|
-
if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
425
|
-
throw new factory_1.factory.errors.ArgumentNull('ownedBy.id');
|
|
426
|
-
}
|
|
427
|
-
let newOwner;
|
|
428
|
-
if (params.ownedBy.typeOf === factory_1.factory.personType.Person) {
|
|
429
|
-
newOwner = {
|
|
430
|
-
id: params.ownedBy.id,
|
|
431
|
-
typeOf: params.ownedBy.typeOf
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
if (newOwner !== undefined) {
|
|
435
|
-
const doc = await this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $addToSet: { ownedBy: newOwner } }, {
|
|
436
|
-
new: true,
|
|
437
|
-
projection: { _id: 1 }
|
|
438
|
-
})
|
|
439
|
-
.exec();
|
|
440
|
-
if (doc === null) {
|
|
441
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
/**
|
|
446
|
-
* 所有者を削除する
|
|
447
|
-
*/
|
|
448
|
-
async removeOwnerIfExist(params) {
|
|
449
|
-
if (typeof params.ownedBy.id !== 'string' || params.ownedBy.id.length === 0) {
|
|
450
|
-
throw new factory_1.factory.errors.ArgumentNull('ownedBy.id');
|
|
451
|
-
}
|
|
452
|
-
const doc = await this.ownershipInfoModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $pull: { ownedBy: { id: params.ownedBy.id } } }, {
|
|
453
|
-
new: true,
|
|
454
|
-
projection: { _id: 1 }
|
|
455
|
-
})
|
|
456
|
-
.exec();
|
|
457
|
-
if (doc === null) {
|
|
458
|
-
throw new factory_1.factory.errors.NotFound(this.ownershipInfoModel.modelName);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
async unsetUnnecessaryFields(params) {
|
|
462
|
-
return this.ownershipInfoModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
463
|
-
.exec();
|
|
464
|
-
}
|
|
465
129
|
}
|
|
466
130
|
exports.OwnershipInfoRepo = OwnershipInfoRepo;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
2
|
import { factory } from '../factory';
|
|
3
|
-
import { IDocType } from './mongoose/schemas/task';
|
|
4
3
|
/**
|
|
5
4
|
* リトライ可能なタスク作成属性
|
|
6
5
|
*/
|
|
@@ -39,9 +38,31 @@ export declare class TaskRepo {
|
|
|
39
38
|
reservationFor: {
|
|
40
39
|
id: string;
|
|
41
40
|
};
|
|
42
|
-
}): Promise<(import("mongoose").
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
}): Promise<(import("mongoose").FlattenMaps<{
|
|
42
|
+
name: factory.taskName;
|
|
43
|
+
description?: string | undefined;
|
|
44
|
+
project: {
|
|
45
|
+
id: string;
|
|
46
|
+
typeOf: factory.organizationType.Project;
|
|
47
|
+
};
|
|
48
|
+
identifier?: string | undefined;
|
|
49
|
+
data: import("@chevre/factory/lib/chevre/task").IData;
|
|
50
|
+
status: factory.taskStatus;
|
|
51
|
+
runsAt: Date;
|
|
52
|
+
dateAborted?: Date | undefined;
|
|
53
|
+
executionResults: {
|
|
54
|
+
executedAt: Date;
|
|
55
|
+
endDate: Date;
|
|
56
|
+
error: string | import("@chevre/factory/lib/chevre/task").IExecutionErrorAsObject;
|
|
57
|
+
}[];
|
|
58
|
+
executor?: {
|
|
59
|
+
name: string;
|
|
60
|
+
} | undefined;
|
|
61
|
+
lastTriedAt?: Date | undefined;
|
|
62
|
+
remainingNumberOfTries: number;
|
|
63
|
+
numberOfTried: number;
|
|
64
|
+
expires?: never | undefined;
|
|
65
|
+
}> & {
|
|
45
66
|
_id: import("mongoose").Types.ObjectId;
|
|
46
67
|
} & {
|
|
47
68
|
__v: number;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -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;
|