@chevre/domain 21.28.0-alpha.13 → 21.28.0-alpha.15
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/playAroundProductModel.ts +64 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +4 -4
- package/lib/chevre/repo/mongoose/schemas/product.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/product.js +22 -38
- package/lib/chevre/repo/mongoose/schemas/productModel.d.ts +5 -0
- package/lib/chevre/repo/mongoose/schemas/productModel.js +68 -0
- package/lib/chevre/repo/paymentService.d.ts +0 -3
- package/lib/chevre/repo/paymentService.js +1 -45
- package/lib/chevre/repo/product.d.ts +4 -0
- package/lib/chevre/repo/product.js +6 -0
- package/lib/chevre/repo/productModel.d.ts +61 -0
- package/lib/chevre/repo/productModel.js +138 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/package.json +1 -1
- package/example/src/chevre/deleteOldPaymentServices.ts +0 -18
- package/example/src/chevre/migratePaymentServicesToNewCollection.ts +0 -21
- package/example/src/chevre/playAroundProjectMakesOffer.ts +0 -47
|
@@ -0,0 +1,64 @@
|
|
|
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 productModelRepo = await chevre.repository.ProductModel.createInstance(mongoose.connection);
|
|
12
|
+
const result = await productModelRepo.search(
|
|
13
|
+
{
|
|
14
|
+
limit: 100,
|
|
15
|
+
page: 1,
|
|
16
|
+
category: {
|
|
17
|
+
codeValue: { $in: ['Premium'] },
|
|
18
|
+
inCodeSet: { identifier: { $eq: chevre.factory.categoryCode.CategorySetIdentifier.SeatingType } }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
[],
|
|
22
|
+
[]
|
|
23
|
+
);
|
|
24
|
+
console.log('result:', result);
|
|
25
|
+
|
|
26
|
+
const productModel = {
|
|
27
|
+
project: {
|
|
28
|
+
id: project.id,
|
|
29
|
+
typeOf: <chevre.factory.organizationType.Project>chevre.factory.organizationType.Project
|
|
30
|
+
},
|
|
31
|
+
typeOf: <'ProductModel'>'ProductModel',
|
|
32
|
+
category: {
|
|
33
|
+
codeValue: 'Premium',
|
|
34
|
+
inCodeSet: {
|
|
35
|
+
identifier: chevre.factory.categoryCode.CategorySetIdentifier.SeatingType,
|
|
36
|
+
typeOf: <'CategoryCodeSet'>'CategoryCodeSet'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
name: { ja: 'プレミアムシート' },
|
|
40
|
+
offers: [{
|
|
41
|
+
typeOf: <chevre.factory.offerType.Offer>chevre.factory.offerType.Offer
|
|
42
|
+
}]
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createdModel = await productModelRepo.save({
|
|
46
|
+
$set: productModel
|
|
47
|
+
});
|
|
48
|
+
console.log('created. id:', createdModel);
|
|
49
|
+
|
|
50
|
+
await productModelRepo.save({
|
|
51
|
+
id: createdModel.id,
|
|
52
|
+
$set: productModel
|
|
53
|
+
});
|
|
54
|
+
console.log('updated. id:', createdModel.id);
|
|
55
|
+
|
|
56
|
+
await productModelRepo.deleteById({
|
|
57
|
+
id: createdModel.id
|
|
58
|
+
});
|
|
59
|
+
console.log('deleted. id:', createdModel.id);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main()
|
|
63
|
+
.then(console.log)
|
|
64
|
+
.catch(console.error);
|
|
@@ -8,13 +8,13 @@ async function main() {
|
|
|
8
8
|
|
|
9
9
|
let updateResult: any;
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
updateResult = await
|
|
11
|
+
const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
|
|
12
|
+
updateResult = await productRepo.unsetUnnecessaryFields({
|
|
13
13
|
filter: {
|
|
14
|
-
'
|
|
14
|
+
'serviceType.project': { $exists: true }
|
|
15
15
|
},
|
|
16
16
|
$unset: {
|
|
17
|
-
'
|
|
17
|
+
'serviceType.project': 1
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
console.log('unset processed.', updateResult);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Schema } from 'mongoose';
|
|
2
2
|
declare const modelName = "Product";
|
|
3
|
-
declare function createSchema(): Schema;
|
|
4
3
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
4
|
+
declare function createSchema(): Schema;
|
|
5
5
|
export { modelName, indexes, createSchema };
|
|
@@ -8,21 +8,15 @@ const modelName = 'Product';
|
|
|
8
8
|
exports.modelName = modelName;
|
|
9
9
|
const schemaDefinition = {
|
|
10
10
|
project: mongoose_1.SchemaTypes.Mixed,
|
|
11
|
-
typeOf: {
|
|
12
|
-
type: String,
|
|
13
|
-
required: true
|
|
14
|
-
},
|
|
11
|
+
typeOf: { type: String, required: true },
|
|
15
12
|
additionalProperty: [mongoose_1.SchemaTypes.Mixed],
|
|
16
13
|
availableChannel: mongoose_1.SchemaTypes.Mixed,
|
|
17
14
|
description: mongoose_1.SchemaTypes.Mixed,
|
|
18
15
|
hasOfferCatalog: mongoose_1.SchemaTypes.Mixed,
|
|
19
16
|
name: mongoose_1.SchemaTypes.Mixed,
|
|
20
17
|
offers: [mongoose_1.SchemaTypes.Mixed],
|
|
21
|
-
productID: {
|
|
22
|
-
|
|
23
|
-
required: true
|
|
24
|
-
},
|
|
25
|
-
provider: [mongoose_1.SchemaTypes.Mixed],
|
|
18
|
+
productID: { type: String, required: true },
|
|
19
|
+
// provider: [SchemaTypes.Mixed], // 廃止(2024-04-12~)
|
|
26
20
|
serviceOutput: mongoose_1.SchemaTypes.Mixed,
|
|
27
21
|
serviceType: mongoose_1.SchemaTypes.Mixed
|
|
28
22
|
};
|
|
@@ -52,17 +46,6 @@ const schemaOptions = {
|
|
|
52
46
|
versionKey: false
|
|
53
47
|
}
|
|
54
48
|
};
|
|
55
|
-
/**
|
|
56
|
-
* プロダクトスキーマ
|
|
57
|
-
*/
|
|
58
|
-
let schema;
|
|
59
|
-
function createSchema() {
|
|
60
|
-
if (schema === undefined) {
|
|
61
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
62
|
-
}
|
|
63
|
-
return schema;
|
|
64
|
-
}
|
|
65
|
-
exports.createSchema = createSchema;
|
|
66
49
|
const indexes = [
|
|
67
50
|
[
|
|
68
51
|
{ createdAt: 1 },
|
|
@@ -74,15 +57,11 @@ const indexes = [
|
|
|
74
57
|
],
|
|
75
58
|
[
|
|
76
59
|
{ productID: 1 },
|
|
77
|
-
{
|
|
78
|
-
name: 'searchByProductID'
|
|
79
|
-
}
|
|
60
|
+
{ name: 'searchByProductID' }
|
|
80
61
|
],
|
|
81
62
|
[
|
|
82
63
|
{ 'project.id': 1, productID: 1 },
|
|
83
|
-
{
|
|
84
|
-
name: 'searchByProjectId-v20220721'
|
|
85
|
-
}
|
|
64
|
+
{ name: 'searchByProjectId-v20220721' }
|
|
86
65
|
],
|
|
87
66
|
[
|
|
88
67
|
{ 'hasOfferCatalog.id': 1, productID: 1 },
|
|
@@ -122,9 +101,7 @@ const indexes = [
|
|
|
122
101
|
],
|
|
123
102
|
[
|
|
124
103
|
{ typeOf: 1, productID: 1 },
|
|
125
|
-
{
|
|
126
|
-
name: 'searchByTypeOf'
|
|
127
|
-
}
|
|
104
|
+
{ name: 'searchByTypeOf' }
|
|
128
105
|
],
|
|
129
106
|
[
|
|
130
107
|
{ 'name.ja': 1, productID: 1 },
|
|
@@ -143,15 +120,22 @@ const indexes = [
|
|
|
143
120
|
'name.en': { $exists: true }
|
|
144
121
|
}
|
|
145
122
|
}
|
|
146
|
-
],
|
|
147
|
-
[
|
|
148
|
-
{ 'provider.id': 1, productID: 1 },
|
|
149
|
-
{
|
|
150
|
-
name: 'searchByProviderId',
|
|
151
|
-
partialFilterExpression: {
|
|
152
|
-
'provider.id': { $exists: true }
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
123
|
]
|
|
156
124
|
];
|
|
157
125
|
exports.indexes = indexes;
|
|
126
|
+
/**
|
|
127
|
+
* プロダクトスキーマ
|
|
128
|
+
*/
|
|
129
|
+
let schema;
|
|
130
|
+
function createSchema() {
|
|
131
|
+
if (schema === undefined) {
|
|
132
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
133
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
134
|
+
indexes.forEach((indexParams) => {
|
|
135
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return schema;
|
|
140
|
+
}
|
|
141
|
+
exports.createSchema = createSchema;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchema = exports.indexes = exports.modelName = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const writeConcern_1 = require("../writeConcern");
|
|
6
|
+
const settings_1 = require("../../../settings");
|
|
7
|
+
const modelName = 'ProductModel';
|
|
8
|
+
exports.modelName = modelName;
|
|
9
|
+
const schemaDefinition = {
|
|
10
|
+
project: mongoose_1.SchemaTypes.Mixed,
|
|
11
|
+
typeOf: { type: String, required: true },
|
|
12
|
+
category: mongoose_1.SchemaTypes.Mixed,
|
|
13
|
+
name: mongoose_1.SchemaTypes.Mixed,
|
|
14
|
+
offers: mongoose_1.SchemaTypes.Mixed
|
|
15
|
+
};
|
|
16
|
+
const schemaOptions = {
|
|
17
|
+
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
18
|
+
autoCreate: false,
|
|
19
|
+
collection: 'productModels',
|
|
20
|
+
id: true,
|
|
21
|
+
read: settings_1.MONGO_READ_PREFERENCE,
|
|
22
|
+
writeConcern: writeConcern_1.writeConcern,
|
|
23
|
+
strict: true,
|
|
24
|
+
strictQuery: false,
|
|
25
|
+
timestamps: {
|
|
26
|
+
createdAt: 'createdAt',
|
|
27
|
+
updatedAt: 'updatedAt'
|
|
28
|
+
},
|
|
29
|
+
toJSON: {
|
|
30
|
+
getters: false,
|
|
31
|
+
virtuals: false,
|
|
32
|
+
minimize: false,
|
|
33
|
+
versionKey: false
|
|
34
|
+
},
|
|
35
|
+
toObject: {
|
|
36
|
+
getters: false,
|
|
37
|
+
virtuals: true,
|
|
38
|
+
minimize: false,
|
|
39
|
+
versionKey: false
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const indexes = [
|
|
43
|
+
[
|
|
44
|
+
{ createdAt: 1 },
|
|
45
|
+
{ name: 'searchByCreatedAt' }
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
{ updatedAt: 1 },
|
|
49
|
+
{ name: 'searchByUpdatedAt' }
|
|
50
|
+
]
|
|
51
|
+
];
|
|
52
|
+
exports.indexes = indexes;
|
|
53
|
+
/**
|
|
54
|
+
* プロダクトモデルスキーマ
|
|
55
|
+
*/
|
|
56
|
+
let schema;
|
|
57
|
+
function createSchema() {
|
|
58
|
+
if (schema === undefined) {
|
|
59
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
60
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
61
|
+
indexes.forEach((indexParams) => {
|
|
62
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return schema;
|
|
67
|
+
}
|
|
68
|
+
exports.createSchema = createSchema;
|
|
@@ -11,7 +11,6 @@ type ISearchConditions4paymentService = factory.service.paymentService.ISearchCo
|
|
|
11
11
|
*/
|
|
12
12
|
export declare class MongoRepository {
|
|
13
13
|
private readonly paymentServiceModel;
|
|
14
|
-
private readonly productModel;
|
|
15
14
|
constructor(connection: Connection);
|
|
16
15
|
static CREATE_MONGO_CONDITIONS(params: ISearchConditions4paymentService): FilterQuery<import("@chevre/factory/lib/service/paymentService").IService>[];
|
|
17
16
|
/**
|
|
@@ -52,7 +51,5 @@ export declare class MongoRepository {
|
|
|
52
51
|
typeOf: factory.service.paymentService.PaymentServiceType.CreditCard | factory.service.paymentService.PaymentServiceType.MovieTicket;
|
|
53
52
|
id: string;
|
|
54
53
|
}): Promise<factory.product.IAvailableChannel>;
|
|
55
|
-
migratePaymentServicesToNewCollection(): Promise<void>;
|
|
56
|
-
deleteOldPaymentServices(): Promise<import("mongodb").DeleteResult>;
|
|
57
54
|
}
|
|
58
55
|
export {};
|
|
@@ -21,17 +21,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.MongoRepository = void 0;
|
|
24
|
-
const paymentService_1 = require("./mongoose/schemas/paymentService");
|
|
25
|
-
const product_1 = require("./mongoose/schemas/product");
|
|
26
24
|
const factory = require("../factory");
|
|
27
25
|
const settings_1 = require("../settings");
|
|
26
|
+
const paymentService_1 = require("./mongoose/schemas/paymentService");
|
|
28
27
|
/**
|
|
29
28
|
* 決済サービスリポジトリ
|
|
30
29
|
*/
|
|
31
30
|
class MongoRepository {
|
|
32
31
|
constructor(connection) {
|
|
33
32
|
this.paymentServiceModel = connection.model(paymentService_1.modelName, (0, paymentService_1.createSchema)());
|
|
34
|
-
this.productModel = connection.model(product_1.modelName, (0, product_1.createSchema)());
|
|
35
33
|
}
|
|
36
34
|
// tslint:disable-next-line:max-func-body-length
|
|
37
35
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
@@ -266,47 +264,5 @@ class MongoRepository {
|
|
|
266
264
|
return availableChannel;
|
|
267
265
|
});
|
|
268
266
|
}
|
|
269
|
-
migratePaymentServicesToNewCollection() {
|
|
270
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
-
const cursor = this.productModel.find({
|
|
272
|
-
typeOf: {
|
|
273
|
-
$in: [
|
|
274
|
-
factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
275
|
-
factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
276
|
-
]
|
|
277
|
-
}
|
|
278
|
-
// _id: { $eq: 'xxx' }
|
|
279
|
-
})
|
|
280
|
-
.cursor();
|
|
281
|
-
let i = 0;
|
|
282
|
-
yield cursor.eachAsync((doc) => __awaiter(this, void 0, void 0, function* () {
|
|
283
|
-
i += 1;
|
|
284
|
-
const existingPaymentService = doc.toObject();
|
|
285
|
-
const { _id, id, createdAt, updatedAt, offers } = existingPaymentService, setFields = __rest(existingPaymentService, ["_id", "id", "createdAt", "updatedAt", "offers"]);
|
|
286
|
-
// tslint:disable-next-line:no-console
|
|
287
|
-
// console.log('migrating paymentService...', setFields, id, i);
|
|
288
|
-
yield this.paymentServiceModel.findByIdAndUpdate(id, {
|
|
289
|
-
// $setOnInsert: { _id },
|
|
290
|
-
$set: setFields
|
|
291
|
-
}, { upsert: true })
|
|
292
|
-
.exec();
|
|
293
|
-
// tslint:disable-next-line:no-console
|
|
294
|
-
console.log('paymentService migrated.', i);
|
|
295
|
-
}));
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
deleteOldPaymentServices() {
|
|
299
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
-
return this.productModel.deleteMany({
|
|
301
|
-
typeOf: {
|
|
302
|
-
$in: [
|
|
303
|
-
factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
304
|
-
factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
305
|
-
]
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
.exec();
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
267
|
}
|
|
312
268
|
exports.MongoRepository = MongoRepository;
|
|
@@ -109,5 +109,9 @@ export declare class MongoRepository {
|
|
|
109
109
|
};
|
|
110
110
|
}): Promise<void>;
|
|
111
111
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
112
|
+
unsetUnnecessaryFields(params: {
|
|
113
|
+
filter: FilterQuery<factory.product.IProduct>;
|
|
114
|
+
$unset: any;
|
|
115
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
112
116
|
}
|
|
113
117
|
export {};
|
|
@@ -342,5 +342,11 @@ class MongoRepository {
|
|
|
342
342
|
.sort({ productID: factory.sortType.Ascending })
|
|
343
343
|
.cursor();
|
|
344
344
|
}
|
|
345
|
+
unsetUnnecessaryFields(params) {
|
|
346
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
347
|
+
return this.productModel.updateMany(params.filter, { $unset: params.$unset })
|
|
348
|
+
.exec();
|
|
349
|
+
});
|
|
350
|
+
}
|
|
345
351
|
}
|
|
346
352
|
exports.MongoRepository = MongoRepository;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
|
+
import * as factory from '../factory';
|
|
3
|
+
interface IProductModel {
|
|
4
|
+
id?: string;
|
|
5
|
+
project: {
|
|
6
|
+
id: string;
|
|
7
|
+
typeOf: factory.organizationType.Project;
|
|
8
|
+
};
|
|
9
|
+
typeOf: 'ProductModel';
|
|
10
|
+
category: Pick<factory.categoryCode.ICategoryCode, 'codeValue' | 'inCodeSet'>;
|
|
11
|
+
name: factory.multilingualString;
|
|
12
|
+
offers: {
|
|
13
|
+
typeOf: factory.offerType.Offer;
|
|
14
|
+
eligibleCustomerType?: {
|
|
15
|
+
codeValue: string;
|
|
16
|
+
}[];
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
type IKeyOfProjection = keyof IProductModel | '_id';
|
|
20
|
+
type ISearchConditions = Pick<factory.product.ISearchConditions, 'id' | 'limit' | 'page' | 'project'> & {
|
|
21
|
+
category?: {
|
|
22
|
+
codeValue?: {
|
|
23
|
+
$in?: string[];
|
|
24
|
+
};
|
|
25
|
+
inCodeSet?: {
|
|
26
|
+
identifier?: {
|
|
27
|
+
$eq?: string;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* プロダクトモデルリポジトリ
|
|
34
|
+
*/
|
|
35
|
+
export declare class MongoRepository {
|
|
36
|
+
private readonly productModelModel;
|
|
37
|
+
constructor(connection: Connection);
|
|
38
|
+
static CREATE_MONGO_CONDITIONS(params: ISearchConditions): FilterQuery<factory.product.IProduct>[];
|
|
39
|
+
search(conditions: ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<IProductModel[]>;
|
|
40
|
+
deleteById(params: {
|
|
41
|
+
id: string;
|
|
42
|
+
}): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* プロダクトを保管する
|
|
45
|
+
*/
|
|
46
|
+
save(params: {
|
|
47
|
+
/**
|
|
48
|
+
* idを指定すれば更新
|
|
49
|
+
*/
|
|
50
|
+
id?: string;
|
|
51
|
+
$set: IProductModel;
|
|
52
|
+
}): Promise<{
|
|
53
|
+
id: string;
|
|
54
|
+
}>;
|
|
55
|
+
deleteByProject(params: {
|
|
56
|
+
project: {
|
|
57
|
+
id: string;
|
|
58
|
+
};
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.MongoRepository = void 0;
|
|
24
|
+
const factory = require("../factory");
|
|
25
|
+
const settings_1 = require("../settings");
|
|
26
|
+
const productModel_1 = require("./mongoose/schemas/productModel");
|
|
27
|
+
/**
|
|
28
|
+
* プロダクトモデルリポジトリ
|
|
29
|
+
*/
|
|
30
|
+
class MongoRepository {
|
|
31
|
+
constructor(connection) {
|
|
32
|
+
this.productModelModel = connection.model(productModel_1.modelName, (0, productModel_1.createSchema)());
|
|
33
|
+
}
|
|
34
|
+
// tslint:disable-next-line:max-func-body-length
|
|
35
|
+
static CREATE_MONGO_CONDITIONS(params) {
|
|
36
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
37
|
+
// MongoDB検索条件
|
|
38
|
+
const andConditions = [];
|
|
39
|
+
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
40
|
+
if (typeof projectIdEq === 'string') {
|
|
41
|
+
andConditions.push({
|
|
42
|
+
'project.id': { $eq: projectIdEq }
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
|
|
46
|
+
if (typeof idEq === 'string') {
|
|
47
|
+
andConditions.push({ _id: { $eq: idEq } });
|
|
48
|
+
}
|
|
49
|
+
const idIn = (_d = params.id) === null || _d === void 0 ? void 0 : _d.$in;
|
|
50
|
+
if (Array.isArray(idIn)) {
|
|
51
|
+
andConditions.push({ _id: { $in: idIn } });
|
|
52
|
+
}
|
|
53
|
+
const categoryCodeValueIn = (_f = (_e = params.category) === null || _e === void 0 ? void 0 : _e.codeValue) === null || _f === void 0 ? void 0 : _f.$in;
|
|
54
|
+
if (Array.isArray(categoryCodeValueIn)) {
|
|
55
|
+
andConditions.push({ 'category.codeValue': { $exists: true, $in: categoryCodeValueIn } });
|
|
56
|
+
}
|
|
57
|
+
const categoryInCodeSetIdentifierEq = (_j = (_h = (_g = params.category) === null || _g === void 0 ? void 0 : _g.inCodeSet) === null || _h === void 0 ? void 0 : _h.identifier) === null || _j === void 0 ? void 0 : _j.$eq;
|
|
58
|
+
if (typeof categoryInCodeSetIdentifierEq === 'string') {
|
|
59
|
+
andConditions.push({ 'category.inCodeSet.identifier': { $exists: true, $eq: categoryInCodeSetIdentifierEq } });
|
|
60
|
+
}
|
|
61
|
+
return andConditions;
|
|
62
|
+
}
|
|
63
|
+
search(conditions, inclusion, exclusion) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const andConditions = MongoRepository.CREATE_MONGO_CONDITIONS(conditions);
|
|
66
|
+
let projection = {};
|
|
67
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
68
|
+
inclusion.forEach((field) => {
|
|
69
|
+
projection[field] = 1;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
projection = {
|
|
74
|
+
__v: 0,
|
|
75
|
+
createdAt: 0,
|
|
76
|
+
updatedAt: 0
|
|
77
|
+
};
|
|
78
|
+
if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
79
|
+
exclusion.forEach((field) => {
|
|
80
|
+
projection[field] = 0;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const query = this.productModelModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
|
|
85
|
+
if (typeof conditions.limit === 'number' && conditions.limit > 0) {
|
|
86
|
+
const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
|
|
87
|
+
query.limit(conditions.limit)
|
|
88
|
+
.skip(conditions.limit * (page - 1));
|
|
89
|
+
}
|
|
90
|
+
// if (conditions.sort?.productID !== undefined) {
|
|
91
|
+
// query.sort({ productID: conditions.sort.productID });
|
|
92
|
+
// }
|
|
93
|
+
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
94
|
+
.exec()
|
|
95
|
+
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
deleteById(params) {
|
|
99
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
yield this.productModelModel.findOneAndDelete({ _id: params.id })
|
|
101
|
+
.exec();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* プロダクトを保管する
|
|
106
|
+
*/
|
|
107
|
+
save(params) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
let doc;
|
|
110
|
+
if (typeof params.id === 'string') {
|
|
111
|
+
// 上書き禁止属性を除外
|
|
112
|
+
const _a = params.$set, { id, project, typeOf, offers } = _a, setFields = __rest(_a, ["id", "project", "typeOf", "offers"]);
|
|
113
|
+
doc = yield this.productModelModel.findOneAndUpdate({ _id: { $eq: params.id } }, {
|
|
114
|
+
$set: setFields
|
|
115
|
+
// $unset: params.$unset
|
|
116
|
+
}, { upsert: false, new: true, projection: { _id: 1 } })
|
|
117
|
+
.exec();
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const _b = params.$set, { id } = _b, createParams = __rest(_b, ["id"]);
|
|
121
|
+
doc = yield this.productModelModel.create(createParams);
|
|
122
|
+
}
|
|
123
|
+
if (doc === null) {
|
|
124
|
+
throw new factory.errors.NotFound(this.productModelModel.modelName);
|
|
125
|
+
}
|
|
126
|
+
return doc.toObject();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
deleteByProject(params) {
|
|
130
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
+
yield this.productModelModel.deleteMany({
|
|
132
|
+
'project.id': { $eq: params.project.id }
|
|
133
|
+
})
|
|
134
|
+
.exec();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.MongoRepository = MongoRepository;
|
|
@@ -41,6 +41,7 @@ import type { MongoRepository as SeatRepo } from './repo/place/seat';
|
|
|
41
41
|
import type { MongoRepository as SectionRepo } from './repo/place/section';
|
|
42
42
|
import type { MongoRepository as PriceSpecificationRepo } from './repo/priceSpecification';
|
|
43
43
|
import type { MongoRepository as ProductRepo } from './repo/product';
|
|
44
|
+
import type { MongoRepository as ProductModelRepo } from './repo/productModel';
|
|
44
45
|
import type { MongoRepository as ProductOfferRepo } from './repo/productOffer';
|
|
45
46
|
import type { MongoRepository as ProjectRepo } from './repo/project';
|
|
46
47
|
import type { MongoRepository as ProjectMakesOfferRepo } from './repo/projectMakesOffer';
|
|
@@ -262,6 +263,10 @@ export type Product = ProductRepo;
|
|
|
262
263
|
export declare namespace Product {
|
|
263
264
|
function createInstance(...params: ConstructorParameters<typeof ProductRepo>): Promise<ProductRepo>;
|
|
264
265
|
}
|
|
266
|
+
export type ProductModel = ProductModelRepo;
|
|
267
|
+
export declare namespace ProductModel {
|
|
268
|
+
function createInstance(...params: ConstructorParameters<typeof ProductModelRepo>): Promise<ProductModelRepo>;
|
|
269
|
+
}
|
|
265
270
|
export type ProductOffer = ProductOfferRepo;
|
|
266
271
|
export declare namespace ProductOffer {
|
|
267
272
|
function createInstance(...params: ConstructorParameters<typeof ProductOfferRepo>): Promise<ProductOfferRepo>;
|
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.TransactionNumber = exports.Transaction = exports.Telemetry = void 0;
|
|
12
|
+
exports.StockHolder = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.SellerPaymentAccepted = 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.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Code = 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.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = void 0;
|
|
14
14
|
var AcceptedOffer;
|
|
15
15
|
(function (AcceptedOffer) {
|
|
16
16
|
let repo;
|
|
@@ -607,6 +607,19 @@ var Product;
|
|
|
607
607
|
}
|
|
608
608
|
Product.createInstance = createInstance;
|
|
609
609
|
})(Product = exports.Product || (exports.Product = {}));
|
|
610
|
+
var ProductModel;
|
|
611
|
+
(function (ProductModel) {
|
|
612
|
+
let repo;
|
|
613
|
+
function createInstance(...params) {
|
|
614
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
if (repo === undefined) {
|
|
616
|
+
repo = (yield Promise.resolve().then(() => require('./repo/productModel'))).MongoRepository;
|
|
617
|
+
}
|
|
618
|
+
return new repo(...params);
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
ProductModel.createInstance = createInstance;
|
|
622
|
+
})(ProductModel = exports.ProductModel || (exports.ProductModel = {}));
|
|
610
623
|
var ProductOffer;
|
|
611
624
|
(function (ProductOffer) {
|
|
612
625
|
let repo;
|
package/package.json
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
// tslint:disable-next-line:max-func-body-length
|
|
7
|
-
async function main() {
|
|
8
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
9
|
-
|
|
10
|
-
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
11
|
-
|
|
12
|
-
const result = await paymentServiceRepo.deleteOldPaymentServices();
|
|
13
|
-
console.log(result);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
main()
|
|
17
|
-
.then()
|
|
18
|
-
.catch(console.error);
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as mongoose from 'mongoose';
|
|
3
|
-
|
|
4
|
-
import { chevre } from '../../../lib/index';
|
|
5
|
-
|
|
6
|
-
mongoose.Model.on('index', (...args) => {
|
|
7
|
-
console.error('******** index event emitted. ********\n', args);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
// tslint:disable-next-line:max-func-body-length
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: process.env.MONGO_AUTO_INDEX === '1' });
|
|
13
|
-
|
|
14
|
-
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
await paymentServiceRepo.migratePaymentServicesToNewCollection();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
main()
|
|
20
|
-
.then()
|
|
21
|
-
.catch(console.error);
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
const CLIENT_ID = 'xxxx';
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
11
|
-
|
|
12
|
-
const projectMakesOfferRepo = await chevre.repository.ProjectMakesOffer.createInstance(mongoose.connection);
|
|
13
|
-
const result = await projectMakesOfferRepo.search({
|
|
14
|
-
limit: 100,
|
|
15
|
-
page: 1,
|
|
16
|
-
offeredBy: { id: { $eq: project.id } },
|
|
17
|
-
availableAtOrFrom: { id: { $eq: CLIENT_ID } }
|
|
18
|
-
});
|
|
19
|
-
console.log('result:', result);
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
await projectMakesOfferRepo.create({
|
|
23
|
-
availableAtOrFrom: { id: CLIENT_ID },
|
|
24
|
-
offeredBy: { id: project.id }
|
|
25
|
-
});
|
|
26
|
-
console.log('offer created');
|
|
27
|
-
} catch (error) {
|
|
28
|
-
console.error(error);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
await projectMakesOfferRepo.updateOne({
|
|
32
|
-
availableAtOrFrom: { id: CLIENT_ID },
|
|
33
|
-
eligibleCustomerType: [{ codeValue: 'Enduser' }],
|
|
34
|
-
offeredBy: { id: project.id }
|
|
35
|
-
});
|
|
36
|
-
console.log('offer updated');
|
|
37
|
-
|
|
38
|
-
await projectMakesOfferRepo.deleteOne({
|
|
39
|
-
availableAtOrFrom: { id: CLIENT_ID },
|
|
40
|
-
offeredBy: { id: project.id }
|
|
41
|
-
});
|
|
42
|
-
console.log('offer deleted');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
main()
|
|
46
|
-
.then(console.log)
|
|
47
|
-
.catch(console.error);
|