@chevre/domain 22.14.0-alpha.8 → 23.0.0-alpha.0
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/{createEventBySchedule.ts → addEventBySchedule.ts} +2 -2
- package/example/src/chevre/aggregateEventPublicFields.ts +1 -1
- package/example/src/chevre/aggregation/createAggregateEventTasks.ts +1 -1
- package/example/src/chevre/authorizeEventServiceOffer.ts +119 -0
- package/example/src/chevre/findAnyEventById.ts +1 -1
- package/example/src/chevre/findReservationByCode.ts +0 -1
- package/example/src/chevre/productOffer/publishMemberTierToken.ts +92 -0
- package/example/src/chevre/reIndex.ts +3 -1
- package/example/src/chevre/roles/addAdminProductOfferPermissionIfNotExists.ts +48 -0
- package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +1 -2
- package/example/src/chevre/updateEventPartiallyById.ts +1 -1
- package/lib/chevre/factory/event.d.ts +2 -4
- package/lib/chevre/repo/accountingReport.d.ts +4 -4
- package/lib/chevre/repo/accountingReport.js +1 -1
- package/lib/chevre/repo/action.d.ts +1 -1
- package/lib/chevre/repo/aggregateReservation.d.ts +2 -2
- package/lib/chevre/repo/creativeWork.d.ts +1 -3
- package/lib/chevre/repo/creativeWork.js +65 -47
- package/lib/chevre/repo/event.d.ts +44 -48
- package/lib/chevre/repo/event.js +13 -111
- package/lib/chevre/repo/eventSeries.d.ts +14 -14
- package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +2 -15
- package/lib/chevre/repo/mongoose/schemas/aggregateReservation.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/event.d.ts +2 -5
- package/lib/chevre/repo/mongoose/schemas/eventSeries.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/place.js +13 -14
- package/lib/chevre/repo/mongoose/schemas/product.js +14 -4
- package/lib/chevre/repo/mongoose/schemas/{offer/event.d.ts → productOffer.d.ts} +6 -3
- package/lib/chevre/repo/mongoose/schemas/{offer/event.js → productOffer.js} +26 -29
- package/lib/chevre/repo/mongoose/schemas/seller.js +17 -6
- package/lib/chevre/repo/productOffer.d.ts +36 -61
- package/lib/chevre/repo/productOffer.js +163 -157
- package/lib/chevre/repository.d.ts +0 -5
- package/lib/chevre/repository.js +2 -15
- package/lib/chevre/service/aggregation/event/aggregateOffers.d.ts +1 -1
- package/lib/chevre/service/aggregation/event/aggregateOffers.js +2 -6
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +3 -19
- package/lib/chevre/service/assetTransaction/reserve/start/createSubReservations.d.ts +1 -3
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createReservation.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.d.ts +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start/factory/createStartParams.js +1 -6
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +0 -2
- package/lib/chevre/service/assetTransaction/reserve/start.js +4 -4
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +3 -3
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +57 -32
- package/lib/chevre/service/offer/event/authorize/factory.d.ts +2 -2
- package/lib/chevre/service/offer/event/authorize/factory.js +2 -2
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +2 -4
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.js +2 -2
- package/lib/chevre/service/offer/event/authorize.d.ts +0 -2
- package/lib/chevre/service/offer/event/authorize.js +2 -2
- package/lib/chevre/service/offer/event/checkAvailability.d.ts +1 -1
- package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +1 -1
- package/lib/chevre/service/offer/event/searchOffersByIds.d.ts +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize/factory.d.ts +1 -1
- package/lib/chevre/service/offer/onEventChanged.js +2 -19
- package/lib/chevre/service/offer/product.d.ts +0 -3
- package/lib/chevre/service/offer/product.js +29 -38
- package/lib/chevre/service/order/createAccountingReportIfNotExist.js +0 -1
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderPaymentDue.js +2 -2
- package/lib/chevre/service/order/onOrderStatusChanged/onOrderProcessing/factory.js +1 -1
- package/lib/chevre/service/payment/movieTicket/factory.d.ts +2 -2
- package/lib/chevre/service/payment/movieTicket/processPurchaseNumberAuth.d.ts +1 -1
- package/lib/chevre/service/reserve/useReservation.js +2 -3
- package/lib/chevre/service/reserve/verifyToken4reservation.d.ts +0 -2
- package/lib/chevre/service/task/checkResource.d.ts +2 -2
- package/lib/chevre/service/task/checkResource.js +8 -6
- package/lib/chevre/service/task/createAccountingReport.d.ts +2 -2
- package/lib/chevre/service/task/createAccountingReport.js +15 -15
- package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.d.ts +1 -1
- package/lib/chevre/service/task/createEvent/createEventBySchedule.d.ts +1 -1
- package/lib/chevre/service/task/createEvent/createEventBySchedule.js +3 -2
- package/lib/chevre/service/task/createEvent/createEventSeries.d.ts +1 -1
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +7 -6
- package/lib/chevre/service/task/useReservation.js +1 -2
- package/lib/chevre/service/taskHandler.js +2 -0
- package/lib/chevre/service/transaction/returnOrder/potentialActions/returnPointAward.d.ts +0 -1
- package/package.json +3 -3
- package/example/src/chevre/eventOffer/adminEventOffers.ts +0 -67
- package/example/src/chevre/roles/addPermissionIfNotExists.ts +0 -48
- package/example/src/chevre/upsertMoviesByIdentifier.ts +0 -58
- package/lib/chevre/repo/offer/event.d.ts +0 -38
- package/lib/chevre/repo/offer/event.js +0 -142
|
@@ -50,10 +50,10 @@ const indexes = [
|
|
|
50
50
|
{ productID: 1 },
|
|
51
51
|
{ name: 'searchByProductID' }
|
|
52
52
|
],
|
|
53
|
-
[
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
],
|
|
53
|
+
// [
|
|
54
|
+
// { 'project.id': 1, productID: 1 },
|
|
55
|
+
// { name: 'searchByProjectId-v20220721' }
|
|
56
|
+
// ], // migrate to uniqueProductID(2025-09-30~)
|
|
57
57
|
[
|
|
58
58
|
{ 'hasOfferCatalog.id': 1, productID: 1 },
|
|
59
59
|
{
|
|
@@ -129,6 +129,16 @@ const indexes = [
|
|
|
129
129
|
additionalProperty: { $exists: true }
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
],
|
|
133
|
+
[
|
|
134
|
+
{
|
|
135
|
+
'project.id': 1,
|
|
136
|
+
productID: 1
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'uniqueProductID',
|
|
140
|
+
unique: true
|
|
141
|
+
}
|
|
132
142
|
]
|
|
133
143
|
];
|
|
134
144
|
exports.indexes = indexes;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
-
import * as factory from '
|
|
3
|
-
type IDocType = factory.
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
type IDocType = Omit<factory.productOffer.IProductOffer, 'acceptedPaymentMethod' | 'validForMemberTier'> & {
|
|
4
|
+
acceptedPaymentMethod?: factory.productOffer.IAcceptedPaymentMethod;
|
|
5
|
+
validForMemberTier?: factory.productOffer.IValidForMemberTier;
|
|
6
|
+
};
|
|
4
7
|
type IModel = Model<IDocType>;
|
|
5
8
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
6
9
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
7
|
-
declare const modelName = "
|
|
10
|
+
declare const modelName = "ProductOffer";
|
|
8
11
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
9
12
|
declare function createSchema(): ISchema;
|
|
10
13
|
export { createSchema, IDocType, IModel, indexes, modelName };
|
|
@@ -3,25 +3,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.modelName = exports.indexes = void 0;
|
|
4
4
|
exports.createSchema = createSchema;
|
|
5
5
|
const mongoose_1 = require("mongoose");
|
|
6
|
-
const settings_1 = require("
|
|
7
|
-
const writeConcern_1 = require("
|
|
8
|
-
const modelName = '
|
|
6
|
+
const settings_1 = require("../../../settings");
|
|
7
|
+
const writeConcern_1 = require("../writeConcern");
|
|
8
|
+
const modelName = 'ProductOffer';
|
|
9
9
|
exports.modelName = modelName;
|
|
10
10
|
const schemaDefinition = {
|
|
11
11
|
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
|
-
seller: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
13
12
|
typeOf: { type: String, required: true },
|
|
14
13
|
identifier: { type: String, required: true },
|
|
15
14
|
itemOffered: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
16
|
-
|
|
15
|
+
offeredBy: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
16
|
+
availability: { type: String, required: true },
|
|
17
17
|
validFrom: { type: Date, required: true },
|
|
18
18
|
validThrough: { type: Date, required: true },
|
|
19
|
-
|
|
19
|
+
// availableAtOrFrom: { type: SchemaTypes.Mixed, required: false },
|
|
20
|
+
validForMemberTier: { type: mongoose_1.SchemaTypes.Mixed, required: false },
|
|
21
|
+
acceptedPaymentMethod: { type: mongoose_1.SchemaTypes.Mixed, required: false }
|
|
20
22
|
};
|
|
21
23
|
const schemaOptions = {
|
|
22
24
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
23
25
|
autoCreate: false,
|
|
24
|
-
collection: '
|
|
26
|
+
collection: 'productOffers',
|
|
25
27
|
id: true,
|
|
26
28
|
read: settings_1.MONGO_READ_PREFERENCE,
|
|
27
29
|
writeConcern: writeConcern_1.writeConcern,
|
|
@@ -49,7 +51,8 @@ const indexes = [
|
|
|
49
51
|
],
|
|
50
52
|
[
|
|
51
53
|
{
|
|
52
|
-
'
|
|
54
|
+
'project.id': 1,
|
|
55
|
+
'itemOffered.identifier': 1,
|
|
53
56
|
identifier: 1
|
|
54
57
|
},
|
|
55
58
|
{
|
|
@@ -57,45 +60,39 @@ const indexes = [
|
|
|
57
60
|
unique: true
|
|
58
61
|
}
|
|
59
62
|
],
|
|
60
|
-
[
|
|
61
|
-
{
|
|
62
|
-
'itemOffered.id': 1,
|
|
63
|
-
'availableAtOrFrom.id': 1,
|
|
64
|
-
'validForMemberTier.identifier': 1
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: 'uniqueByItemOfferedAndAvailableAt',
|
|
68
|
-
unique: true
|
|
69
|
-
}
|
|
70
|
-
],
|
|
71
63
|
[
|
|
72
64
|
{ 'project.id': 1, validFrom: 1 },
|
|
73
65
|
{ name: 'projectId' }
|
|
74
66
|
],
|
|
75
|
-
[
|
|
76
|
-
{ 'seller.id': 1, validFrom: 1 },
|
|
77
|
-
{ name: 'sellerId' }
|
|
78
|
-
],
|
|
79
67
|
[
|
|
80
68
|
{ identifier: 1, validFrom: 1 },
|
|
81
69
|
{ name: 'identifier' }
|
|
82
70
|
],
|
|
83
71
|
[
|
|
84
|
-
{ 'itemOffered.
|
|
85
|
-
{ name: '
|
|
72
|
+
{ 'itemOffered.identifier': 1, validFrom: 1 },
|
|
73
|
+
{ name: 'itemOfferedIdentifier' }
|
|
74
|
+
],
|
|
75
|
+
[
|
|
76
|
+
{ 'offeredBy.id': 1, validFrom: 1 },
|
|
77
|
+
{ name: 'offeredById' }
|
|
86
78
|
],
|
|
87
79
|
[
|
|
88
|
-
{
|
|
89
|
-
{ name: '
|
|
80
|
+
{ validThrough: 1, validFrom: 1 },
|
|
81
|
+
{ name: 'validThrough' }
|
|
90
82
|
],
|
|
91
83
|
[
|
|
92
84
|
{ 'validForMemberTier.identifier': 1, validFrom: 1 },
|
|
93
|
-
{
|
|
85
|
+
{
|
|
86
|
+
name: 'validForMemberTierIdentifier',
|
|
87
|
+
partialFilterExpression: {
|
|
88
|
+
'validForMemberTier.identifier': { $exists: true }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
94
91
|
]
|
|
95
92
|
];
|
|
96
93
|
exports.indexes = indexes;
|
|
97
94
|
/**
|
|
98
|
-
*
|
|
95
|
+
* プロダクトオファー(汎用的なオファー設定)スキーマ
|
|
99
96
|
*/
|
|
100
97
|
let schema;
|
|
101
98
|
function createSchema() {
|
|
@@ -57,12 +57,12 @@ const indexes = [
|
|
|
57
57
|
{ typeOf: 1, branchCode: 1 },
|
|
58
58
|
{ name: 'searchByTypeOf' }
|
|
59
59
|
],
|
|
60
|
-
[
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
],
|
|
60
|
+
// [
|
|
61
|
+
// { 'project.id': 1, branchCode: 1 },
|
|
62
|
+
// {
|
|
63
|
+
// name: 'searchByProjectId-v20220721'
|
|
64
|
+
// }
|
|
65
|
+
// ],
|
|
66
66
|
[
|
|
67
67
|
{ 'name.ja': 1, branchCode: 1 },
|
|
68
68
|
{
|
|
@@ -107,6 +107,17 @@ const indexes = [
|
|
|
107
107
|
'hasMerchantReturnPolicy.identifier': { $exists: true }
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
// unique index(2025-10-01~)
|
|
113
|
+
{
|
|
114
|
+
'project.id': 1,
|
|
115
|
+
branchCode: 1
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
unique: true,
|
|
119
|
+
name: 'uniqueBranchCode'
|
|
120
|
+
}
|
|
110
121
|
]
|
|
111
122
|
];
|
|
112
123
|
exports.indexes = indexes;
|
|
@@ -1,77 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BulkWriteResult, DeleteResult } from 'mongodb';
|
|
2
|
+
import { Connection, FilterQuery } from 'mongoose';
|
|
2
3
|
import * as factory from '../factory';
|
|
4
|
+
import { IDocType } from './mongoose/schemas/productOffer';
|
|
5
|
+
type IUnset = {
|
|
6
|
+
[key in keyof IDocType]?: 1;
|
|
7
|
+
};
|
|
8
|
+
type IDocWithId = factory.productOffer.IProductOffer & {
|
|
9
|
+
id: string;
|
|
10
|
+
};
|
|
11
|
+
type IKeyOfProjection = keyof IDocType;
|
|
3
12
|
/**
|
|
4
13
|
* プロダクトオファーリポジトリ
|
|
5
14
|
*/
|
|
6
15
|
export declare class ProductOfferRepo {
|
|
7
|
-
private readonly
|
|
16
|
+
private readonly productOfferModel;
|
|
8
17
|
constructor(connection: Connection);
|
|
18
|
+
static CREATE_MONGO_CONDITIONS(params: factory.productOffer.ISearchConditions): FilterQuery<IDocType>[];
|
|
19
|
+
findProductOffers(params: factory.productOffer.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IDocWithId[]>;
|
|
9
20
|
/**
|
|
10
|
-
*
|
|
21
|
+
* オファーコードとオファーコレクションコードをキーにして冪等置換
|
|
11
22
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
seller?: {
|
|
26
|
-
id?: {
|
|
27
|
-
$eq?: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
}): Promise<(Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'> & {
|
|
31
|
-
itemOffered: Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'>;
|
|
32
|
-
})[]>;
|
|
33
|
-
create(params: factory.product.IOffer & {
|
|
34
|
-
project: {
|
|
35
|
-
id: string;
|
|
36
|
-
};
|
|
37
|
-
itemOffered: {
|
|
38
|
-
/**
|
|
39
|
-
* プロダクトID
|
|
40
|
-
*/
|
|
41
|
-
id: string;
|
|
42
|
-
};
|
|
23
|
+
upsertOffersByIdentifier(params: {
|
|
24
|
+
$set: Pick<IDocType, 'acceptedPaymentMethod' | 'availability' | 'identifier' | 'itemOffered' | 'offeredBy' | 'project' | 'typeOf' | 'validForMemberTier' | 'validFrom' | 'validThrough'> & {
|
|
25
|
+
id?: never;
|
|
26
|
+
};
|
|
27
|
+
$unset: IUnset;
|
|
28
|
+
}[], options: {
|
|
29
|
+
/**
|
|
30
|
+
* falseの場合setOnInsertのみ
|
|
31
|
+
* trueの場合setのみ
|
|
32
|
+
*/
|
|
33
|
+
update: boolean;
|
|
43
34
|
}): Promise<{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
update(params: factory.product.IOffer & {
|
|
47
|
-
project: {
|
|
35
|
+
bulkWriteResult: BulkWriteResult;
|
|
36
|
+
modifiedProductOffers: {
|
|
48
37
|
id: string;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
}): Promise<{
|
|
57
|
-
id: string;
|
|
58
|
-
}>;
|
|
59
|
-
deleteOne(params: Pick<factory.product.IOffer, 'seller'> & {
|
|
38
|
+
}[];
|
|
39
|
+
} | void>;
|
|
40
|
+
/**
|
|
41
|
+
* 販売者の提供するプロダクトオファーを削除する
|
|
42
|
+
*/
|
|
43
|
+
deleteProductOffersBySeller(params: {
|
|
60
44
|
project: {
|
|
61
45
|
id: string;
|
|
62
46
|
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* プロダクトID
|
|
66
|
-
*/
|
|
67
|
-
id: string;
|
|
68
|
-
};
|
|
69
|
-
}): Promise<{
|
|
70
|
-
id: string;
|
|
71
|
-
}>;
|
|
72
|
-
deleteManyBySellerId(params: Pick<factory.product.IOffer, 'seller'> & {
|
|
73
|
-
project: {
|
|
47
|
+
offeredBy: {
|
|
74
48
|
id: string;
|
|
75
49
|
};
|
|
76
|
-
}): Promise<
|
|
50
|
+
}): Promise<DeleteResult>;
|
|
77
51
|
}
|
|
52
|
+
export {};
|
|
@@ -10,189 +10,195 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.ProductOfferRepo = void 0;
|
|
13
|
-
const mongoose_1 = require("mongoose");
|
|
14
|
-
const product_1 = require("./mongoose/schemas/product");
|
|
15
13
|
const factory = require("../factory");
|
|
16
14
|
const settings_1 = require("../settings");
|
|
15
|
+
const productOffer_1 = require("./mongoose/schemas/productOffer");
|
|
16
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
17
|
+
'identifier',
|
|
18
|
+
'project',
|
|
19
|
+
'itemOffered',
|
|
20
|
+
'offeredBy',
|
|
21
|
+
'typeOf',
|
|
22
|
+
'validFrom',
|
|
23
|
+
'validThrough',
|
|
24
|
+
'availability',
|
|
25
|
+
'acceptedPaymentMethod',
|
|
26
|
+
'validForMemberTier'
|
|
27
|
+
];
|
|
17
28
|
/**
|
|
18
29
|
* プロダクトオファーリポジトリ
|
|
19
30
|
*/
|
|
20
31
|
class ProductOfferRepo {
|
|
21
32
|
constructor(connection) {
|
|
22
|
-
this.
|
|
33
|
+
this.productOfferModel = connection.model(productOffer_1.modelName, (0, productOffer_1.createSchema)());
|
|
23
34
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
static CREATE_MONGO_CONDITIONS(params) {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
37
|
+
const andConditions = [];
|
|
38
|
+
const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
39
|
+
if (typeof idEq === 'string') {
|
|
40
|
+
andConditions.push({ _id: { $eq: idEq } });
|
|
41
|
+
}
|
|
42
|
+
const projectIdEq = (_c = (_b = params.project) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
43
|
+
if (typeof projectIdEq === 'string') {
|
|
44
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
45
|
+
}
|
|
46
|
+
const identifierEq = (_d = params.identifier) === null || _d === void 0 ? void 0 : _d.$eq;
|
|
47
|
+
if (typeof identifierEq === 'string') {
|
|
48
|
+
andConditions.push({ identifier: { $eq: identifierEq } });
|
|
49
|
+
}
|
|
50
|
+
const identifierIn = (_e = params.identifier) === null || _e === void 0 ? void 0 : _e.$in;
|
|
51
|
+
if (Array.isArray(identifierIn)) {
|
|
52
|
+
andConditions.push({ identifier: { $in: identifierIn } });
|
|
53
|
+
}
|
|
54
|
+
const itemOfferedIdentifierEq = (_g = (_f = params.itemOffered) === null || _f === void 0 ? void 0 : _f.identifier) === null || _g === void 0 ? void 0 : _g.$eq;
|
|
55
|
+
if (typeof itemOfferedIdentifierEq === 'string') {
|
|
56
|
+
andConditions.push({ 'itemOffered.identifier': { $eq: itemOfferedIdentifierEq } });
|
|
57
|
+
}
|
|
58
|
+
const itemOfferedIdentifierIn = (_j = (_h = params.itemOffered) === null || _h === void 0 ? void 0 : _h.identifier) === null || _j === void 0 ? void 0 : _j.$in;
|
|
59
|
+
if (Array.isArray(itemOfferedIdentifierIn)) {
|
|
60
|
+
andConditions.push({ 'itemOffered.identifier': { $in: itemOfferedIdentifierIn } });
|
|
61
|
+
}
|
|
62
|
+
const offeredByIdEq = (_l = (_k = params.offeredBy) === null || _k === void 0 ? void 0 : _k.id) === null || _l === void 0 ? void 0 : _l.$eq;
|
|
63
|
+
if (typeof offeredByIdEq === 'string') {
|
|
64
|
+
andConditions.push({ 'offeredBy.id': { $eq: offeredByIdEq } });
|
|
65
|
+
}
|
|
66
|
+
const sellerByIdEq = (_o = (_m = params.seller) === null || _m === void 0 ? void 0 : _m.id) === null || _o === void 0 ? void 0 : _o.$eq;
|
|
67
|
+
if (typeof sellerByIdEq === 'string') {
|
|
68
|
+
andConditions.push({ 'offeredBy.id': { $eq: sellerByIdEq } });
|
|
69
|
+
}
|
|
70
|
+
const validForMemberTierIdentifierEq = (_q = (_p = params.validForMemberTier) === null || _p === void 0 ? void 0 : _p.identifier) === null || _q === void 0 ? void 0 : _q.$eq;
|
|
71
|
+
if (typeof validForMemberTierIdentifierEq === 'string') {
|
|
72
|
+
andConditions.push({ 'validForMemberTier.identifier': { $exists: true, $eq: validForMemberTierIdentifierEq } });
|
|
73
|
+
}
|
|
74
|
+
const validFromLte = (_r = params.validFrom) === null || _r === void 0 ? void 0 : _r.$lte;
|
|
75
|
+
if (validFromLte instanceof Date) {
|
|
76
|
+
andConditions.push({ validFrom: { $lte: validFromLte } });
|
|
77
|
+
}
|
|
78
|
+
const validThroughGte = (_s = params.validThrough) === null || _s === void 0 ? void 0 : _s.$gte;
|
|
79
|
+
if (validThroughGte instanceof Date) {
|
|
80
|
+
andConditions.push({ validThrough: { $gte: validThroughGte } });
|
|
81
|
+
}
|
|
82
|
+
return andConditions;
|
|
83
|
+
}
|
|
84
|
+
findProductOffers(params, inclusion) {
|
|
28
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
var _a
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
factory.product.ProductType.MembershipService,
|
|
35
|
-
factory.product.ProductType.PaymentCard
|
|
36
|
-
]
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}];
|
|
40
|
-
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
41
|
-
if (typeof projectIdEq === 'string') {
|
|
42
|
-
matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
|
|
86
|
+
var _a;
|
|
87
|
+
const conditions = ProductOfferRepo.CREATE_MONGO_CONDITIONS(params);
|
|
88
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
89
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
90
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
43
91
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(itemOfferedIdEq) } } });
|
|
92
|
+
else {
|
|
93
|
+
throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
|
|
47
94
|
}
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
95
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
96
|
+
const query = this.productOfferModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
97
|
+
if (typeof ((_a = params.sort) === null || _a === void 0 ? void 0 : _a.validFrom) === 'number') {
|
|
98
|
+
query.sort({ validFrom: params.sort.validFrom });
|
|
51
99
|
}
|
|
52
|
-
const aggregate = this.productModel.aggregate([
|
|
53
|
-
{ $sort: { productID: factory.sortType.Ascending } },
|
|
54
|
-
{
|
|
55
|
-
$unwind: {
|
|
56
|
-
path: '$offers'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
...matchStages,
|
|
60
|
-
{
|
|
61
|
-
$project: {
|
|
62
|
-
_id: 0,
|
|
63
|
-
itemOffered: {
|
|
64
|
-
id: { $toString: '$_id' },
|
|
65
|
-
name: '$name',
|
|
66
|
-
typeOf: '$typeOf'
|
|
67
|
-
},
|
|
68
|
-
availabilityEnds: '$offers.availabilityEnds',
|
|
69
|
-
availabilityStarts: '$offers.availabilityStarts',
|
|
70
|
-
validFrom: '$offers.validFrom',
|
|
71
|
-
validThrough: '$offers.validThrough',
|
|
72
|
-
seller: '$offers.seller'
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
]);
|
|
76
100
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
77
101
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
78
|
-
|
|
102
|
+
query.limit(params.limit)
|
|
79
103
|
.skip(params.limit * (page - 1));
|
|
80
104
|
}
|
|
81
|
-
return
|
|
82
|
-
.
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
create(params) {
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
var _a;
|
|
88
|
-
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
89
|
-
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
90
|
-
throw new factory.errors.ArgumentNull('seller.id');
|
|
91
|
-
}
|
|
92
|
-
// プロダクト存在確認
|
|
93
|
-
let doc = yield this.productModel.findOne({
|
|
94
|
-
'project.id': { $eq: params.project.id },
|
|
95
|
-
_id: { $eq: params.itemOffered.id }
|
|
96
|
-
}, { _id: 1 })
|
|
97
|
-
.exec();
|
|
98
|
-
if (doc === null) {
|
|
99
|
-
throw new factory.errors.NotFound('Product');
|
|
100
|
-
}
|
|
101
|
-
const creatingOffer = {
|
|
102
|
-
priceCurrency: factory.priceCurrency.JPY,
|
|
103
|
-
availabilityEnds: params.availabilityEnds,
|
|
104
|
-
availabilityStarts: params.availabilityStarts,
|
|
105
|
-
validFrom: params.validFrom,
|
|
106
|
-
validThrough: params.validThrough,
|
|
107
|
-
seller: { id: sellerId },
|
|
108
|
-
typeOf: factory.offerType.Offer
|
|
109
|
-
};
|
|
110
|
-
doc = yield this.productModel.findOneAndUpdate({
|
|
111
|
-
'project.id': { $eq: params.project.id },
|
|
112
|
-
_id: { $eq: params.itemOffered.id },
|
|
113
|
-
'offers.seller.id': { $ne: sellerId }
|
|
114
|
-
}, {
|
|
115
|
-
$push: { offers: creatingOffer }
|
|
116
|
-
}, {
|
|
117
|
-
new: true,
|
|
118
|
-
projection: { _id: 1 }
|
|
119
|
-
})
|
|
120
|
-
.exec();
|
|
121
|
-
// 存在しなければプロバイダーID重複
|
|
122
|
-
if (doc === null) {
|
|
123
|
-
throw new factory.errors.AlreadyInUse('offers.seller', ['id']);
|
|
124
|
-
}
|
|
125
|
-
return doc.toObject();
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
update(params) {
|
|
129
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
-
var _a;
|
|
131
|
-
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
132
|
-
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
133
|
-
throw new factory.errors.ArgumentNull('seller.id');
|
|
134
|
-
}
|
|
135
|
-
const doc = yield this.productModel.findOneAndUpdate({
|
|
136
|
-
'project.id': { $eq: params.project.id },
|
|
137
|
-
_id: { $eq: params.itemOffered.id },
|
|
138
|
-
'offers.seller.id': { $exists: true, $eq: sellerId }
|
|
139
|
-
}, Object.assign(Object.assign(Object.assign(Object.assign({}, (params.availabilityEnds instanceof Date)
|
|
140
|
-
? { 'offers.$[offerBySeller].availabilityEnds': params.availabilityEnds }
|
|
141
|
-
: undefined), (params.availabilityStarts instanceof Date)
|
|
142
|
-
? { 'offers.$[offerBySeller].availabilityStarts': params.availabilityStarts }
|
|
143
|
-
: undefined), (params.validFrom instanceof Date)
|
|
144
|
-
? { 'offers.$[offerBySeller].validFrom': params.validFrom }
|
|
145
|
-
: undefined), (params.validThrough instanceof Date)
|
|
146
|
-
? { 'offers.$[offerBySeller].validThrough': params.validThrough }
|
|
147
|
-
: undefined), {
|
|
148
|
-
new: true,
|
|
149
|
-
arrayFilters: [
|
|
150
|
-
{ 'offerBySeller.seller.id': { $eq: sellerId } }
|
|
151
|
-
],
|
|
152
|
-
projection: { _id: 1 }
|
|
153
|
-
})
|
|
105
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
106
|
+
.lean()
|
|
154
107
|
.exec();
|
|
155
|
-
if (doc === null) {
|
|
156
|
-
throw new factory.errors.NotFound('Product');
|
|
157
|
-
}
|
|
158
|
-
return doc.toObject();
|
|
159
108
|
});
|
|
160
109
|
}
|
|
161
|
-
|
|
110
|
+
/**
|
|
111
|
+
* オファーコードとオファーコレクションコードをキーにして冪等置換
|
|
112
|
+
*/
|
|
113
|
+
upsertOffersByIdentifier(params, options) {
|
|
162
114
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
115
|
+
const { update } = options;
|
|
116
|
+
const bulkWriteOps = [];
|
|
117
|
+
const queryFilters = [];
|
|
118
|
+
if (Array.isArray(params)) {
|
|
119
|
+
params.forEach(({ $set, $unset }) => {
|
|
120
|
+
const { availability, identifier, itemOffered, offeredBy, project, validFrom, validThrough, acceptedPaymentMethod, validForMemberTier } = $set;
|
|
121
|
+
if (typeof identifier !== 'string' || identifier === '') {
|
|
122
|
+
throw new factory.errors.ArgumentNull('identifier');
|
|
123
|
+
}
|
|
124
|
+
if (typeof itemOffered.identifier !== 'string' || itemOffered.identifier === '') {
|
|
125
|
+
throw new factory.errors.ArgumentNull('itemOffered.identifier');
|
|
126
|
+
}
|
|
127
|
+
// リソースのユニークネスを保証するfilter
|
|
128
|
+
const filter = {
|
|
129
|
+
'project.id': { $eq: project.id },
|
|
130
|
+
'itemOffered.identifier': { $eq: itemOffered.identifier },
|
|
131
|
+
identifier: { $eq: identifier }
|
|
132
|
+
};
|
|
133
|
+
queryFilters.push({
|
|
134
|
+
'project.id': { $eq: project.id },
|
|
135
|
+
'itemOffered.identifier': { $eq: itemOffered.identifier },
|
|
136
|
+
identifier: { $eq: identifier }
|
|
137
|
+
});
|
|
138
|
+
if (update === true) {
|
|
139
|
+
const setFields = Object.assign(Object.assign({ availability,
|
|
140
|
+
validFrom,
|
|
141
|
+
validThrough }, (typeof (acceptedPaymentMethod === null || acceptedPaymentMethod === void 0 ? void 0 : acceptedPaymentMethod.typeOf) === 'string') ? { acceptedPaymentMethod } : undefined), (typeof (validForMemberTier === null || validForMemberTier === void 0 ? void 0 : validForMemberTier.typeOf) === 'string') ? { validForMemberTier } : undefined);
|
|
142
|
+
const updateFilter = Object.assign({ $set: setFields }, ($unset !== undefined) ? { $unset } : undefined);
|
|
143
|
+
const updateOne = {
|
|
144
|
+
filter,
|
|
145
|
+
update: updateFilter,
|
|
146
|
+
upsert: false
|
|
147
|
+
};
|
|
148
|
+
bulkWriteOps.push({ updateOne });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const setOnInsert = Object.assign(Object.assign({ itemOffered, offeredBy, identifier, project, typeOf: factory.offerType.Offer, availability,
|
|
152
|
+
validFrom,
|
|
153
|
+
validThrough }, (typeof (acceptedPaymentMethod === null || acceptedPaymentMethod === void 0 ? void 0 : acceptedPaymentMethod.typeOf) === 'string') ? { acceptedPaymentMethod } : undefined), (typeof (validForMemberTier === null || validForMemberTier === void 0 ? void 0 : validForMemberTier.typeOf) === 'string') ? { validForMemberTier } : undefined);
|
|
154
|
+
const updateFilter = {
|
|
155
|
+
$setOnInsert: setOnInsert
|
|
156
|
+
};
|
|
157
|
+
const updateOne = {
|
|
158
|
+
filter,
|
|
159
|
+
update: updateFilter,
|
|
160
|
+
upsert: true
|
|
161
|
+
};
|
|
162
|
+
bulkWriteOps.push({ updateOne });
|
|
163
|
+
}
|
|
164
|
+
});
|
|
167
165
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (doc === null) {
|
|
179
|
-
throw new factory.errors.NotFound('Product');
|
|
166
|
+
if (bulkWriteOps.length > 0) {
|
|
167
|
+
const bulkWriteResult = yield this.productOfferModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
168
|
+
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
169
|
+
const modifiedProductOffers = yield this.productOfferModel.find({ $or: queryFilters }, {
|
|
170
|
+
_id: 0,
|
|
171
|
+
id: { $toString: '$_id' }
|
|
172
|
+
})
|
|
173
|
+
.lean()
|
|
174
|
+
.exec();
|
|
175
|
+
return { bulkWriteResult, modifiedProductOffers };
|
|
180
176
|
}
|
|
181
|
-
return doc.toObject();
|
|
182
177
|
});
|
|
183
178
|
}
|
|
184
|
-
|
|
179
|
+
// public async deleteProductOffersByIds(params: {
|
|
180
|
+
// project: { id: string };
|
|
181
|
+
// ids: string[];
|
|
182
|
+
// }): Promise<DeleteResult | void> {
|
|
183
|
+
// const { project, ids } = params;
|
|
184
|
+
// if (Array.isArray(ids) && ids.length > 0) {
|
|
185
|
+
// return this.productOfferModel.deleteMany(
|
|
186
|
+
// {
|
|
187
|
+
// 'project.id': { $eq: project.id },
|
|
188
|
+
// _id: { $in: ids }
|
|
189
|
+
// }
|
|
190
|
+
// )
|
|
191
|
+
// .exec();
|
|
192
|
+
// }
|
|
193
|
+
// }
|
|
194
|
+
/**
|
|
195
|
+
* 販売者の提供するプロダクトオファーを削除する
|
|
196
|
+
*/
|
|
197
|
+
deleteProductOffersBySeller(params) {
|
|
185
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
186
|
-
|
|
187
|
-
const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
|
|
188
|
-
if (typeof sellerId !== 'string' || sellerId.length === 0) {
|
|
189
|
-
throw new factory.errors.ArgumentNull('seller.id');
|
|
190
|
-
}
|
|
191
|
-
return this.productModel.updateMany({
|
|
199
|
+
return this.productOfferModel.deleteMany({
|
|
192
200
|
'project.id': { $eq: params.project.id },
|
|
193
|
-
'
|
|
194
|
-
}, {
|
|
195
|
-
$pull: { offers: { 'seller.id': { $exists: true, $eq: sellerId } } }
|
|
201
|
+
'offeredBy.id': { $eq: params.offeredBy.id }
|
|
196
202
|
})
|
|
197
203
|
.exec();
|
|
198
204
|
});
|