1 | /**
|
2 | * 注文検索サンプル
|
3 | */
|
4 | const moment = require('moment');
|
5 | const mongoose = require('mongoose');
|
6 | const domain = require('../');
|
7 |
|
8 | async function main() {
|
9 | await mongoose.connect(process.env.MONGOLAB_URI);
|
10 |
|
11 | const orderRepo = new domain.repository.Order(mongoose.connection);
|
12 | const orders = await orderRepo.search({
|
13 | orderDateFrom: moment().add(-3, 'days').toDate(),
|
14 | orderDateThrough: moment().toDate(),
|
15 | // paymentMethods: {
|
16 | // typeOfs: [domain.factory.paymentMethodType.MovieTicket],
|
17 | // paymentMethodIds: ['xxx']
|
18 | // },
|
19 | // seller: { ids: ['xxx'] },
|
20 | // customer: {
|
21 | // ids: ['xxx'],
|
22 | // identifiers: [{ name: '', value: '' }],
|
23 | // givenName: 'xxx'
|
24 | // },
|
25 | // acceptedOffers: {
|
26 | // itemOffered: {
|
27 | // ids: ['xxx'],
|
28 | // reservationFor: { ids: ['xxx'] }
|
29 | // }
|
30 | // },
|
31 | price: { $gte: 500, $lte: 1000 },
|
32 | sort: { orderDate: -1 }
|
33 | });
|
34 | console.log(orders);
|
35 | console.log(orders.length, 'orders found.');
|
36 | console.log(typeof orders[0].id);
|
37 | console.log(typeof orders[0].acceptedOffers);
|
38 | console.log(orders[0].orderDate instanceof Date);
|
39 |
|
40 | // const res = await orderRepo.orderModel.find({
|
41 | // $and: [
|
42 | // { orderDate: { $gte: moment().add(-3, 'days').toDate() } },
|
43 | // { orderDate: { $lte: moment().toDate() } },
|
44 | // { confirmationNumber: { $in: ['0', '517205'] } },
|
45 | // {
|
46 | // 'paymentMethods.typeOf': {
|
47 | // $exists: true,
|
48 | // $in: [domain.factory.paymentMethodType.CreditCard, domain.factory.paymentMethodType.MovieTicket]
|
49 | // }
|
50 | // },
|
51 | // {
|
52 | // 'customer.identifier': {
|
53 | // $exists: true,
|
54 | // $in: [
|
55 | // { name: 'clientId', value: 'xxx' }
|
56 | // ]
|
57 |
|
58 | // }
|
59 | // }
|
60 | // ]
|
61 | // })
|
62 | // .sort({ orderDate: 1 })
|
63 | // .explain();
|
64 | // console.log(res[0].executionStats.allPlansExecution.map((e) => e.executionStages));
|
65 |
|
66 | // await mongoose.disconnect();
|
67 | }
|
68 |
|
69 | main().then(() => {
|
70 | console.log('success!');
|
71 | }).catch((error) => {
|
72 | console.error(error);
|
73 | process.exit(1);
|
74 | });
|