@chevre/domain 22.3.0-alpha.0 → 22.3.0-alpha.2
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/migrateCustomerAdditionalProperties.ts +114 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +15 -2
- package/lib/chevre/repo/accountTitle.d.ts +4 -0
- package/lib/chevre/repo/accountTitle.js +6 -0
- package/lib/chevre/repo/customer.d.ts +4 -0
- package/lib/chevre/repo/customer.js +16 -22
- package/lib/chevre/repo/mongoose/schemas/accountTitle.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/accountTitle.js +36 -23
- package/lib/chevre/repo/mongoose/schemas/customer.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/customer.js +21 -23
- package/package.json +3 -3
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
// const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const additionalPropertyRepo = await chevre.repository.AdditionalProperty.createInstance(mongoose.connection);
|
|
15
|
+
const customerRepo = await chevre.repository.Customer.createInstance(mongoose.connection);
|
|
16
|
+
|
|
17
|
+
const cursor = customerRepo.getCursor(
|
|
18
|
+
{
|
|
19
|
+
// typeOf: { $eq: chevre.factory.placeType.ScreeningRoom }
|
|
20
|
+
// 'project.id': { $eq: project.id },
|
|
21
|
+
// 'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
// paymentMethods: 1,
|
|
25
|
+
// project: 1,
|
|
26
|
+
// orderDate: 1
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
console.log('docs found');
|
|
30
|
+
|
|
31
|
+
const additionalPropertyNames: string[] = [];
|
|
32
|
+
const projectIds: string[] = [];
|
|
33
|
+
const unexpextedprojectIds: string[] = [];
|
|
34
|
+
let checked: number = 0;
|
|
35
|
+
let created: number = 0;
|
|
36
|
+
|
|
37
|
+
let i = 0;
|
|
38
|
+
await cursor.eachAsync(async (doc) => {
|
|
39
|
+
i += 1;
|
|
40
|
+
const customer: chevre.factory.customer.ICustomer = doc.toObject();
|
|
41
|
+
|
|
42
|
+
const additionalPropertyNamesOnResource = (Array.isArray(customer.additionalProperty))
|
|
43
|
+
? customer.additionalProperty?.map((p) => p.name)
|
|
44
|
+
: [];
|
|
45
|
+
if (Array.isArray(additionalPropertyNamesOnResource) && additionalPropertyNamesOnResource.length > 0) {
|
|
46
|
+
console.log(
|
|
47
|
+
additionalPropertyNamesOnResource.join(','),
|
|
48
|
+
additionalPropertyNamesOnResource.length,
|
|
49
|
+
'additionalPropertyNamesOnResource found',
|
|
50
|
+
customer.project.id,
|
|
51
|
+
customer.branchCode
|
|
52
|
+
);
|
|
53
|
+
additionalPropertyNames.push(...additionalPropertyNamesOnResource);
|
|
54
|
+
projectIds.push(customer.project.id);
|
|
55
|
+
additionalPropertyNamesOnResource.forEach((name) => {
|
|
56
|
+
if (!name.match(/^[a-zA-Z]*$/)) {
|
|
57
|
+
unexpextedprojectIds.push(customer.project.id);
|
|
58
|
+
}
|
|
59
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
60
|
+
if (name.length < 5) {
|
|
61
|
+
unexpextedprojectIds.push(customer.project.id);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
for (const additionalPropertyNameOnResource of additionalPropertyNamesOnResource) {
|
|
66
|
+
checked += 1;
|
|
67
|
+
const existingAdditionalProperties = await additionalPropertyRepo.search({
|
|
68
|
+
limit: 1,
|
|
69
|
+
project: { id: { $eq: customer.project.id } },
|
|
70
|
+
codeValue: { $eq: additionalPropertyNameOnResource },
|
|
71
|
+
inCodeSet: { identifier: { $eq: customer.typeOf } }
|
|
72
|
+
});
|
|
73
|
+
if (existingAdditionalProperties.length === 0) {
|
|
74
|
+
const additionalProperty: chevre.factory.additionalProperty.IAdditionalProperty = {
|
|
75
|
+
project: customer.project,
|
|
76
|
+
// id?: string;
|
|
77
|
+
typeOf: 'CategoryCode',
|
|
78
|
+
codeValue: additionalPropertyNameOnResource,
|
|
79
|
+
inCodeSet: {
|
|
80
|
+
typeOf: 'CategoryCodeSet',
|
|
81
|
+
identifier: customer.typeOf
|
|
82
|
+
},
|
|
83
|
+
name: { ja: additionalPropertyNameOnResource }
|
|
84
|
+
};
|
|
85
|
+
await additionalPropertyRepo.save({ attributes: additionalProperty });
|
|
86
|
+
created += 1;
|
|
87
|
+
console.log(
|
|
88
|
+
'additionalProerty created',
|
|
89
|
+
additionalPropertyNameOnResource,
|
|
90
|
+
customer.project.id,
|
|
91
|
+
customer.branchCode
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
console.log(
|
|
95
|
+
'additionalProerty existed',
|
|
96
|
+
additionalPropertyNameOnResource,
|
|
97
|
+
customer.project.id,
|
|
98
|
+
customer.branchCode
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
console.log(i, 'places checked');
|
|
105
|
+
console.log('additionalPropertyNames:', [...new Set(additionalPropertyNames)]);
|
|
106
|
+
console.log('projectIds:', [...new Set(projectIds)]);
|
|
107
|
+
console.log('unexpextedprojectIds:', [...new Set(unexpextedprojectIds)]);
|
|
108
|
+
console.log('checked:', checked);
|
|
109
|
+
console.log('created:', created);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
main()
|
|
113
|
+
.then()
|
|
114
|
+
.catch(console.error);
|
|
@@ -6,10 +6,23 @@ import { chevre } from '../../../lib/index';
|
|
|
6
6
|
async function main() {
|
|
7
7
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const accountTitleRepo = await chevre.repository.AccountTitle.createInstance(mongoose.connection);
|
|
10
|
+
const customerRepo = await chevre.repository.Customer.createInstance(mongoose.connection);
|
|
10
11
|
|
|
11
12
|
let updateResult: any;
|
|
12
|
-
updateResult = await
|
|
13
|
+
updateResult = await customerRepo.unsetUnnecessaryFields({
|
|
14
|
+
filter: {
|
|
15
|
+
_id: { $exists: true }
|
|
16
|
+
},
|
|
17
|
+
$unset: {
|
|
18
|
+
createdAt: 1,
|
|
19
|
+
updatedAt: 1,
|
|
20
|
+
__v: 1
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
console.log(updateResult);
|
|
24
|
+
|
|
25
|
+
updateResult = await accountTitleRepo.unsetUnnecessaryFields({
|
|
13
26
|
filter: {
|
|
14
27
|
_id: { $exists: true }
|
|
15
28
|
},
|
|
@@ -41,4 +41,8 @@ export declare class AccountTitleRepo {
|
|
|
41
41
|
}, never>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, factory.accountTitle.IAccountTitle> & Omit<factory.accountTitle.IAccountTitle & {
|
|
42
42
|
_id: import("mongoose").Types.ObjectId;
|
|
43
43
|
}, never>>>;
|
|
44
|
+
unsetUnnecessaryFields(params: {
|
|
45
|
+
filter: any;
|
|
46
|
+
$unset: any;
|
|
47
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
44
48
|
}
|
|
@@ -32,5 +32,11 @@ class AccountTitleRepo {
|
|
|
32
32
|
.sort({ codeValue: factory.sortType.Descending })
|
|
33
33
|
.cursor();
|
|
34
34
|
}
|
|
35
|
+
unsetUnnecessaryFields(params) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return this.accountTitleModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
38
|
+
.exec();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
exports.AccountTitleRepo = AccountTitleRepo;
|
|
@@ -50,5 +50,9 @@ export declare class CustomerRepo {
|
|
|
50
50
|
}, never>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, factory.customer.ICustomer> & Omit<factory.customer.ICustomer & {
|
|
51
51
|
_id: import("mongoose").Types.ObjectId;
|
|
52
52
|
}, never>>>;
|
|
53
|
+
unsetUnnecessaryFields(params: {
|
|
54
|
+
filter: any;
|
|
55
|
+
$unset: any;
|
|
56
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
53
57
|
}
|
|
54
58
|
export {};
|
|
@@ -32,7 +32,7 @@ class CustomerRepo {
|
|
|
32
32
|
this.customerModel = connection.model(customer_1.modelName, (0, customer_1.createSchema)());
|
|
33
33
|
}
|
|
34
34
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
35
|
-
var _a, _b, _c, _d, _e;
|
|
35
|
+
var _a, _b, _c, _d, _e, _f;
|
|
36
36
|
const andConditions = [];
|
|
37
37
|
const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
|
|
38
38
|
if (typeof projectIdEq === 'string') {
|
|
@@ -55,29 +55,17 @@ class CustomerRepo {
|
|
|
55
55
|
]
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
|
+
const additionalPropertyElemMatch = (_f = params.additionalProperty) === null || _f === void 0 ? void 0 : _f.$elemMatch;
|
|
59
|
+
if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
|
|
60
|
+
andConditions.push({
|
|
61
|
+
additionalProperty: {
|
|
62
|
+
$exists: true,
|
|
63
|
+
$elemMatch: additionalPropertyElemMatch
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
58
67
|
return andConditions;
|
|
59
68
|
}
|
|
60
|
-
// public async findById(
|
|
61
|
-
// conditions: {
|
|
62
|
-
// id: string;
|
|
63
|
-
// },
|
|
64
|
-
// projection?: any
|
|
65
|
-
// ): Promise<factory.customer.ICustomer> {
|
|
66
|
-
// const doc = await this.customerModel.findOne(
|
|
67
|
-
// { _id: conditions.id },
|
|
68
|
-
// {
|
|
69
|
-
// __v: 0,
|
|
70
|
-
// createdAt: 0,
|
|
71
|
-
// updatedAt: 0,
|
|
72
|
-
// ...projection
|
|
73
|
-
// }
|
|
74
|
-
// )
|
|
75
|
-
// .exec();
|
|
76
|
-
// if (doc === null) {
|
|
77
|
-
// throw new factory.errors.NotFound(this.customerModel.modelName);
|
|
78
|
-
// }
|
|
79
|
-
// return doc.toObject();
|
|
80
|
-
// }
|
|
81
69
|
save(params) {
|
|
82
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
71
|
let customer;
|
|
@@ -132,5 +120,11 @@ class CustomerRepo {
|
|
|
132
120
|
.sort({ branchCode: factory.sortType.Ascending })
|
|
133
121
|
.cursor();
|
|
134
122
|
}
|
|
123
|
+
unsetUnnecessaryFields(params) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
return this.customerModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
126
|
+
.exec();
|
|
127
|
+
});
|
|
128
|
+
}
|
|
135
129
|
}
|
|
136
130
|
exports.CustomerRepo = CustomerRepo;
|
|
@@ -5,6 +5,6 @@ type IModel = Model<IDocType>;
|
|
|
5
5
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
6
6
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
7
7
|
declare const modelName = "AccountTitle";
|
|
8
|
-
declare function createSchema(): ISchema;
|
|
9
8
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
9
|
+
declare function createSchema(): ISchema;
|
|
10
10
|
export { createSchema, IModel, indexes, modelName };
|
|
@@ -21,6 +21,9 @@ const schemaDefinition = {
|
|
|
21
21
|
inDefinedTermSet: mongoose_1.SchemaTypes.Mixed,
|
|
22
22
|
hasDefinedTerm: mongoose_1.SchemaTypes.Mixed,
|
|
23
23
|
additionalProperty: mongoose_1.SchemaTypes.Mixed
|
|
24
|
+
// createdAt: SchemaTypes.Mixed,
|
|
25
|
+
// updatedAt: SchemaTypes.Mixed,
|
|
26
|
+
// __v: SchemaTypes.Mixed
|
|
24
27
|
};
|
|
25
28
|
const schemaOptions = {
|
|
26
29
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -30,10 +33,8 @@ const schemaOptions = {
|
|
|
30
33
|
read: settings_1.MONGO_READ_PREFERENCE,
|
|
31
34
|
writeConcern: writeConcern_1.writeConcern,
|
|
32
35
|
strictQuery: false,
|
|
33
|
-
timestamps:
|
|
34
|
-
|
|
35
|
-
updatedAt: 'updatedAt'
|
|
36
|
-
},
|
|
36
|
+
timestamps: false,
|
|
37
|
+
versionKey: false,
|
|
37
38
|
toJSON: {
|
|
38
39
|
getters: false,
|
|
39
40
|
virtuals: false,
|
|
@@ -47,26 +48,7 @@ const schemaOptions = {
|
|
|
47
48
|
versionKey: false
|
|
48
49
|
}
|
|
49
50
|
};
|
|
50
|
-
/**
|
|
51
|
-
* 勘定科目スキーマ
|
|
52
|
-
*/
|
|
53
|
-
let schema;
|
|
54
|
-
function createSchema() {
|
|
55
|
-
if (schema === undefined) {
|
|
56
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
57
|
-
}
|
|
58
|
-
return schema;
|
|
59
|
-
}
|
|
60
|
-
exports.createSchema = createSchema;
|
|
61
51
|
const indexes = [
|
|
62
|
-
[
|
|
63
|
-
{ createdAt: 1 },
|
|
64
|
-
{ name: 'searchByCreatedAt' }
|
|
65
|
-
],
|
|
66
|
-
[
|
|
67
|
-
{ updatedAt: 1 },
|
|
68
|
-
{ name: 'searchByUpdatedAt' }
|
|
69
|
-
],
|
|
70
52
|
[
|
|
71
53
|
{ codeValue: 1 },
|
|
72
54
|
{ name: 'searchByCodeValue' }
|
|
@@ -122,3 +104,34 @@ const indexes = [
|
|
|
122
104
|
]
|
|
123
105
|
];
|
|
124
106
|
exports.indexes = indexes;
|
|
107
|
+
// 'hasCategoryCode.hasCategoryCode.codeValue': null のインデックスは作成されてうまくいかないので保留
|
|
108
|
+
// schema.index(
|
|
109
|
+
// {
|
|
110
|
+
// 'project.id': 1,
|
|
111
|
+
// 'hasCategoryCode.hasCategoryCode.codeValue': 1
|
|
112
|
+
// },
|
|
113
|
+
// {
|
|
114
|
+
// name: 'uniqueHasCategoryCodeHasCategoryCodeCodeValue',
|
|
115
|
+
// unique: true,
|
|
116
|
+
// partialFilterExpression: {
|
|
117
|
+
// 'project.id': { $exists: true },
|
|
118
|
+
// 'hasCategoryCode.hasCategoryCode.codeValue': { $exists: true }
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
121
|
+
// );
|
|
122
|
+
/**
|
|
123
|
+
* 勘定科目スキーマ
|
|
124
|
+
*/
|
|
125
|
+
let schema;
|
|
126
|
+
function createSchema() {
|
|
127
|
+
if (schema === undefined) {
|
|
128
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
129
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
130
|
+
indexes.forEach((indexParams) => {
|
|
131
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return schema;
|
|
136
|
+
}
|
|
137
|
+
exports.createSchema = createSchema;
|
|
@@ -5,6 +5,6 @@ type IModel = Model<IDocType>;
|
|
|
5
5
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
6
6
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
7
7
|
declare const modelName = "Customer";
|
|
8
|
-
declare function createSchema(): ISchema;
|
|
9
8
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
9
|
+
declare function createSchema(): ISchema;
|
|
10
10
|
export { createSchema, IModel, indexes, modelName };
|
|
@@ -19,6 +19,9 @@ const schemaDefinition = {
|
|
|
19
19
|
},
|
|
20
20
|
url: String,
|
|
21
21
|
telephone: String
|
|
22
|
+
// createdAt: SchemaTypes.Mixed,
|
|
23
|
+
// updatedAt: SchemaTypes.Mixed,
|
|
24
|
+
// __v: SchemaTypes.Mixed
|
|
22
25
|
};
|
|
23
26
|
const schemaOptions = {
|
|
24
27
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -29,10 +32,8 @@ const schemaOptions = {
|
|
|
29
32
|
writeConcern: writeConcern_1.writeConcern,
|
|
30
33
|
strict: true,
|
|
31
34
|
strictQuery: false,
|
|
32
|
-
timestamps:
|
|
33
|
-
|
|
34
|
-
updatedAt: 'updatedAt'
|
|
35
|
-
},
|
|
35
|
+
timestamps: false,
|
|
36
|
+
versionKey: false,
|
|
36
37
|
toJSON: {
|
|
37
38
|
getters: false,
|
|
38
39
|
virtuals: false,
|
|
@@ -46,26 +47,7 @@ const schemaOptions = {
|
|
|
46
47
|
versionKey: false
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
|
-
/**
|
|
50
|
-
* 顧客スキーマ
|
|
51
|
-
*/
|
|
52
|
-
let schema;
|
|
53
|
-
function createSchema() {
|
|
54
|
-
if (schema === undefined) {
|
|
55
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
56
|
-
}
|
|
57
|
-
return schema;
|
|
58
|
-
}
|
|
59
|
-
exports.createSchema = createSchema;
|
|
60
50
|
const indexes = [
|
|
61
|
-
[
|
|
62
|
-
{ createdAt: 1 },
|
|
63
|
-
{ name: 'searchByCreatedAt' }
|
|
64
|
-
],
|
|
65
|
-
[
|
|
66
|
-
{ updatedAt: 1 },
|
|
67
|
-
{ name: 'searchByUpdatedAt' }
|
|
68
|
-
],
|
|
69
51
|
[
|
|
70
52
|
{ branchCode: 1 },
|
|
71
53
|
{ name: 'searchByBranchCode' }
|
|
@@ -96,3 +78,19 @@ const indexes = [
|
|
|
96
78
|
]
|
|
97
79
|
];
|
|
98
80
|
exports.indexes = indexes;
|
|
81
|
+
/**
|
|
82
|
+
* 顧客スキーマ
|
|
83
|
+
*/
|
|
84
|
+
let schema;
|
|
85
|
+
function createSchema() {
|
|
86
|
+
if (schema === undefined) {
|
|
87
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
88
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
89
|
+
indexes.forEach((indexParams) => {
|
|
90
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return schema;
|
|
95
|
+
}
|
|
96
|
+
exports.createSchema = createSchema;
|
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
}
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@chevre/factory": "4.
|
|
13
|
-
"@cinerino/sdk": "10.
|
|
12
|
+
"@chevre/factory": "4.383.0-alpha.1",
|
|
13
|
+
"@cinerino/sdk": "10.9.0-alpha.1",
|
|
14
14
|
"@motionpicture/coa-service": "9.5.0-alpha.0",
|
|
15
15
|
"@motionpicture/gmo-service": "5.3.0",
|
|
16
16
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"postversion": "git push origin --tags",
|
|
111
111
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
112
112
|
},
|
|
113
|
-
"version": "22.3.0-alpha.
|
|
113
|
+
"version": "22.3.0-alpha.2"
|
|
114
114
|
}
|