@chevre/domain 23.0.0-alpha.25 → 23.0.0-alpha.26
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/movieTicketType/migrateCollections.ts +15 -0
- package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.d.ts +22 -0
- package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +116 -0
- package/lib/chevre/repo/movieTicketType.d.ts +2 -12
- package/lib/chevre/repo/movieTicketType.js +37 -1
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// tslint:disable:no-console no-magic-numbers
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const movieTicketTypeRepo = await chevre.repository.MovieTicketType.createInstance(mongoose.connection);
|
|
10
|
+
await movieTicketTypeRepo.migrateCollections(mongoose.connection);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
main()
|
|
14
|
+
.then()
|
|
15
|
+
.catch(console.error);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
+
import * as factory from '../../../factory';
|
|
3
|
+
type IMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf'> & {
|
|
4
|
+
paymentMethod: {
|
|
5
|
+
/**
|
|
6
|
+
* 決済カード区分の場合、対応決済方法区分
|
|
7
|
+
*/
|
|
8
|
+
typeOf: string;
|
|
9
|
+
};
|
|
10
|
+
inCodeSet: {
|
|
11
|
+
typeOf: 'CategoryCodeSet';
|
|
12
|
+
identifier: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
type IDocType = factory.categoryCode.ICategoryCode;
|
|
16
|
+
type IModel = Model<IDocType>;
|
|
17
|
+
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
18
|
+
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
19
|
+
declare const modelName = "MovieTicketType";
|
|
20
|
+
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
21
|
+
declare function createSchema(): ISchema;
|
|
22
|
+
export { createSchema, IModel, IMovieTicketType, indexes, modelName };
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.modelName = exports.indexes = void 0;
|
|
4
|
+
exports.createSchema = createSchema;
|
|
5
|
+
const mongoose_1 = require("mongoose");
|
|
6
|
+
const writeConcern_1 = require("../writeConcern");
|
|
7
|
+
const settings_1 = require("../../../settings");
|
|
8
|
+
const modelName = 'MovieTicketType';
|
|
9
|
+
exports.modelName = modelName;
|
|
10
|
+
const schemaDefinition = {
|
|
11
|
+
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
|
+
typeOf: { type: String, required: true },
|
|
13
|
+
additionalProperty: [mongoose_1.SchemaTypes.Mixed],
|
|
14
|
+
color: String,
|
|
15
|
+
image: String,
|
|
16
|
+
codeValue: { type: String, required: true },
|
|
17
|
+
inCodeSet: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
18
|
+
name: mongoose_1.SchemaTypes.Mixed,
|
|
19
|
+
paymentMethod: { type: mongoose_1.SchemaTypes.Mixed, required: true }
|
|
20
|
+
};
|
|
21
|
+
const schemaOptions = {
|
|
22
|
+
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
23
|
+
autoCreate: false,
|
|
24
|
+
collection: 'movieTicketTypes',
|
|
25
|
+
id: true,
|
|
26
|
+
read: settings_1.MONGO_READ_PREFERENCE,
|
|
27
|
+
writeConcern: writeConcern_1.writeConcern,
|
|
28
|
+
strict: true,
|
|
29
|
+
strictQuery: false,
|
|
30
|
+
timestamps: false, // 2024-08-22~
|
|
31
|
+
versionKey: false, // 2024-08-22~
|
|
32
|
+
toJSON: {
|
|
33
|
+
getters: false,
|
|
34
|
+
virtuals: false,
|
|
35
|
+
minimize: false,
|
|
36
|
+
versionKey: false
|
|
37
|
+
},
|
|
38
|
+
toObject: {
|
|
39
|
+
getters: false,
|
|
40
|
+
virtuals: true,
|
|
41
|
+
minimize: false,
|
|
42
|
+
versionKey: false
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const indexes = [
|
|
46
|
+
[
|
|
47
|
+
{ codeValue: 1 },
|
|
48
|
+
{ name: 'codeValue' }
|
|
49
|
+
],
|
|
50
|
+
[
|
|
51
|
+
{ 'project.id': 1, codeValue: 1 },
|
|
52
|
+
{ name: 'projectId' }
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
{ 'paymentMethod.typeOf': 1, codeValue: 1 },
|
|
56
|
+
{ name: 'paymentMethodTypeOf' }
|
|
57
|
+
],
|
|
58
|
+
[
|
|
59
|
+
{ 'inCodeSet.identifier': 1, codeValue: 1 },
|
|
60
|
+
{ name: 'inCodeSetIdentifier' }
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
{
|
|
64
|
+
'project.id': 1,
|
|
65
|
+
'paymentMethod.typeOf': 1,
|
|
66
|
+
codeValue: 1
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
unique: true,
|
|
70
|
+
name: 'uniqueByCodeValueAndPaymentMethod'
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
{ 'name.ja': 1, codeValue: 1 },
|
|
75
|
+
{
|
|
76
|
+
name: 'nameJa',
|
|
77
|
+
partialFilterExpression: {
|
|
78
|
+
'name.ja': { $exists: true }
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
[
|
|
83
|
+
{ 'name.en': 1, codeValue: 1 },
|
|
84
|
+
{
|
|
85
|
+
name: 'nameEn',
|
|
86
|
+
partialFilterExpression: {
|
|
87
|
+
'name.en': { $exists: true }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
{ additionalProperty: 1, codeValue: 1 },
|
|
93
|
+
{
|
|
94
|
+
name: 'searchByAdditionalProperty',
|
|
95
|
+
partialFilterExpression: {
|
|
96
|
+
additionalProperty: { $exists: true }
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
];
|
|
101
|
+
exports.indexes = indexes;
|
|
102
|
+
/**
|
|
103
|
+
* 決済カード区分スキーマ
|
|
104
|
+
*/
|
|
105
|
+
let schema;
|
|
106
|
+
function createSchema() {
|
|
107
|
+
if (schema === undefined) {
|
|
108
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
109
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
110
|
+
indexes.forEach((indexParams) => {
|
|
111
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return schema;
|
|
116
|
+
}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
1
|
import { AnyExpression, Connection, FilterQuery } from 'mongoose';
|
|
2
|
+
import { IMovieTicketType } from './mongoose/schemas/movieTicketTypes';
|
|
2
3
|
import * as factory from '../factory';
|
|
3
4
|
type IUnset = {
|
|
4
5
|
[key in keyof Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'color' | 'image'>]?: 1;
|
|
5
6
|
};
|
|
6
|
-
type IMovieTicketType = Pick<factory.categoryCode.ICategoryCode, 'additionalProperty' | 'codeValue' | 'color' | 'id' | 'image' | 'name' | 'project' | 'typeOf'> & {
|
|
7
|
-
paymentMethod: {
|
|
8
|
-
/**
|
|
9
|
-
* 決済カード区分の場合、対応決済方法区分
|
|
10
|
-
*/
|
|
11
|
-
typeOf: string;
|
|
12
|
-
};
|
|
13
|
-
inCodeSet: {
|
|
14
|
-
typeOf: 'CategoryCodeSet';
|
|
15
|
-
identifier: factory.categoryCode.CategorySetIdentifier.MovieTicketType;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
7
|
type IKeyOfProjection = keyof IMovieTicketType;
|
|
19
8
|
/**
|
|
20
9
|
* 決済カード区分リポジトリ
|
|
@@ -64,5 +53,6 @@ export declare class MovieTicketTypeRepo {
|
|
|
64
53
|
id: string;
|
|
65
54
|
};
|
|
66
55
|
}): Promise<void>;
|
|
56
|
+
migrateCollections(connection: Connection): Promise<void>;
|
|
67
57
|
}
|
|
68
58
|
export {};
|
|
@@ -24,17 +24,24 @@ exports.MovieTicketTypeRepo = void 0;
|
|
|
24
24
|
// tslint:disable-next-line:no-implicit-dependencies
|
|
25
25
|
const mongoose_1 = require("mongoose");
|
|
26
26
|
const categoryCode_1 = require("./mongoose/schemas/categoryCode");
|
|
27
|
+
const movieTicketTypes_1 = require("./mongoose/schemas/movieTicketTypes");
|
|
27
28
|
const factory = require("../factory");
|
|
28
29
|
const settings_1 = require("../settings");
|
|
29
30
|
const AVAILABLE_PROJECT_FIELDS = [
|
|
30
31
|
'additionalProperty', 'codeValue', 'color', 'image', 'inCodeSet', 'name', 'paymentMethod', 'project', 'typeOf'
|
|
31
32
|
];
|
|
33
|
+
const USE_MOVIE_TICKET_TYPE_SCHEMA = process.env.USE_MOVIE_TICKET_TYPE_SCHEMA === '1';
|
|
32
34
|
/**
|
|
33
35
|
* 決済カード区分リポジトリ
|
|
34
36
|
*/
|
|
35
37
|
class MovieTicketTypeRepo {
|
|
36
38
|
constructor(connection) {
|
|
37
|
-
|
|
39
|
+
if (USE_MOVIE_TICKET_TYPE_SCHEMA) {
|
|
40
|
+
this.categoryCodeModel = connection.model(movieTicketTypes_1.modelName, (0, movieTicketTypes_1.createSchema)());
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this.categoryCodeModel = connection.model(categoryCode_1.modelName, (0, categoryCode_1.createSchema)());
|
|
44
|
+
}
|
|
38
45
|
}
|
|
39
46
|
// tslint:disable-next-line:cyclomatic-complexity max-func-body-length
|
|
40
47
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
@@ -258,5 +265,34 @@ class MovieTicketTypeRepo {
|
|
|
258
265
|
.exec();
|
|
259
266
|
});
|
|
260
267
|
}
|
|
268
|
+
// tslint:disable-next-line:prefer-function-over-method
|
|
269
|
+
migrateCollections(connection) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
const oldCategoryCodeModel = connection.model(categoryCode_1.modelName, (0, categoryCode_1.createSchema)());
|
|
272
|
+
const movieTicketTypeModel = connection.model(movieTicketTypes_1.modelName, (0, movieTicketTypes_1.createSchema)());
|
|
273
|
+
const cursor = oldCategoryCodeModel.find({
|
|
274
|
+
'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.MovieTicketType }
|
|
275
|
+
})
|
|
276
|
+
.sort({ codeValue: factory.sortType.Ascending })
|
|
277
|
+
.cursor();
|
|
278
|
+
let i = 0;
|
|
279
|
+
yield cursor.eachAsync((doc) => __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
i += 1;
|
|
281
|
+
const movieTicketType = doc.toObject();
|
|
282
|
+
// tslint:disable-next-line:no-console
|
|
283
|
+
console.log('upserting...', doc);
|
|
284
|
+
const result = yield movieTicketTypeModel.findOneAndReplace({ _id: { $eq: doc._id } }, doc, {
|
|
285
|
+
upsert: true,
|
|
286
|
+
projection: { _id: 1 }
|
|
287
|
+
})
|
|
288
|
+
.exec();
|
|
289
|
+
// await additionalPropertyRepo.save({ attributes: additionalProperty });
|
|
290
|
+
// tslint:disable-next-line:no-console
|
|
291
|
+
console.log('upserted', result, movieTicketType.id, movieTicketType.project.id, movieTicketType.codeValue);
|
|
292
|
+
}));
|
|
293
|
+
// tslint:disable-next-line:no-console
|
|
294
|
+
console.log(i, 'docs checked');
|
|
295
|
+
});
|
|
296
|
+
}
|
|
261
297
|
}
|
|
262
298
|
exports.MovieTicketTypeRepo = MovieTicketTypeRepo;
|
package/package.json
CHANGED