@chevre/domain 22.5.0-alpha.19 → 22.5.0-alpha.20
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.
|
@@ -0,0 +1,98 @@
|
|
|
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 excludedProject = { id: String(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 eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = eventRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'project.id': { $ne: excludedProject.id },
|
|
19
|
+
startDate: {
|
|
20
|
+
$gte: moment()
|
|
21
|
+
.add(-1, 'days')
|
|
22
|
+
.toDate()
|
|
23
|
+
},
|
|
24
|
+
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
|
|
25
|
+
// _id: { $eq: 'blyk9q24f' }
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
_id: 1,
|
|
29
|
+
offers: 1,
|
|
30
|
+
startDate: 1,
|
|
31
|
+
project: 1,
|
|
32
|
+
typeOf: 1
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
console.log('events found');
|
|
36
|
+
|
|
37
|
+
let i = 0;
|
|
38
|
+
let updateCount = 0;
|
|
39
|
+
await cursor.eachAsync(async (doc) => {
|
|
40
|
+
i += 1;
|
|
41
|
+
const event: Pick<
|
|
42
|
+
chevre.factory.event.screeningEvent.IEvent,
|
|
43
|
+
'id' | 'offers' | 'startDate' | 'project' | 'typeOf'
|
|
44
|
+
> = doc.toObject();
|
|
45
|
+
|
|
46
|
+
console.log(
|
|
47
|
+
'alreadyMigrated?', event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
48
|
+
const originMakesOffer = event.offers.seller.makesOffer;
|
|
49
|
+
const alreadyMigrated = Array.isArray(originMakesOffer)
|
|
50
|
+
&& originMakesOffer.every(
|
|
51
|
+
({ availableAtOrFrom }) => !Array.isArray(availableAtOrFrom) && typeof availableAtOrFrom?.id === 'string'
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (alreadyMigrated) {
|
|
55
|
+
console.log(
|
|
56
|
+
'already migrated.', event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
57
|
+
} else {
|
|
58
|
+
const newMakesOffer: chevre.factory.event.screeningEvent.ISellerMakesOffer[] = originMakesOffer.map((offer) => {
|
|
59
|
+
let newAvailableAtOrFrom: { id: string } | undefined;
|
|
60
|
+
if (Array.isArray(offer.availableAtOrFrom)) {
|
|
61
|
+
newAvailableAtOrFrom = offer.availableAtOrFrom.at(0);
|
|
62
|
+
}
|
|
63
|
+
if (newAvailableAtOrFrom === undefined) {
|
|
64
|
+
throw new Error('newAvailableAtOrFrom undefined');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
...offer,
|
|
69
|
+
availableAtOrFrom: newAvailableAtOrFrom
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
console.log(
|
|
73
|
+
'updating project...',
|
|
74
|
+
event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
75
|
+
await eventRepo.updatePartiallyById({
|
|
76
|
+
project: { id: event.project.id },
|
|
77
|
+
id: event.id,
|
|
78
|
+
attributes: {
|
|
79
|
+
typeOf: event.typeOf,
|
|
80
|
+
...{
|
|
81
|
+
'offers.seller.makesOffer': newMakesOffer
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
updateCount += 1;
|
|
86
|
+
console.log(
|
|
87
|
+
'updated.',
|
|
88
|
+
event.project.id, event.typeOf, event.id, event.startDate, i);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log(i, 'events checked');
|
|
93
|
+
console.log(updateCount, 'events updated');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
main()
|
|
97
|
+
.then()
|
|
98
|
+
.catch(console.error);
|
|
@@ -45,8 +45,8 @@ async function main() {
|
|
|
45
45
|
},
|
|
46
46
|
offers: {
|
|
47
47
|
typeOf: chevre.factory.offerType.Offer,
|
|
48
|
-
availabilityEnds: new Date('2024-09-15T11:45:00.000Z'),
|
|
49
|
-
availabilityStarts: new Date('2024-09-01T15:00:00.000Z'),
|
|
48
|
+
// availabilityEnds: new Date('2024-09-15T11:45:00.000Z'),
|
|
49
|
+
// availabilityStarts: new Date('2024-09-01T15:00:00.000Z'),
|
|
50
50
|
eligibleQuantity: {
|
|
51
51
|
typeOf: 'QuantitativeValue',
|
|
52
52
|
unitCode: chevre.factory.unitCode.C62,
|
|
@@ -97,8 +97,8 @@ async function main() {
|
|
|
97
97
|
typeOf: 'CategoryCode'
|
|
98
98
|
}
|
|
99
99
|
},
|
|
100
|
-
validFrom: new Date('2024-09-01T15:00:00.000Z'),
|
|
101
|
-
validThrough: new Date('2024-09-15T11:45:00.000Z'),
|
|
100
|
+
// validFrom: new Date('2024-09-01T15:00:00.000Z'),
|
|
101
|
+
// validThrough: new Date('2024-09-15T11:45:00.000Z'),
|
|
102
102
|
seller: {
|
|
103
103
|
typeOf: chevre.factory.organizationType.Corporation,
|
|
104
104
|
id: '59d20831e53ebc2b4e774466',
|
package/package.json
CHANGED
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "4.386.0-alpha.
|
|
15
|
-
"@cinerino/sdk": "10.13.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.386.0-alpha.9",
|
|
15
|
+
"@cinerino/sdk": "10.13.0-alpha.11",
|
|
16
16
|
"@motionpicture/coa-service": "9.5.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.3.0",
|
|
18
18
|
"@sendgrid/mail": "6.4.0",
|
|
@@ -108,5 +108,5 @@
|
|
|
108
108
|
"postversion": "git push origin --tags",
|
|
109
109
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
110
110
|
},
|
|
111
|
-
"version": "22.5.0-alpha.
|
|
111
|
+
"version": "22.5.0-alpha.20"
|
|
112
112
|
}
|
|
@@ -1,78 +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
|
-
enum ROLE_NAME {
|
|
8
|
-
Customer = 'customer',
|
|
9
|
-
POS = 'pos'
|
|
10
|
-
}
|
|
11
|
-
const CLIENT_ID = '5an0cmki8v29vdmk627kdo1r0p';
|
|
12
|
-
const CUSTOMER_TYPE = 'Enduser';
|
|
13
|
-
|
|
14
|
-
// tslint:disable-next-line:max-func-body-length
|
|
15
|
-
async function main() {
|
|
16
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
17
|
-
|
|
18
|
-
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
19
|
-
const makesOfferRepo = await chevre.repository.ProjectMakesOffer.createInstance(mongoose.connection);
|
|
20
|
-
|
|
21
|
-
const cursor = memberRepo.getCursor(
|
|
22
|
-
{
|
|
23
|
-
'member.hasRole.roleName': { $in: [ROLE_NAME.Customer, ROLE_NAME.POS] },
|
|
24
|
-
'member.id': { $eq: CLIENT_ID }
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
// _id: 1,
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
console.log('members found');
|
|
31
|
-
|
|
32
|
-
let i = 0;
|
|
33
|
-
let updateCount = 0;
|
|
34
|
-
await cursor.eachAsync(async (doc) => {
|
|
35
|
-
i += 1;
|
|
36
|
-
const iamMember: chevre.factory.iam.IMember = doc.toObject();
|
|
37
|
-
|
|
38
|
-
const existingOffers = await makesOfferRepo.search({
|
|
39
|
-
offeredBy: { id: { $eq: iamMember.project.id } },
|
|
40
|
-
availableAtOrFrom: { id: { $eq: iamMember.member.id } }
|
|
41
|
-
});
|
|
42
|
-
const alreadyMigrated = existingOffers.length === 1
|
|
43
|
-
&& Array.isArray(existingOffers[0].eligibleCustomerType)
|
|
44
|
-
&& existingOffers[0].eligibleCustomerType.length === 1
|
|
45
|
-
&& existingOffers[0].eligibleCustomerType[0].codeValue === CUSTOMER_TYPE;
|
|
46
|
-
|
|
47
|
-
if (alreadyMigrated) {
|
|
48
|
-
console.log(
|
|
49
|
-
'already exist...', iamMember.project.id, iamMember.member.id, iamMember.member.typeOf, iamMember.member.name, i);
|
|
50
|
-
} else {
|
|
51
|
-
console.log(
|
|
52
|
-
'updating project...',
|
|
53
|
-
iamMember.project.id, iamMember.member.id, iamMember.member.typeOf, iamMember.member.name, i);
|
|
54
|
-
try {
|
|
55
|
-
await makesOfferRepo.updateOne({
|
|
56
|
-
availableAtOrFrom: { id: iamMember.member.id },
|
|
57
|
-
eligibleCustomerType: [{
|
|
58
|
-
codeValue: CUSTOMER_TYPE
|
|
59
|
-
}],
|
|
60
|
-
offeredBy: { id: iamMember.project.id }
|
|
61
|
-
});
|
|
62
|
-
} catch (error) {
|
|
63
|
-
console.error(error);
|
|
64
|
-
}
|
|
65
|
-
updateCount += 1;
|
|
66
|
-
console.log(
|
|
67
|
-
'updated.',
|
|
68
|
-
iamMember.project.id, iamMember.member.id, iamMember.member.typeOf, iamMember.member.name, i);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
console.log(i, 'members checked');
|
|
73
|
-
console.log(updateCount, 'members updated');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
main()
|
|
77
|
-
.then()
|
|
78
|
-
.catch(console.error);
|