@chevre/domain 21.20.1 → 21.21.0-alpha.1
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/lib/chevre/credentials.d.ts +1 -0
- package/lib/chevre/credentials.js +2 -1
- package/lib/chevre/repo/person.js +3 -2
- package/lib/chevre/repo/seller.d.ts +4 -0
- package/lib/chevre/repo/seller.js +6 -0
- package/package.json +1 -1
- package/example/src/chevre/migrateEventMakesOfferAvailableAtOrFrom.ts +0 -87
- package/example/src/chevre/migrateOfferAvailableAtOrFrom.ts +0 -63
|
@@ -7,7 +7,8 @@ exports.credentials = void 0;
|
|
|
7
7
|
exports.credentials = {
|
|
8
8
|
aws: {
|
|
9
9
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
10
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
|
|
10
|
+
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
11
|
+
tokenIssuerEndpoint: process.env.TOKEN_ISSUER_ENDPOINT
|
|
11
12
|
},
|
|
12
13
|
chevre: {
|
|
13
14
|
authorizeServerDomain: process.env.CHEVRE_AUTHORIZE_SERVER_DOMAIN,
|
|
@@ -15,7 +15,6 @@ const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
|
15
15
|
const google_libphonenumber_1 = require("google-libphonenumber");
|
|
16
16
|
const factory = require("../factory");
|
|
17
17
|
const awsCredentials = (0, credential_providers_1.fromEnv)();
|
|
18
|
-
const TOKEN_ISSUER_ENDPOINT = 'https://cognito-idp.ap-northeast-1.amazonaws.com';
|
|
19
18
|
/**
|
|
20
19
|
* 会員リポジトリ
|
|
21
20
|
*/
|
|
@@ -78,7 +77,9 @@ class CognitoRepository {
|
|
|
78
77
|
const profile = CognitoRepository.ATTRIBUTE2PROFILE(params);
|
|
79
78
|
const identifier = [];
|
|
80
79
|
if (typeof params.userPoolId === 'string') {
|
|
81
|
-
identifier.push(
|
|
80
|
+
// identifier.push(
|
|
81
|
+
// { name: 'iss', value: `${credentials.aws.tokenIssuerEndpoint}/${params.userPoolId}` }
|
|
82
|
+
// );
|
|
82
83
|
}
|
|
83
84
|
const person = Object.assign(Object.assign({}, profile), { typeOf: factory.personType.Person, id: '', identifier: identifier, memberOf: {
|
|
84
85
|
membershipNumber: params.username,
|
|
@@ -82,6 +82,10 @@ export declare class MongoRepository {
|
|
|
82
82
|
id: string;
|
|
83
83
|
};
|
|
84
84
|
}): Promise<void>;
|
|
85
|
+
addAvailableAtOrFrom(params: {
|
|
86
|
+
id: string;
|
|
87
|
+
makesOffer: factory.seller.IMakesOffer;
|
|
88
|
+
}): Promise<any>;
|
|
85
89
|
getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
|
|
86
90
|
unsetUnnecessaryFields(params: {
|
|
87
91
|
filter: any;
|
|
@@ -303,6 +303,12 @@ class MongoRepository {
|
|
|
303
303
|
.exec();
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
|
+
addAvailableAtOrFrom(params) {
|
|
307
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
return this.organizationModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $push: { makesOffer: params.makesOffer } })
|
|
309
|
+
.exec();
|
|
310
|
+
});
|
|
311
|
+
}
|
|
306
312
|
getCursor(conditions, projection) {
|
|
307
313
|
return this.organizationModel.find(conditions, projection)
|
|
308
314
|
.sort({ branchCode: factory.sortType.Ascending })
|
package/package.json
CHANGED
|
@@ -1,87 +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 OLD_CLIENT = String(process.env.OLD_CLIENT);
|
|
8
|
-
const NEW_CLIENT = String(process.env.NEW_CLIENT);
|
|
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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = eventRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
'project.id': { $eq: project.id },
|
|
19
|
-
// _id: { $eq: 'als04raei' },
|
|
20
|
-
'offers.seller.makesOffer.availableAtOrFrom.id': { $eq: OLD_CLIENT },
|
|
21
|
-
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
_id: 1,
|
|
25
|
-
offers: 1,
|
|
26
|
-
project: 1,
|
|
27
|
-
startDate: 1
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
console.log('events found');
|
|
31
|
-
|
|
32
|
-
let i = 0;
|
|
33
|
-
let updateCount = 0;
|
|
34
|
-
await cursor.eachAsync(async (doc) => {
|
|
35
|
-
i += 1;
|
|
36
|
-
const event: Pick<
|
|
37
|
-
chevre.factory.event.screeningEvent.IEvent,
|
|
38
|
-
'id' | 'offers' | 'project' | 'startDate'
|
|
39
|
-
> = doc.toObject();
|
|
40
|
-
|
|
41
|
-
const eventOffers = <chevre.factory.event.screeningEvent.IOffer>event.offers;
|
|
42
|
-
const alreadyMigrated = eventOffers.seller.makesOffer.some(
|
|
43
|
-
({ availableAtOrFrom }) => availableAtOrFrom?.some((({ id }) => id === NEW_CLIENT))
|
|
44
|
-
);
|
|
45
|
-
const offerOnOldClient = eventOffers.seller.makesOffer.find(
|
|
46
|
-
({ availableAtOrFrom }) => availableAtOrFrom?.some((({ id }) => id === OLD_CLIENT))
|
|
47
|
-
);
|
|
48
|
-
if (offerOnOldClient === undefined) {
|
|
49
|
-
throw new Error('!oldClientExists');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (alreadyMigrated) {
|
|
53
|
-
await eventRepo.deleteAvailableAtOrFrom({
|
|
54
|
-
id: String(event.id),
|
|
55
|
-
offers: {
|
|
56
|
-
seller: {
|
|
57
|
-
makesOffer: { availableAtOrFrom: { id: OLD_CLIENT } }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
console.log('already exist.', event.project.id, event.id, event.startDate, i);
|
|
62
|
-
} else {
|
|
63
|
-
const offerNewOldClient: chevre.factory.event.screeningEvent.ISellerMakesOffer = {
|
|
64
|
-
...offerOnOldClient,
|
|
65
|
-
availableAtOrFrom: [{ id: NEW_CLIENT }]
|
|
66
|
-
};
|
|
67
|
-
console.log('updating...', event.project.id, event.id, event.startDate, i);
|
|
68
|
-
await eventRepo.addAvailableAtOrFrom({
|
|
69
|
-
id: String(event.id),
|
|
70
|
-
offers: {
|
|
71
|
-
seller: {
|
|
72
|
-
makesOffer: offerNewOldClient
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
updateCount += 1;
|
|
77
|
-
console.log('updated.', event.project.id, event.id, event.startDate, i);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
console.log(i, 'offers checked');
|
|
82
|
-
console.log(updateCount, 'offers updated');
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
main()
|
|
86
|
-
.then()
|
|
87
|
-
.catch(console.error);
|
|
@@ -1,63 +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 OLD_CLIENT = String(process.env.OLD_CLIENT);
|
|
8
|
-
const NEW_CLIENT = String(process.env.NEW_CLIENT);
|
|
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 offerRepo = await chevre.repository.Offer.createInstance(mongoose.connection);
|
|
15
|
-
|
|
16
|
-
const cursor = offerRepo.getCursor(
|
|
17
|
-
{
|
|
18
|
-
'project.id': { $eq: project.id },
|
|
19
|
-
// _id: { $eq: 'blqm9a6ui' },
|
|
20
|
-
'offers.availableAtOrFrom.id': { $eq: OLD_CLIENT }
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
_id: 1,
|
|
24
|
-
offers: 1,
|
|
25
|
-
project: 1
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
console.log('offers found');
|
|
29
|
-
|
|
30
|
-
let i = 0;
|
|
31
|
-
let updateCount = 0;
|
|
32
|
-
await cursor.eachAsync(async (doc) => {
|
|
33
|
-
i += 1;
|
|
34
|
-
const aggregateOffer: chevre.factory.aggregateOffer.IAggregateOffer = doc.toObject();
|
|
35
|
-
|
|
36
|
-
const alreadyMigrated = aggregateOffer.offers[0].availableAtOrFrom?.some(({ id }) => id === NEW_CLIENT);
|
|
37
|
-
console.log(aggregateOffer.offers[0].availableAtOrFrom, i);
|
|
38
|
-
|
|
39
|
-
if (alreadyMigrated) {
|
|
40
|
-
await offerRepo.deleteAvailableAtOrFrom({
|
|
41
|
-
id: String(aggregateOffer.id),
|
|
42
|
-
offers: { availableAtOrFrom: { id: OLD_CLIENT } }
|
|
43
|
-
});
|
|
44
|
-
console.log('already exist.', aggregateOffer.project.id, aggregateOffer.id, i);
|
|
45
|
-
} else {
|
|
46
|
-
console.log('updating...', aggregateOffer.project.id, aggregateOffer.id, i);
|
|
47
|
-
await offerRepo.addAvailableAtOrFrom({
|
|
48
|
-
id: String(aggregateOffer.id),
|
|
49
|
-
identifier: aggregateOffer.offers[0].identifier,
|
|
50
|
-
offers: { availableAtOrFrom: { id: NEW_CLIENT } }
|
|
51
|
-
});
|
|
52
|
-
updateCount += 1;
|
|
53
|
-
console.log('updated.', aggregateOffer.project.id, aggregateOffer.id, i);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
console.log(i, 'offers checked');
|
|
58
|
-
console.log(updateCount, 'offers updated');
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
main()
|
|
62
|
-
.then()
|
|
63
|
-
.catch(console.error);
|