@chevre/domain 21.30.0 → 21.31.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/migrateMembers2.ts +74 -0
- package/example/src/chevre/unsetUnnecessaryFields.ts +4 -16
- package/lib/chevre/repo/member.d.ts +0 -15
- package/lib/chevre/repo/member.js +0 -18
- package/lib/chevre/repo/message.d.ts +4 -0
- package/lib/chevre/repo/message.js +6 -0
- package/lib/chevre/repo/mongoose/schemas/message.js +5 -12
- package/lib/chevre/repo/mongoose/schemas/paymentService.js +5 -12
- package/lib/chevre/repo/paymentService.d.ts +4 -0
- package/lib/chevre/repo/paymentService.js +6 -0
- package/package.json +1 -1
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
const NEW_ROLE_NAME = 'sellerAdmin';
|
|
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 memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = memberRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'member.memberOf.typeOf': { $eq: chevre.factory.organizationType.Project },
|
|
19
|
+
'member.hasRole.roleName': { $eq: 'inventoryManager' }
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
console.log('members found');
|
|
25
|
+
|
|
26
|
+
let i = 0;
|
|
27
|
+
let updateCount = 0;
|
|
28
|
+
await cursor.eachAsync(async (doc) => {
|
|
29
|
+
i += 1;
|
|
30
|
+
const inventoryManager: chevre.factory.iam.IMember = doc.toObject();
|
|
31
|
+
const alreadyMigrated = inventoryManager.member.hasRole.some(({ roleName }) => roleName === NEW_ROLE_NAME);
|
|
32
|
+
if (alreadyMigrated) {
|
|
33
|
+
console.log(
|
|
34
|
+
'already exist.',
|
|
35
|
+
inventoryManager.project.id,
|
|
36
|
+
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
updateCount += 1;
|
|
40
|
+
const newHasRole: chevre.factory.iam.IMemberRole[] = [
|
|
41
|
+
...inventoryManager.member.hasRole.map(({ roleName }) => {
|
|
42
|
+
return { typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName };
|
|
43
|
+
}),
|
|
44
|
+
{ typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName: NEW_ROLE_NAME }
|
|
45
|
+
].sort((a, b) => (a.roleName > b.roleName) ? 1 : -1);
|
|
46
|
+
console.log(
|
|
47
|
+
'updating...',
|
|
48
|
+
inventoryManager.project.id,
|
|
49
|
+
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount, newHasRole
|
|
50
|
+
);
|
|
51
|
+
await memberRepo.updateByMemberId({
|
|
52
|
+
project: { id: inventoryManager.project.id },
|
|
53
|
+
member: {
|
|
54
|
+
id: inventoryManager.member.id,
|
|
55
|
+
memberOf: inventoryManager.member.memberOf,
|
|
56
|
+
hasRole: newHasRole
|
|
57
|
+
},
|
|
58
|
+
$unset: {}
|
|
59
|
+
});
|
|
60
|
+
console.log(
|
|
61
|
+
'updated.',
|
|
62
|
+
inventoryManager.project.id,
|
|
63
|
+
inventoryManager.member.memberOf.typeOf, inventoryManager.member.memberOf.id, i, updateCount
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
console.log(i, 'members checked');
|
|
69
|
+
console.log(updateCount, 'members updated');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
main()
|
|
73
|
+
.then()
|
|
74
|
+
.catch(console.error);
|
|
@@ -8,22 +8,10 @@ async function main() {
|
|
|
8
8
|
|
|
9
9
|
let updateResult: any;
|
|
10
10
|
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const ownershipInfoRepo = await chevre.repository.OwnershipInfo.createInstance(mongoose.connection);
|
|
14
|
-
updateResult = await memberRepo.unsetUnnecessaryFields({
|
|
15
|
-
filter: {
|
|
16
|
-
_id: { $exists: true }
|
|
17
|
-
},
|
|
18
|
-
$unset: {
|
|
19
|
-
__v: 1,
|
|
20
|
-
createdAt: 1,
|
|
21
|
-
updatedAt: 1
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
console.log('unset processed.', updateResult);
|
|
11
|
+
const messageRepo = await chevre.repository.Message.createInstance(mongoose.connection);
|
|
12
|
+
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
25
13
|
|
|
26
|
-
updateResult = await
|
|
14
|
+
updateResult = await messageRepo.unsetUnnecessaryFields({
|
|
27
15
|
filter: {
|
|
28
16
|
_id: { $exists: true }
|
|
29
17
|
},
|
|
@@ -35,7 +23,7 @@ async function main() {
|
|
|
35
23
|
});
|
|
36
24
|
console.log('unset processed.', updateResult);
|
|
37
25
|
|
|
38
|
-
updateResult = await
|
|
26
|
+
updateResult = await paymentServiceRepo.unsetUnnecessaryFields({
|
|
39
27
|
filter: {
|
|
40
28
|
_id: { $exists: true }
|
|
41
29
|
},
|
|
@@ -88,21 +88,6 @@ export declare class MongoRepository {
|
|
|
88
88
|
'member.member'?: 1;
|
|
89
89
|
};
|
|
90
90
|
}): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* 互換性維持プログラム専用
|
|
93
|
-
*/
|
|
94
|
-
updateByMemberMemberOf(params: {
|
|
95
|
-
project: {
|
|
96
|
-
id: string;
|
|
97
|
-
};
|
|
98
|
-
member: {
|
|
99
|
-
id: string;
|
|
100
|
-
memberOf: {
|
|
101
|
-
id: string;
|
|
102
|
-
typeOf: factory.organizationType.Project;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
}): Promise<void>;
|
|
106
91
|
/**
|
|
107
92
|
* メンバー削除
|
|
108
93
|
*/
|
|
@@ -194,24 +194,6 @@ class MongoRepository {
|
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
/**
|
|
198
|
-
* 互換性維持プログラム専用
|
|
199
|
-
*/
|
|
200
|
-
updateByMemberMemberOf(params) {
|
|
201
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
const doc = yield this.memberModel.findOneAndUpdate({
|
|
203
|
-
'project.id': { $eq: params.project.id },
|
|
204
|
-
'member.id': { $eq: params.member.id },
|
|
205
|
-
'member.memberOf': { $exists: false }
|
|
206
|
-
}, {
|
|
207
|
-
'member.memberOf': params.member.memberOf
|
|
208
|
-
})
|
|
209
|
-
.exec();
|
|
210
|
-
if (doc === null) {
|
|
211
|
-
throw new factory.errors.NotFound(this.memberModel.modelName);
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
197
|
/**
|
|
216
198
|
* メンバー削除
|
|
217
199
|
*/
|
|
@@ -179,5 +179,11 @@ class MessageRepo {
|
|
|
179
179
|
});
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
+
unsetUnnecessaryFields(params) {
|
|
183
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
184
|
+
return this.messageModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
185
|
+
.exec();
|
|
186
|
+
});
|
|
187
|
+
}
|
|
182
188
|
}
|
|
183
189
|
exports.MessageRepo = MessageRepo;
|
|
@@ -39,6 +39,9 @@ const schemaDefinition = {
|
|
|
39
39
|
required: true
|
|
40
40
|
},
|
|
41
41
|
toRecipient: mongoose_1.SchemaTypes.Mixed
|
|
42
|
+
// __v: SchemaTypes.Mixed,
|
|
43
|
+
// createdAt: SchemaTypes.Mixed,
|
|
44
|
+
// updatedAt: SchemaTypes.Mixed
|
|
42
45
|
};
|
|
43
46
|
const schemaOptions = {
|
|
44
47
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -49,10 +52,8 @@ const schemaOptions = {
|
|
|
49
52
|
writeConcern: writeConcern_1.writeConcern,
|
|
50
53
|
strict: true,
|
|
51
54
|
strictQuery: false,
|
|
52
|
-
timestamps:
|
|
53
|
-
|
|
54
|
-
updatedAt: 'updatedAt'
|
|
55
|
-
},
|
|
55
|
+
timestamps: false,
|
|
56
|
+
versionKey: false,
|
|
56
57
|
toJSON: {
|
|
57
58
|
getters: false,
|
|
58
59
|
virtuals: false,
|
|
@@ -67,14 +68,6 @@ const schemaOptions = {
|
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
const indexes = [
|
|
70
|
-
[
|
|
71
|
-
{ createdAt: 1 },
|
|
72
|
-
{ name: 'searchByCreatedAt' }
|
|
73
|
-
],
|
|
74
|
-
[
|
|
75
|
-
{ updatedAt: 1 },
|
|
76
|
-
{ name: 'searchByUpdatedAt' }
|
|
77
|
-
],
|
|
78
71
|
[
|
|
79
72
|
{ datePublished: 1 },
|
|
80
73
|
{ name: 'searchByDatePublished' }
|
|
@@ -17,6 +17,9 @@ const schemaDefinition = {
|
|
|
17
17
|
provider: [mongoose_1.SchemaTypes.Mixed],
|
|
18
18
|
serviceOutput: mongoose_1.SchemaTypes.Mixed,
|
|
19
19
|
serviceType: mongoose_1.SchemaTypes.Mixed
|
|
20
|
+
// __v: SchemaTypes.Mixed,
|
|
21
|
+
// createdAt: SchemaTypes.Mixed,
|
|
22
|
+
// updatedAt: SchemaTypes.Mixed
|
|
20
23
|
};
|
|
21
24
|
const schemaOptions = {
|
|
22
25
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -27,10 +30,8 @@ const schemaOptions = {
|
|
|
27
30
|
writeConcern: writeConcern_1.writeConcern,
|
|
28
31
|
strict: true,
|
|
29
32
|
strictQuery: false,
|
|
30
|
-
timestamps:
|
|
31
|
-
|
|
32
|
-
updatedAt: 'updatedAt'
|
|
33
|
-
},
|
|
33
|
+
timestamps: false,
|
|
34
|
+
versionKey: false,
|
|
34
35
|
toJSON: {
|
|
35
36
|
getters: false,
|
|
36
37
|
virtuals: false,
|
|
@@ -45,14 +46,6 @@ const schemaOptions = {
|
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
const indexes = [
|
|
48
|
-
[
|
|
49
|
-
{ createdAt: 1 },
|
|
50
|
-
{ name: 'searchByCreatedAt' }
|
|
51
|
-
],
|
|
52
|
-
[
|
|
53
|
-
{ updatedAt: 1 },
|
|
54
|
-
{ name: 'searchByUpdatedAt' }
|
|
55
|
-
],
|
|
56
49
|
[
|
|
57
50
|
{ productID: 1 },
|
|
58
51
|
{
|
|
@@ -51,5 +51,9 @@ export declare class MongoRepository {
|
|
|
51
51
|
typeOf: factory.service.paymentService.PaymentServiceType.CreditCard | factory.service.paymentService.PaymentServiceType.MovieTicket;
|
|
52
52
|
id: string;
|
|
53
53
|
}): Promise<factory.product.IAvailableChannel>;
|
|
54
|
+
unsetUnnecessaryFields(params: {
|
|
55
|
+
filter: any;
|
|
56
|
+
$unset: any;
|
|
57
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
54
58
|
}
|
|
55
59
|
export {};
|
|
@@ -264,5 +264,11 @@ class MongoRepository {
|
|
|
264
264
|
return availableChannel;
|
|
265
265
|
});
|
|
266
266
|
}
|
|
267
|
+
unsetUnnecessaryFields(params) {
|
|
268
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
+
return this.paymentServiceModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
270
|
+
.exec();
|
|
271
|
+
});
|
|
272
|
+
}
|
|
267
273
|
}
|
|
268
274
|
exports.MongoRepository = MongoRepository;
|
package/package.json
CHANGED