@chevre/domain 22.5.0-alpha.15 → 22.5.0-alpha.16
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/aggregateEventSellerMakesOffer.ts +32 -0
- package/lib/chevre/repo/event.js +53 -0
- package/lib/chevre/repo/eventSellerMakesOffer.d.ts +54 -0
- package/lib/chevre/repo/eventSellerMakesOffer.js +73 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
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 eventSellerMakesOfferRepo = await chevre.repository.EventSellerMakesOffer.createInstance(mongoose.connection);
|
|
12
|
+
const result = await eventSellerMakesOfferRepo.aggregateMakesOffer(
|
|
13
|
+
{
|
|
14
|
+
limit: 10,
|
|
15
|
+
page: 1,
|
|
16
|
+
// id: { $eq: 'bm0f0cadu' },
|
|
17
|
+
// typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
18
|
+
project: { id: { $eq: project.id } },
|
|
19
|
+
availableAtOrFrom: { id: { $eq: '3eo6okferrsdpfd9j2ce1iv9k7' } },
|
|
20
|
+
itemOffered: {
|
|
21
|
+
serviceOutput: { reservationFor: { id: { $in: ['bm0f0cadu', 'blco2394l'] } } }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
// tslint:disable-next-line:no-null-keyword
|
|
26
|
+
console.dir(result, { depth: null });
|
|
27
|
+
console.dir(result.length, 'results found');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
main()
|
|
31
|
+
.then(console.log)
|
|
32
|
+
.catch(console.error);
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -681,6 +681,59 @@ class EventRepo {
|
|
|
681
681
|
.exec();
|
|
682
682
|
});
|
|
683
683
|
}
|
|
684
|
+
// public async aggregateFields<T extends AvailableEventType>(
|
|
685
|
+
// params: ISearchConditions<T>,
|
|
686
|
+
// inclusion: IKeyOfProjection<T>[],
|
|
687
|
+
// makesOffer?: { $filter: { availableAtOrFrom: { id: { $in: string[] } } } }
|
|
688
|
+
// ): Promise<Omit<factory.event.IEvent<T>, 'aggregateEntranceGate' | 'aggregateOffer'>[]> {
|
|
689
|
+
// const conditions = EventRepo.CREATE_MONGO_CONDITIONS<T>(params);
|
|
690
|
+
// const makesOfferAvailableAtOrFromIdIn = makesOffer?.$filter.availableAtOrFrom.id.$in;
|
|
691
|
+
// let projection: ProjectionType<factory.event.IEvent<T>> = {};
|
|
692
|
+
// const positiveProjectionFields: IKeyOfProjection<T>[] = (Array.isArray(inclusion))
|
|
693
|
+
// ? inclusion.filter((key) => key !== 'id' && key !== '_id')
|
|
694
|
+
// : [];
|
|
695
|
+
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
696
|
+
// projection = {
|
|
697
|
+
// _id: 0,
|
|
698
|
+
// id: { $toString: '$_id' },
|
|
699
|
+
// ...(Array.isArray(makesOfferAvailableAtOrFromIdIn))
|
|
700
|
+
// ? {
|
|
701
|
+
// offerByClient: {
|
|
702
|
+
// $filter: {
|
|
703
|
+
// input: '$offers.seller.makesOffer',
|
|
704
|
+
// as: 'item',
|
|
705
|
+
// // cond: { $in: [makesOfferAvailableAtOrFromIdIn, '$$item.availableAtOrFrom.id'] }
|
|
706
|
+
// // cond: { $eq: [$arrayElemAt: [ "'$$item.availableAtOrFrom.$.id'", 0 ], ] }
|
|
707
|
+
// cond: { $in: ['$$item.availableAtOrFrom', makesOfferAvailableAtOrFromIdIn.map((id) => ([{ id }]))] }
|
|
708
|
+
// }
|
|
709
|
+
// }
|
|
710
|
+
// }
|
|
711
|
+
// : undefined,
|
|
712
|
+
// ...Object.fromEntries<1>(positiveProjectionFields.map((key) => ([key, 1])))
|
|
713
|
+
// };
|
|
714
|
+
// } else {
|
|
715
|
+
// // discontinue(2024-07-24~)
|
|
716
|
+
// throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
|
|
717
|
+
// }
|
|
718
|
+
// const aggregate = this.eventModel.aggregate<Omit<factory.event.IEvent<T>, 'aggregateEntranceGate' | 'aggregateOffer'>>([
|
|
719
|
+
// { $match: { $and: conditions } },
|
|
720
|
+
// // { $sort: { _id: factory.sortType.Ascending } },
|
|
721
|
+
// { $project: projection }
|
|
722
|
+
// ]);
|
|
723
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
724
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
725
|
+
// aggregate.limit(params.limit * page)
|
|
726
|
+
// .skip(params.limit * (page - 1));
|
|
727
|
+
// }
|
|
728
|
+
// // tslint:disable-next-line:no-single-line-block-comment
|
|
729
|
+
// /* istanbul ignore else */
|
|
730
|
+
// if (params.sort?.startDate !== undefined) {
|
|
731
|
+
// aggregate.sort({ startDate: params.sort.startDate });
|
|
732
|
+
// }
|
|
733
|
+
// return aggregate
|
|
734
|
+
// .option({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
735
|
+
// .exec();
|
|
736
|
+
// }
|
|
684
737
|
/**
|
|
685
738
|
* IDのみで検索する
|
|
686
739
|
* projectionなし
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
type IAggregateMakesOfferResult = Pick<factory.event.screeningEvent.ISellerMakesOffer, 'availabilityEnds' | 'availabilityStarts' | 'validFrom' | 'validThrough'> & {
|
|
4
|
+
itemOffered: {
|
|
5
|
+
serviceOutput: {
|
|
6
|
+
reservationFor: {
|
|
7
|
+
/**
|
|
8
|
+
* イベントID
|
|
9
|
+
*/
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* イベントの販売者makesOfferリポジトリ
|
|
17
|
+
*/
|
|
18
|
+
export declare class EventSellerMakesOfferRepo {
|
|
19
|
+
private readonly eventModel;
|
|
20
|
+
constructor(connection: Connection);
|
|
21
|
+
/**
|
|
22
|
+
* 指定クライアントのオファーを集計する(2024-10-09~)
|
|
23
|
+
*/
|
|
24
|
+
aggregateMakesOffer(conditions: {
|
|
25
|
+
limit?: number;
|
|
26
|
+
page?: number;
|
|
27
|
+
project: {
|
|
28
|
+
id: {
|
|
29
|
+
$eq: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* アプリケーション(指定必須)
|
|
34
|
+
*/
|
|
35
|
+
availableAtOrFrom: {
|
|
36
|
+
id: {
|
|
37
|
+
$eq: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
itemOffered: {
|
|
41
|
+
serviceOutput: {
|
|
42
|
+
reservationFor: {
|
|
43
|
+
/**
|
|
44
|
+
* イベントID
|
|
45
|
+
*/
|
|
46
|
+
id: {
|
|
47
|
+
$in?: string[];
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}): Promise<IAggregateMakesOfferResult[]>;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
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.EventSellerMakesOfferRepo = void 0;
|
|
13
|
+
const factory = require("../factory");
|
|
14
|
+
const settings_1 = require("../settings");
|
|
15
|
+
const event_1 = require("./mongoose/schemas/event");
|
|
16
|
+
/**
|
|
17
|
+
* イベントの販売者makesOfferリポジトリ
|
|
18
|
+
*/
|
|
19
|
+
class EventSellerMakesOfferRepo {
|
|
20
|
+
constructor(connection) {
|
|
21
|
+
this.eventModel = connection.model(event_1.modelName, (0, event_1.createSchema)());
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 指定クライアントのオファーを集計する(2024-10-09~)
|
|
25
|
+
*/
|
|
26
|
+
aggregateMakesOffer(conditions) {
|
|
27
|
+
var _a;
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const { availableAtOrFrom } = conditions;
|
|
30
|
+
if (typeof ((_a = availableAtOrFrom === null || availableAtOrFrom === void 0 ? void 0 : availableAtOrFrom.id) === null || _a === void 0 ? void 0 : _a.$eq) !== 'string' || availableAtOrFrom.id.$eq === '') {
|
|
31
|
+
throw new factory.errors.ArgumentNull('availableAtOrFrom.id.$eq');
|
|
32
|
+
}
|
|
33
|
+
const matchStages = [
|
|
34
|
+
{ $match: { 'project.id': { $eq: conditions.project.id.$eq } } },
|
|
35
|
+
{ $match: { 'offers.seller.makesOffer.availableAtOrFrom.id': { $exists: true, $eq: availableAtOrFrom.id.$eq } } }
|
|
36
|
+
];
|
|
37
|
+
const reservationForIdIn = conditions.itemOffered.serviceOutput.reservationFor.id.$in;
|
|
38
|
+
if (Array.isArray(reservationForIdIn)) {
|
|
39
|
+
matchStages.push({ $match: { _id: { $in: reservationForIdIn } } });
|
|
40
|
+
}
|
|
41
|
+
const aggregate = this.eventModel.aggregate([
|
|
42
|
+
{ $unwind: '$offers.seller.makesOffer' },
|
|
43
|
+
...matchStages,
|
|
44
|
+
{ $sort: { _id: factory.sortType.Ascending } },
|
|
45
|
+
{
|
|
46
|
+
$project: {
|
|
47
|
+
_id: 0,
|
|
48
|
+
availabilityEnds: '$offers.seller.makesOffer.availabilityEnds',
|
|
49
|
+
availabilityStarts: '$offers.seller.makesOffer.availabilityStarts',
|
|
50
|
+
validFrom: '$offers.seller.makesOffer.validFrom',
|
|
51
|
+
validThrough: '$offers.seller.makesOffer.validThrough',
|
|
52
|
+
itemOffered: {
|
|
53
|
+
serviceOutput: {
|
|
54
|
+
reservationFor: {
|
|
55
|
+
id: { $toString: '$_id' }
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]);
|
|
62
|
+
if (typeof conditions.limit === 'number' && conditions.limit > 0) {
|
|
63
|
+
const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
|
|
64
|
+
aggregate.limit(conditions.limit * page)
|
|
65
|
+
.skip(conditions.limit * (page - 1));
|
|
66
|
+
}
|
|
67
|
+
return aggregate
|
|
68
|
+
.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
69
|
+
.exec();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.EventSellerMakesOfferRepo = EventSellerMakesOfferRepo;
|
|
@@ -20,6 +20,7 @@ import type { CustomerRepo } from './repo/customer';
|
|
|
20
20
|
import type { CustomerTypeRepo } from './repo/customerType';
|
|
21
21
|
import type { EmailMessageRepo } from './repo/emailMessage';
|
|
22
22
|
import type { EventRepo } from './repo/event';
|
|
23
|
+
import type { EventSellerMakesOfferRepo } from './repo/eventSellerMakesOffer';
|
|
23
24
|
import type { EventSeriesRepo } from './repo/eventSeries';
|
|
24
25
|
import type { MemberRepo } from './repo/member';
|
|
25
26
|
import type { MerchantReturnPolicyRepo } from './repo/merchantReturnPolicy';
|
|
@@ -147,6 +148,10 @@ export type Event = EventRepo;
|
|
|
147
148
|
export declare namespace Event {
|
|
148
149
|
function createInstance(...params: ConstructorParameters<typeof EventRepo>): Promise<EventRepo>;
|
|
149
150
|
}
|
|
151
|
+
export type EventSellerMakesOffer = EventSellerMakesOfferRepo;
|
|
152
|
+
export declare namespace EventSellerMakesOffer {
|
|
153
|
+
function createInstance(...params: ConstructorParameters<typeof EventSellerMakesOfferRepo>): Promise<EventSellerMakesOfferRepo>;
|
|
154
|
+
}
|
|
150
155
|
export type EventSeries = EventSeriesRepo;
|
|
151
156
|
export declare namespace EventSeries {
|
|
152
157
|
function createInstance(...params: ConstructorParameters<typeof EventSeriesRepo>): Promise<EventSeriesRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
13
|
-
exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = void 0;
|
|
12
|
+
exports.Seller = exports.Role = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.place = exports.Permit = exports.Person = exports.paymentMethod = exports.PaymentServiceProvider = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.Member = exports.EventSeries = exports.EventSellerMakesOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOffer = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
|
|
13
|
+
exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerPaymentAccepted = void 0;
|
|
14
14
|
var AcceptedOffer;
|
|
15
15
|
(function (AcceptedOffer) {
|
|
16
16
|
let repo;
|
|
@@ -271,6 +271,19 @@ var Event;
|
|
|
271
271
|
}
|
|
272
272
|
Event.createInstance = createInstance;
|
|
273
273
|
})(Event = exports.Event || (exports.Event = {}));
|
|
274
|
+
var EventSellerMakesOffer;
|
|
275
|
+
(function (EventSellerMakesOffer) {
|
|
276
|
+
let repo;
|
|
277
|
+
function createInstance(...params) {
|
|
278
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
279
|
+
if (repo === undefined) {
|
|
280
|
+
repo = (yield Promise.resolve().then(() => require('./repo/eventSellerMakesOffer'))).EventSellerMakesOfferRepo;
|
|
281
|
+
}
|
|
282
|
+
return new repo(...params);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
EventSellerMakesOffer.createInstance = createInstance;
|
|
286
|
+
})(EventSellerMakesOffer = exports.EventSellerMakesOffer || (exports.EventSellerMakesOffer = {}));
|
|
274
287
|
var EventSeries;
|
|
275
288
|
(function (EventSeries) {
|
|
276
289
|
let repo;
|
package/package.json
CHANGED