@chevre/domain 21.18.0-alpha.0 → 21.18.0-alpha.10
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/example/src/chevre/report2developers.ts +36 -0
- package/example/src/chevre/searchAcceptedOfferIds.ts +57 -0
- package/example/src/chevre/searchOrderAcceptedOffers.ts +12 -12
- package/example/src/chevre/searchOrders.ts +25 -19
- package/example/src/chevre/transaction/processReturnOrder.ts +1 -0
- package/example/src/chevre/upsertMoviesByIdentifier.ts +57 -0
- package/example/src/duration.ts +22 -0
- package/example/src/fetch.ts +45 -0
- package/lib/chevre/repo/acceptedOffer.d.ts +64 -0
- package/lib/chevre/repo/acceptedOffer.js +184 -0
- package/lib/chevre/repo/creativeWork.d.ts +5 -1
- package/lib/chevre/repo/creativeWork.js +43 -22
- package/lib/chevre/repo/offerCatalog.d.ts +8 -2
- package/lib/chevre/repo/offerCatalog.js +8 -8
- package/lib/chevre/repo/order.d.ts +3 -47
- package/lib/chevre/repo/order.js +31 -171
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -1
- package/lib/chevre/service/assetTransaction/pay/potentialActions.d.ts +3 -1
- package/lib/chevre/service/assetTransaction/pay/potentialActions.js +1 -1
- package/lib/chevre/service/assetTransaction/pay.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/pay.js +9 -5
- package/lib/chevre/service/notification.d.ts +9 -2
- package/lib/chevre/service/notification.js +161 -54
- package/lib/chevre/service/order/confirmPayTransaction.d.ts +2 -0
- package/lib/chevre/service/order/confirmPayTransaction.js +1 -0
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.d.ts +0 -3
- package/lib/chevre/service/order/onAssetTransactionStatusChanged.js +2 -4
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.d.ts +11 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled/factory.js +54 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderCancelled.js +38 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.d.ts +12 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered/factory.js +111 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderDelivered.js +83 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +103 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.d.ts +23 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +239 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.d.ts +13 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing.js +216 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.d.ts +10 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned/factory.js +110 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.d.ts +14 -0
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderReturned.js +164 -0
- package/lib/chevre/service/order/onOrderStatusChanged.d.ts +9 -15
- package/lib/chevre/service/order/onOrderStatusChanged.js +11 -446
- package/lib/chevre/service/order/onOrderUpdated/factory.d.ts +6 -0
- package/lib/chevre/service/order/onOrderUpdated/factory.js +45 -0
- package/lib/chevre/service/order/onOrderUpdated.js +1 -1
- package/lib/chevre/service/order/payOrder.d.ts +0 -2
- package/lib/chevre/service/order/placeOrder.d.ts +0 -3
- package/lib/chevre/service/order/placeOrder.js +5 -10
- package/lib/chevre/service/order/returnOrder.d.ts +2 -2
- package/lib/chevre/service/order/returnOrder.js +9 -6
- package/lib/chevre/service/order/sendOrder.js +4 -3
- package/lib/chevre/service/order.d.ts +2 -2
- package/lib/chevre/service/order.js +2 -2
- package/lib/chevre/service/task/confirmPayTransaction.js +2 -1
- package/lib/chevre/service/task/onAssetTransactionStatusChanged.js +3 -6
- package/lib/chevre/service/task/onAuthorizationCreated.js +28 -18
- package/lib/chevre/service/task/onOrderPaymentCompleted.js +3 -6
- package/lib/chevre/service/task/placeOrder.js +8 -17
- package/lib/chevre/service/task/returnOrder.js +10 -17
- package/lib/chevre/service/task/triggerWebhook.js +5 -2
- package/lib/chevre/service/task.js +6 -8
- package/lib/chevre/service/transaction/moneyTransfer.js +3 -4
- package/lib/chevre/service/transaction/returnOrder.d.ts +2 -0
- package/lib/chevre/service/transaction/returnOrder.js +22 -10
- package/lib/chevre/settings.d.ts +1 -0
- package/lib/chevre/settings.js +2 -1
- package/package.json +5 -7
- package/lib/chevre/service/order/onOrderStatusChanged/factory.d.ts +0 -42
- package/lib/chevre/service/order/onOrderStatusChanged/factory.js +0 -467
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const notificationService = await chevre.service.notification.createService();
|
|
12
|
+
|
|
13
|
+
// await notificationService.report2developers(
|
|
14
|
+
// 'xxx',
|
|
15
|
+
// 'xxx'
|
|
16
|
+
// )({ accessToken: String(process.env.LINE_NOTIFY_ACCESS_TOKEN) });
|
|
17
|
+
|
|
18
|
+
await notificationService.triggerWebhook({
|
|
19
|
+
typeOf: chevre.factory.actionType.InformAction,
|
|
20
|
+
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
21
|
+
agent: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
22
|
+
recipient: {
|
|
23
|
+
id: 'xxx',
|
|
24
|
+
url: 'https://example.com',
|
|
25
|
+
typeOf: chevre.factory.creativeWorkType.WebApplication
|
|
26
|
+
},
|
|
27
|
+
object: { sample: 'sample' }
|
|
28
|
+
})({
|
|
29
|
+
action: await chevre.repository.Action.createInstance(mongoose.connection),
|
|
30
|
+
useFetchAPI: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main()
|
|
35
|
+
.then(console.log)
|
|
36
|
+
.catch(console.error);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
+
|
|
11
|
+
const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
let offerIds: string[];
|
|
14
|
+
|
|
15
|
+
// const searchConditions: chevre.factory.order.ISearchConditions = {
|
|
16
|
+
// limit: 10,
|
|
17
|
+
// page: 1,
|
|
18
|
+
// project: { id: { $eq: project.id } },
|
|
19
|
+
// orderNumbers: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'],
|
|
20
|
+
// acceptedOffers: { itemOffered: { typeOf: { $in: [chevre.factory.reservationType.EventReservation] } } }
|
|
21
|
+
// };
|
|
22
|
+
// let offerIds = await acceptedOfferRepo.__searchAcceptedOfferIds(searchConditions);
|
|
23
|
+
// console.log(offerIds);
|
|
24
|
+
offerIds = await acceptedOfferRepo.distinctValues(
|
|
25
|
+
{ orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
|
|
26
|
+
'acceptedOffers.id'
|
|
27
|
+
);
|
|
28
|
+
console.log(offerIds);
|
|
29
|
+
|
|
30
|
+
const productIds = await acceptedOfferRepo.distinctValues(
|
|
31
|
+
{ orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
|
|
32
|
+
'acceptedOffers.itemOffered.issuedThrough.id'
|
|
33
|
+
);
|
|
34
|
+
console.log(productIds);
|
|
35
|
+
|
|
36
|
+
const locationBranchCodes = await acceptedOfferRepo.distinctValues(
|
|
37
|
+
{ orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
|
|
38
|
+
'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode'
|
|
39
|
+
);
|
|
40
|
+
console.log(locationBranchCodes);
|
|
41
|
+
|
|
42
|
+
const offeredThroughIdentifiers = await acceptedOfferRepo.distinctValues(
|
|
43
|
+
{ orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
|
|
44
|
+
'acceptedOffers.offeredThrough.identifier'
|
|
45
|
+
);
|
|
46
|
+
console.log(offeredThroughIdentifiers);
|
|
47
|
+
|
|
48
|
+
const invalidValues = await acceptedOfferRepo.distinctValues(
|
|
49
|
+
{ orderNumber: { $in: ['CIN1-3743286-2441943', 'CIN4-3943511-3323473'] } },
|
|
50
|
+
<any>'invalidValues'
|
|
51
|
+
);
|
|
52
|
+
console.log(invalidValues);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main()
|
|
56
|
+
.then()
|
|
57
|
+
.catch(console.error);
|
|
@@ -8,19 +8,19 @@ const project = { id: String(process.env.PROJECT_ID) };
|
|
|
8
8
|
async function main() {
|
|
9
9
|
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const acceptedOfferRepo = await chevre.repository.AcceptedOffer.createInstance(mongoose.connection);
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
const acceptedOffers = await acceptedOfferRepo.searchAcceptedOffersByOrderNumber(
|
|
14
|
+
{
|
|
15
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
16
|
+
limit: 10,
|
|
17
|
+
page: 1,
|
|
18
|
+
project: { id: { $eq: project.id } },
|
|
19
|
+
orderNumber: { $eq: 'CIN3-0760465-8981560' },
|
|
20
|
+
acceptedOffers: { itemOffered: { typeOf: { $in: [chevre.factory.reservationType.EventReservation] } } }
|
|
21
|
+
},
|
|
22
|
+
['itemOffered', 'id']
|
|
23
|
+
);
|
|
24
24
|
// tslint:disable-next-line:no-null-keyword
|
|
25
25
|
console.dir(acceptedOffers, { depth: 1 });
|
|
26
26
|
const reservationIds = acceptedOffers.map((acceptedOffer) => {
|
|
@@ -10,28 +10,34 @@ async function main() {
|
|
|
10
10
|
|
|
11
11
|
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
12
12
|
|
|
13
|
-
const orders = await orderRepo.search(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
const orders = await orderRepo.search(
|
|
14
|
+
{
|
|
15
|
+
limit: 10,
|
|
16
|
+
project: { id: { $eq: project.id } },
|
|
17
|
+
acceptedOffers: {
|
|
18
|
+
// $size: 1
|
|
19
|
+
// itemOffered: {
|
|
20
|
+
// issuedThrough: { typeOf: { $eq: chevre.factory.product.ProductType.MembershipService } }
|
|
21
|
+
// }
|
|
22
|
+
},
|
|
23
|
+
orderedItem: {
|
|
24
|
+
$size: 3
|
|
25
|
+
}
|
|
26
|
+
// paymentMethods: {
|
|
27
|
+
// paymentMethod: { identifier: { $in: ['Cash'] } }
|
|
28
|
+
// additionalProperty: {
|
|
29
|
+
// $in: [
|
|
30
|
+
// { name: 'orderId', value: '0102022031518442020' },
|
|
31
|
+
// { name: 'orderId', value: '0102022031518423030' }
|
|
32
|
+
// ]
|
|
20
33
|
// }
|
|
34
|
+
// }
|
|
21
35
|
},
|
|
22
|
-
|
|
23
|
-
|
|
36
|
+
{
|
|
37
|
+
orderNumber: 1,
|
|
38
|
+
customer: 1
|
|
24
39
|
}
|
|
25
|
-
|
|
26
|
-
// paymentMethod: { identifier: { $in: ['Cash'] } }
|
|
27
|
-
// additionalProperty: {
|
|
28
|
-
// $in: [
|
|
29
|
-
// { name: 'orderId', value: '0102022031518442020' },
|
|
30
|
-
// { name: 'orderId', value: '0102022031518423030' }
|
|
31
|
-
// ]
|
|
32
|
-
// }
|
|
33
|
-
// }
|
|
34
|
-
});
|
|
40
|
+
);
|
|
35
41
|
console.log('orders found', orders);
|
|
36
42
|
console.log(orders.length, 'orders found');
|
|
37
43
|
}
|
|
@@ -23,6 +23,7 @@ async function main() {
|
|
|
23
23
|
id: 'xxx'
|
|
24
24
|
}
|
|
25
25
|
})({
|
|
26
|
+
acceptedOffer: await chevre.repository.AcceptedOffer.createInstance(mongoose.connection),
|
|
26
27
|
event: await chevre.repository.Event.createInstance(mongoose.connection),
|
|
27
28
|
merchantReturnPolicy: await chevre.repository.MerchantReturnPolicy.createInstance(mongoose.connection),
|
|
28
29
|
offer: await chevre.repository.Offer.createInstance(mongoose.connection),
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
+
|
|
12
|
+
const creativeWorkRepo = await chevre.repository.CreativeWork.createInstance(mongoose.connection);
|
|
13
|
+
|
|
14
|
+
const result = await creativeWorkRepo.upsertMoviesByIdentifier(
|
|
15
|
+
[
|
|
16
|
+
{
|
|
17
|
+
attributes: {
|
|
18
|
+
id: '',
|
|
19
|
+
identifier: '00001',
|
|
20
|
+
typeOf: chevre.factory.creativeWorkType.Movie,
|
|
21
|
+
duration: 'PT2H',
|
|
22
|
+
name: { ja: '名探偵コナン ゼロの執行人', en: 'Detective Conan Zero Enforcer' },
|
|
23
|
+
offers: {
|
|
24
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
25
|
+
availabilityEnds: moment('2118-11-04T15:00:00.000Z')
|
|
26
|
+
.toDate(),
|
|
27
|
+
availabilityStarts: moment('2018-11-25T15:00:00.000Z')
|
|
28
|
+
.toDate()
|
|
29
|
+
},
|
|
30
|
+
project: { typeOf: chevre.factory.organizationType.Project, id: PROJECT_ID },
|
|
31
|
+
additionalProperty: [
|
|
32
|
+
{
|
|
33
|
+
name: 'posterImage',
|
|
34
|
+
value: 'https://iwiz-movies.c.yimg.jp/c/movies/pict/p/p/90/cb/174755_02.jpg'
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
headline: 'サブタイトルサブタイトルサブタイトル',
|
|
38
|
+
datePublished: moment('2018-11-04T15:00:00.000Z')
|
|
39
|
+
.toDate(),
|
|
40
|
+
distributor: {
|
|
41
|
+
id: '5e35398a8067a30012dd6717',
|
|
42
|
+
codeValue: '001',
|
|
43
|
+
...{
|
|
44
|
+
distributorType: '001'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
],
|
|
50
|
+
{ replace: true }
|
|
51
|
+
);
|
|
52
|
+
console.log('result:', result);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main()
|
|
56
|
+
.then(console.log)
|
|
57
|
+
.catch(console.error);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
|
|
4
|
+
const MINUTES = 10;
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
const duration = moment.duration(MINUTES, 'minutes');
|
|
8
|
+
const newDuration = moment.duration(duration.toISOString());
|
|
9
|
+
console.log(duration);
|
|
10
|
+
console.log(newDuration);
|
|
11
|
+
console.log(duration.toISOString());
|
|
12
|
+
console.log(newDuration.toISOString());
|
|
13
|
+
console.log(newDuration.isValid());
|
|
14
|
+
console.log(moment.duration('invalid')
|
|
15
|
+
.isValid());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
main()
|
|
19
|
+
.then(() => {
|
|
20
|
+
console.log('success!');
|
|
21
|
+
})
|
|
22
|
+
.catch(console.error);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
const url = String(process.env.LINE_NOTIFY_URL);
|
|
3
|
+
const LINE_NOTIFY_ACCESS_TOKEN = String(process.env.LINE_NOTIFY_ACCESS_TOKEN);
|
|
4
|
+
const TIMEOUT = 5000;
|
|
5
|
+
const MESSAGE = 'sample message';
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
try {
|
|
9
|
+
const form = new FormData();
|
|
10
|
+
form.set('message', `${MESSAGE} ${(new Date()).toString()}`);
|
|
11
|
+
|
|
12
|
+
const res = await fetch(
|
|
13
|
+
url,
|
|
14
|
+
{
|
|
15
|
+
signal: AbortSignal.timeout(TIMEOUT),
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
Authorization: `Bearer ${LINE_NOTIFY_ACCESS_TOKEN}`
|
|
19
|
+
},
|
|
20
|
+
body: form
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
const result = await res.json();
|
|
24
|
+
console.log('result', result);
|
|
25
|
+
} catch (err) {
|
|
26
|
+
console.error(err);
|
|
27
|
+
if (err.name === 'TimeoutError') {
|
|
28
|
+
console.error('Timeout: It took more than 5 seconds to get the result!');
|
|
29
|
+
} else if (err.name === 'AbortError') {
|
|
30
|
+
console.error('Fetch aborted by user action (browser stop button, closing tab, etc.');
|
|
31
|
+
} else if (err.name === 'TypeError') {
|
|
32
|
+
console.error('AbortSignal.timeout() method is not supported');
|
|
33
|
+
} else {
|
|
34
|
+
// A network error, or some other problem.
|
|
35
|
+
console.error(`Error: type: ${err.name}, message: ${err.message}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
main()
|
|
42
|
+
.then(() => {
|
|
43
|
+
console.log('success!');
|
|
44
|
+
})
|
|
45
|
+
.catch(console.error);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
type IProjection4searchWithUnwoundAcceptedOffers = {
|
|
4
|
+
[key in keyof Omit<factory.order.IOrder, 'acceptedOffers'>]?: 1;
|
|
5
|
+
} & {
|
|
6
|
+
_id?: 0 | 1;
|
|
7
|
+
};
|
|
8
|
+
type IDistinctField = 'acceptedOffers.id' | 'acceptedOffers.itemOffered.reservationNumber' | 'acceptedOffers.itemOffered.reservationFor.id' | 'acceptedOffers.itemOffered.issuedThrough.id' | 'acceptedOffers.offeredThrough.identifier' | 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode';
|
|
9
|
+
/**
|
|
10
|
+
* 注文オファーリポジトリ
|
|
11
|
+
*/
|
|
12
|
+
export declare class MongoRepository {
|
|
13
|
+
private readonly orderModel;
|
|
14
|
+
constructor(connection: Connection);
|
|
15
|
+
/**
|
|
16
|
+
* オファー展開の注文検索
|
|
17
|
+
*/
|
|
18
|
+
searchWithUnwoundAcceptedOffers(params: factory.order.ISearchConditions, projection?: IProjection4searchWithUnwoundAcceptedOffers): Promise<factory.order.IOrder[]>;
|
|
19
|
+
/**
|
|
20
|
+
* 注文オファーを展開して検索する
|
|
21
|
+
*/
|
|
22
|
+
searchAcceptedOffersByOrderNumber(filter: {
|
|
23
|
+
limit?: number;
|
|
24
|
+
page?: number;
|
|
25
|
+
orderNumber: {
|
|
26
|
+
$eq: string;
|
|
27
|
+
};
|
|
28
|
+
project: {
|
|
29
|
+
id: {
|
|
30
|
+
$eq: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* アイテムタイプで絞る場合
|
|
35
|
+
*/
|
|
36
|
+
acceptedOffers?: {
|
|
37
|
+
itemOffered?: {
|
|
38
|
+
typeOf?: {
|
|
39
|
+
$in?: string[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}, inclusion?: (keyof factory.order.IAcceptedOffer<factory.order.IItemOffered>)[]): Promise<factory.order.IAcceptedOffer<factory.order.IItemOffered>[]>;
|
|
44
|
+
/**
|
|
45
|
+
* 特定のフィールド値リストを検索する
|
|
46
|
+
*/
|
|
47
|
+
distinctValues(filter: {
|
|
48
|
+
orderNumber: {
|
|
49
|
+
$in: string[];
|
|
50
|
+
};
|
|
51
|
+
}, field: IDistinctField): Promise<string[]>;
|
|
52
|
+
/**
|
|
53
|
+
* 注文に含まれるacceptedOffersを検索する
|
|
54
|
+
*/
|
|
55
|
+
searchAcceptedOffersByOrderNumbers(params: {
|
|
56
|
+
orderNumber: {
|
|
57
|
+
$in: string[];
|
|
58
|
+
};
|
|
59
|
+
}): Promise<{
|
|
60
|
+
id: string;
|
|
61
|
+
priceSpecification: factory.order.ITicketPriceSpecification;
|
|
62
|
+
}[]>;
|
|
63
|
+
}
|
|
64
|
+
export {};
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.MongoRepository = void 0;
|
|
13
|
+
const order_1 = require("./mongoose/schemas/order");
|
|
14
|
+
const order_2 = require("./order");
|
|
15
|
+
const settings_1 = require("../settings");
|
|
16
|
+
/**
|
|
17
|
+
* 注文オファーリポジトリ
|
|
18
|
+
*/
|
|
19
|
+
class MongoRepository {
|
|
20
|
+
constructor(connection) {
|
|
21
|
+
this.orderModel = connection.model(order_1.modelName, (0, order_1.createSchema)());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* オファー展開の注文検索
|
|
25
|
+
*/
|
|
26
|
+
searchWithUnwoundAcceptedOffers(params, projection) {
|
|
27
|
+
var _a;
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const conditions = order_2.MongoRepository.CREATE_MONGO_CONDITIONS(params);
|
|
30
|
+
const aggregate = this.orderModel.aggregate();
|
|
31
|
+
// pipelineの順序に注意
|
|
32
|
+
// @see https://docs.mongodb.com/manual/reference/operator/aggregation/sort/
|
|
33
|
+
// tslint:disable-next-line:no-single-line-block-comment
|
|
34
|
+
/* istanbul ignore else */
|
|
35
|
+
if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.orderDate) === 'number') {
|
|
36
|
+
aggregate.sort({ orderDate: params.sort.orderDate });
|
|
37
|
+
}
|
|
38
|
+
aggregate.unwind('$acceptedOffers');
|
|
39
|
+
conditions.forEach((c) => {
|
|
40
|
+
aggregate.match(c);
|
|
41
|
+
});
|
|
42
|
+
aggregate.project(Object.assign(Object.assign({}, projection), { acceptedOffers: ['$acceptedOffers'] }));
|
|
43
|
+
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
44
|
+
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
45
|
+
aggregate.limit(params.limit * page)
|
|
46
|
+
.skip(params.limit * (page - 1));
|
|
47
|
+
}
|
|
48
|
+
return aggregate
|
|
49
|
+
// .allowDiskUse(true) // false化(2023-11-30~)
|
|
50
|
+
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
51
|
+
.exec();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 注文オファーを展開して検索する
|
|
56
|
+
*/
|
|
57
|
+
searchAcceptedOffersByOrderNumber(filter, inclusion) {
|
|
58
|
+
var _a, _b, _c;
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const matchStages = [
|
|
61
|
+
{ $match: { 'project.id': { $eq: filter.project.id.$eq } } },
|
|
62
|
+
{ $match: { orderNumber: { $eq: filter.orderNumber.$eq } } }
|
|
63
|
+
];
|
|
64
|
+
const itemOfferedTypeOfIn = (_c = (_b = (_a = filter.acceptedOffers) === null || _a === void 0 ? void 0 : _a.itemOffered) === null || _b === void 0 ? void 0 : _b.typeOf) === null || _c === void 0 ? void 0 : _c.$in;
|
|
65
|
+
if (Array.isArray(itemOfferedTypeOfIn)) {
|
|
66
|
+
matchStages.push({
|
|
67
|
+
$match: { 'acceptedOffers.itemOffered.typeOf': { $exists: true, $in: itemOfferedTypeOfIn } }
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const aggregate = this.orderModel.aggregate([
|
|
71
|
+
// if (typeof params.sort?.orderDate === 'number') {
|
|
72
|
+
// aggregate.sort({ orderDate: params.sort.orderDate });
|
|
73
|
+
// }
|
|
74
|
+
{
|
|
75
|
+
$unwind: {
|
|
76
|
+
path: '$acceptedOffers'
|
|
77
|
+
// includeArrayIndex: 'elementIndex'
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
...matchStages
|
|
81
|
+
]);
|
|
82
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
83
|
+
const specifiedProjection = {
|
|
84
|
+
_id: 0
|
|
85
|
+
};
|
|
86
|
+
inclusion.forEach((key) => {
|
|
87
|
+
specifiedProjection[key] = `$acceptedOffers.${key}`;
|
|
88
|
+
});
|
|
89
|
+
aggregate.project(specifiedProjection);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
aggregate.project({
|
|
93
|
+
_id: 0,
|
|
94
|
+
itemOffered: '$acceptedOffers.itemOffered',
|
|
95
|
+
priceSpecification: '$acceptedOffers.priceSpecification',
|
|
96
|
+
typeOf: '$acceptedOffers.typeOf',
|
|
97
|
+
id: '$acceptedOffers.id',
|
|
98
|
+
offeredThrough: '$acceptedOffers.offeredThrough',
|
|
99
|
+
name: '$acceptedOffers.name'
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (typeof filter.limit === 'number' && filter.limit > 0) {
|
|
103
|
+
const page = (typeof filter.page === 'number' && filter.page > 0) ? filter.page : 1;
|
|
104
|
+
aggregate.limit(filter.limit * page)
|
|
105
|
+
.skip(filter.limit * (page - 1));
|
|
106
|
+
}
|
|
107
|
+
return aggregate
|
|
108
|
+
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
109
|
+
.exec();
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 特定のフィールド値リストを検索する
|
|
114
|
+
*/
|
|
115
|
+
distinctValues(filter, field) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (!Array.isArray(filter.orderNumber.$in) || filter.orderNumber.$in.length === 0) {
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
const filterQuery = {
|
|
121
|
+
orderNumber: { $in: filter.orderNumber.$in }
|
|
122
|
+
};
|
|
123
|
+
filterQuery[field] = { $exists: true };
|
|
124
|
+
return this.orderModel.distinct(field, filterQuery)
|
|
125
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
126
|
+
.exec();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
// public async searchReservationNumbersByOrderNumbers(
|
|
130
|
+
// params: {
|
|
131
|
+
// orderNumber: { $in: string[] };
|
|
132
|
+
// }
|
|
133
|
+
// ): Promise<(string)[]> {
|
|
134
|
+
// if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
135
|
+
// return [];
|
|
136
|
+
// }
|
|
137
|
+
// return this.orderModel.distinct(
|
|
138
|
+
// 'acceptedOffers.itemOffered.reservationNumber',
|
|
139
|
+
// {
|
|
140
|
+
// 'acceptedOffers.itemOffered.reservationNumber': { $exists: true },
|
|
141
|
+
// orderNumber: { $in: params.orderNumber.$in }
|
|
142
|
+
// })
|
|
143
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
144
|
+
// .exec();
|
|
145
|
+
// }
|
|
146
|
+
// public async searchReservationForIdsByOrderNumbers(
|
|
147
|
+
// params: {
|
|
148
|
+
// orderNumber: { $in: string[] };
|
|
149
|
+
// }
|
|
150
|
+
// ): Promise<string[]> {
|
|
151
|
+
// if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
152
|
+
// return [];
|
|
153
|
+
// }
|
|
154
|
+
// return this.orderModel.distinct(
|
|
155
|
+
// 'acceptedOffers.itemOffered.reservationFor.id',
|
|
156
|
+
// {
|
|
157
|
+
// 'acceptedOffers.itemOffered.reservationFor.id': { $exists: true },
|
|
158
|
+
// orderNumber: { $in: params.orderNumber.$in }
|
|
159
|
+
// })
|
|
160
|
+
// .setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
161
|
+
// .exec();
|
|
162
|
+
// }
|
|
163
|
+
/**
|
|
164
|
+
* 注文に含まれるacceptedOffersを検索する
|
|
165
|
+
*/
|
|
166
|
+
searchAcceptedOffersByOrderNumbers(params) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
if (!Array.isArray(params.orderNumber.$in) || params.orderNumber.$in.length === 0) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const aggregate = this.orderModel.aggregate();
|
|
172
|
+
aggregate.unwind('$acceptedOffers');
|
|
173
|
+
aggregate.match({ orderNumber: { $in: params.orderNumber.$in } });
|
|
174
|
+
aggregate.project({
|
|
175
|
+
_id: 0,
|
|
176
|
+
id: '$acceptedOffers.id',
|
|
177
|
+
priceSpecification: '$acceptedOffers.priceSpecification'
|
|
178
|
+
});
|
|
179
|
+
return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
180
|
+
.exec();
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.MongoRepository = MongoRepository;
|
|
@@ -42,7 +42,11 @@ export declare class MongoRepository {
|
|
|
42
42
|
*/
|
|
43
43
|
upsertMoviesByIdentifier(params: {
|
|
44
44
|
attributes: factory.creativeWork.movie.ICreativeWork;
|
|
45
|
-
}[]
|
|
45
|
+
}[], options?: {
|
|
46
|
+
replace?: boolean;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
bulkWriteResult: BulkWriteResult;
|
|
49
|
+
} | void>;
|
|
46
50
|
/**
|
|
47
51
|
* コンテンツを検索する
|
|
48
52
|
*/
|
|
@@ -138,36 +138,57 @@ class MongoRepository {
|
|
|
138
138
|
/**
|
|
139
139
|
* コードをキーにして冪等作成
|
|
140
140
|
*/
|
|
141
|
-
|
|
141
|
+
// tslint:disable-next-line:max-func-body-length
|
|
142
|
+
upsertMoviesByIdentifier(params, options) {
|
|
142
143
|
return __awaiter(this, void 0, void 0, function* () {
|
|
143
144
|
const bulkWriteOps = [];
|
|
144
145
|
if (Array.isArray(params)) {
|
|
145
146
|
params.forEach((creatingMovieParams) => {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
if ((options === null || options === void 0 ? void 0 : options.replace) === true) {
|
|
148
|
+
const _a = creatingMovieParams.attributes, { id } = _a, replaceFields = __rest(_a, ["id"]);
|
|
149
|
+
if (typeof replaceFields.identifier !== 'string' || replaceFields.identifier.length === 0) {
|
|
150
|
+
throw new factory.errors.ArgumentNull('identifier');
|
|
151
|
+
}
|
|
152
|
+
const replacement = replaceFields;
|
|
153
|
+
const replaceOne = {
|
|
154
|
+
filter: {
|
|
155
|
+
typeOf: replaceFields.typeOf,
|
|
156
|
+
'project.id': { $eq: replaceFields.project.id },
|
|
157
|
+
identifier: { $eq: replaceFields.identifier }
|
|
158
|
+
},
|
|
159
|
+
replacement,
|
|
160
|
+
upsert: true
|
|
161
|
+
};
|
|
162
|
+
bulkWriteOps.push({ replaceOne });
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const _b = creatingMovieParams.attributes, { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = _b, setOnInsertFields = __rest(_b, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
|
|
166
|
+
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
167
|
+
throw new factory.errors.ArgumentNull('identifier');
|
|
168
|
+
}
|
|
169
|
+
const updateFilter = {
|
|
170
|
+
$setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
|
|
171
|
+
project,
|
|
172
|
+
identifier }),
|
|
173
|
+
// 変更可能な属性のみ上書き
|
|
174
|
+
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
|
|
175
|
+
};
|
|
176
|
+
const updateOne = {
|
|
177
|
+
filter: {
|
|
178
|
+
typeOf: typeOf,
|
|
179
|
+
'project.id': { $eq: project.id },
|
|
180
|
+
identifier: { $eq: identifier }
|
|
181
|
+
},
|
|
182
|
+
update: updateFilter,
|
|
183
|
+
upsert: true
|
|
184
|
+
};
|
|
185
|
+
bulkWriteOps.push({ updateOne });
|
|
149
186
|
}
|
|
150
|
-
const updateFilter = {
|
|
151
|
-
$setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
|
|
152
|
-
project,
|
|
153
|
-
identifier }),
|
|
154
|
-
// 変更可能な属性のみ上書き
|
|
155
|
-
$set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : [])
|
|
156
|
-
};
|
|
157
|
-
const updateOne = {
|
|
158
|
-
filter: {
|
|
159
|
-
typeOf: typeOf,
|
|
160
|
-
'project.id': { $eq: project.id },
|
|
161
|
-
identifier: { $eq: identifier }
|
|
162
|
-
},
|
|
163
|
-
update: updateFilter,
|
|
164
|
-
upsert: true
|
|
165
|
-
};
|
|
166
|
-
bulkWriteOps.push({ updateOne });
|
|
167
187
|
});
|
|
168
188
|
}
|
|
169
189
|
if (bulkWriteOps.length > 0) {
|
|
170
|
-
|
|
190
|
+
const bulkWriteResult = yield this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
191
|
+
return { bulkWriteResult };
|
|
171
192
|
}
|
|
172
193
|
});
|
|
173
194
|
}
|