@chevre/domain 20.1.0-alpha.8 → 20.1.0-alpha.9
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,127 @@
|
|
|
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
|
+
|
|
9
|
+
const AVAILABLE_ROLE_NAMES = ['customer', 'pos'];
|
|
10
|
+
const POS_CLIENT_ID = process.env.POS_CLIENT_ID;
|
|
11
|
+
if (typeof POS_CLIENT_ID !== 'string') {
|
|
12
|
+
throw new Error('set POS_CLIENT_ID');
|
|
13
|
+
}
|
|
14
|
+
const MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS = 93;
|
|
15
|
+
|
|
16
|
+
// tslint:disable-next-line:max-func-body-length
|
|
17
|
+
async function main() {
|
|
18
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
19
|
+
|
|
20
|
+
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
21
|
+
const memberRepo = new chevre.repository.Member(mongoose.connection);
|
|
22
|
+
|
|
23
|
+
const cursor = eventRepo.getCursor(
|
|
24
|
+
{
|
|
25
|
+
// 'project.id': { $eq: project.id },
|
|
26
|
+
'project.id': { $ne: 'sskts-test' },
|
|
27
|
+
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
|
|
28
|
+
startDate: {
|
|
29
|
+
$gte: moment()
|
|
30
|
+
.add(-1, 'month')
|
|
31
|
+
.toDate()
|
|
32
|
+
}
|
|
33
|
+
// _id: { $eq: 'al6aff83w' }
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// _id: 1,
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
console.log('events found');
|
|
40
|
+
|
|
41
|
+
let i = 0;
|
|
42
|
+
let updateCount = 0;
|
|
43
|
+
await cursor.eachAsync(async (doc) => {
|
|
44
|
+
i += 1;
|
|
45
|
+
const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
|
|
46
|
+
|
|
47
|
+
// IAMメンバー検索
|
|
48
|
+
const eventOffers = <chevre.factory.event.screeningEvent.IOffer | undefined>event.offers;
|
|
49
|
+
if (eventOffers === undefined) {
|
|
50
|
+
throw new Error('event.offers undefined');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const makesOfferFromEvent = eventOffers.seller.makesOffer;
|
|
54
|
+
|
|
55
|
+
if (Array.isArray(makesOfferFromEvent) && makesOfferFromEvent.length > 0) {
|
|
56
|
+
console.log(
|
|
57
|
+
'already exist...', event.project.id, event.id, makesOfferFromEvent.length, i);
|
|
58
|
+
} else {
|
|
59
|
+
let existingApplicationMembers = await memberRepo.search({
|
|
60
|
+
limit: 100,
|
|
61
|
+
page: 1,
|
|
62
|
+
project: { id: { $eq: event.project.id } },
|
|
63
|
+
member: { typeOf: { $eq: chevre.factory.creativeWorkType.WebApplication } }
|
|
64
|
+
});
|
|
65
|
+
// ロールで絞る(customer or pos)
|
|
66
|
+
existingApplicationMembers = existingApplicationMembers
|
|
67
|
+
.filter((m) => {
|
|
68
|
+
return Array.isArray(m.member.hasRole) && m.member.hasRole.some((r) => AVAILABLE_ROLE_NAMES.includes(r.roleName));
|
|
69
|
+
});
|
|
70
|
+
console.log(
|
|
71
|
+
existingApplicationMembers.length,
|
|
72
|
+
'existingApplicationMembers found.',
|
|
73
|
+
event.project.id,
|
|
74
|
+
existingApplicationMembers.map((m) => m.member.name)
|
|
75
|
+
.join(',')
|
|
76
|
+
);
|
|
77
|
+
const newMakesOffer: chevre.factory.event.screeningEvent.ISellerMakesOffer[] = existingApplicationMembers.map((a) => {
|
|
78
|
+
// posについては有効期間調整
|
|
79
|
+
if (a.member.id === POS_CLIENT_ID) {
|
|
80
|
+
const validFrom4pos: Date = moment(event.startDate)
|
|
81
|
+
.add(-MAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS, 'days')
|
|
82
|
+
.toDate();
|
|
83
|
+
const validThrough4pos: Date = moment(event.endDate)
|
|
84
|
+
.add(1, 'month')
|
|
85
|
+
.toDate();
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
89
|
+
availableAtOrFrom: [{ id: a.member.id }],
|
|
90
|
+
availabilityEnds: validThrough4pos, // 1 month later from endDate
|
|
91
|
+
availabilityStarts: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
|
|
92
|
+
validFrom: validFrom4pos, // startのMAXIMUM_RESERVATION_GRACE_PERIOD_IN_DAYS前
|
|
93
|
+
validThrough: validThrough4pos // 1 month later from endDate
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
return {
|
|
97
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
98
|
+
availableAtOrFrom: [{ id: a.member.id }],
|
|
99
|
+
availabilityEnds: eventOffers.availabilityEnds,
|
|
100
|
+
availabilityStarts: eventOffers.availabilityStarts,
|
|
101
|
+
validFrom: eventOffers.validFrom,
|
|
102
|
+
validThrough: eventOffers.validThrough
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
console.log(
|
|
107
|
+
'updating seller...', event.project.id, event.id, newMakesOffer.length, i);
|
|
108
|
+
await eventRepo.updatePartiallyById({
|
|
109
|
+
id: event.id,
|
|
110
|
+
attributes: <any>{
|
|
111
|
+
typeOf: event.typeOf,
|
|
112
|
+
'offers.seller.makesOffer': newMakesOffer
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
updateCount += 1;
|
|
116
|
+
console.log(
|
|
117
|
+
'updated...', event.project.id, event.id, newMakesOffer.length, i);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log(i, 'events checked');
|
|
122
|
+
console.log(updateCount, 'events updated');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
main()
|
|
126
|
+
.then()
|
|
127
|
+
.catch(console.error);
|
|
@@ -121,12 +121,11 @@ function validateCreateRequest(params) {
|
|
|
121
121
|
}
|
|
122
122
|
const bookingServiceIdentifire = offeredThrough.identifier;
|
|
123
123
|
if (bookingServiceIdentifire === factory.service.webAPI.Identifier.Chevre) {
|
|
124
|
+
if (params.validateEventOfferPeriod === true) {
|
|
125
|
+
validateEventOfferPeriod({ event, now });
|
|
126
|
+
}
|
|
124
127
|
if (params.validateEvent === true) {
|
|
125
|
-
validateEvent({
|
|
126
|
-
event,
|
|
127
|
-
now,
|
|
128
|
-
object: params.object
|
|
129
|
-
});
|
|
128
|
+
validateEvent({ event, object: params.object });
|
|
130
129
|
}
|
|
131
130
|
}
|
|
132
131
|
return { transaction, event, bookingServiceIdentifire };
|
|
@@ -204,8 +203,10 @@ function validateObjectWithoutDetail(params) {
|
|
|
204
203
|
return objectWithoutDetail;
|
|
205
204
|
});
|
|
206
205
|
}
|
|
207
|
-
|
|
208
|
-
|
|
206
|
+
/**
|
|
207
|
+
* イベントのオファー有効期間を検証する
|
|
208
|
+
*/
|
|
209
|
+
function validateEventOfferPeriod(params) {
|
|
209
210
|
const acceptedDate = moment(params.now);
|
|
210
211
|
const eventOffers = params.event.offers;
|
|
211
212
|
const validFrom = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.validFrom;
|
|
@@ -220,6 +221,32 @@ function validateEvent(params) {
|
|
|
220
221
|
throw new factory.errors.Argument('reservationFor.id', `Offer of ${params.event.id} is valid through ${validThrough}`);
|
|
221
222
|
}
|
|
222
223
|
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* イベントの上限座席数を検証する
|
|
227
|
+
*/
|
|
228
|
+
function validateEvent(params) {
|
|
229
|
+
var _a, _b;
|
|
230
|
+
// const acceptedDate = moment(params.now);
|
|
231
|
+
const eventOffers = params.event.offers;
|
|
232
|
+
// const validFrom = eventOffers?.validFrom;
|
|
233
|
+
// const validThrough = eventOffers?.validThrough;
|
|
234
|
+
// if (validFrom !== undefined && validFrom !== null) {
|
|
235
|
+
// if (acceptedDate.isBefore(moment(validFrom))) {
|
|
236
|
+
// throw new factory.errors.Argument(
|
|
237
|
+
// 'reservationFor.id',
|
|
238
|
+
// `Offer of ${params.event.id} is valid from ${validFrom}`
|
|
239
|
+
// );
|
|
240
|
+
// }
|
|
241
|
+
// }
|
|
242
|
+
// if (validThrough !== undefined && validThrough !== null) {
|
|
243
|
+
// if (acceptedDate.isAfter(moment(validThrough))) {
|
|
244
|
+
// throw new factory.errors.Argument(
|
|
245
|
+
// 'reservationFor.id',
|
|
246
|
+
// `Offer of ${params.event.id} is valid through ${validThrough}`
|
|
247
|
+
// );
|
|
248
|
+
// }
|
|
249
|
+
// }
|
|
223
250
|
// イベントのmaxValueを検証
|
|
224
251
|
const maxValue = (_a = eventOffers === null || eventOffers === void 0 ? void 0 : eventOffers.eligibleQuantity) === null || _a === void 0 ? void 0 : _a.maxValue;
|
|
225
252
|
if (typeof maxValue === 'number') {
|
package/package.json
CHANGED
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
11
|
-
|
|
12
|
-
const eventRepo = new chevre.repository.Event(mongoose.connection);
|
|
13
|
-
const productRepo = new chevre.repository.Product(mongoose.connection);
|
|
14
|
-
|
|
15
|
-
const cursor = eventRepo.getCursor(
|
|
16
|
-
{
|
|
17
|
-
// 'project.id': { $eq: project.id },
|
|
18
|
-
'project.id': { $ne: '' },
|
|
19
|
-
typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
|
|
20
|
-
startDate: {
|
|
21
|
-
$gte: moment()
|
|
22
|
-
.add(-1, 'month')
|
|
23
|
-
.toDate()
|
|
24
|
-
}
|
|
25
|
-
// _id: { $eq: 'al6afd7np' }
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
// _id: 1,
|
|
29
|
-
}
|
|
30
|
-
);
|
|
31
|
-
console.log('events found');
|
|
32
|
-
|
|
33
|
-
let i = 0;
|
|
34
|
-
let updateCount = 0;
|
|
35
|
-
await cursor.eachAsync(async (doc) => {
|
|
36
|
-
i += 1;
|
|
37
|
-
const event: chevre.factory.event.screeningEvent.IEvent = doc.toObject();
|
|
38
|
-
|
|
39
|
-
const itemOfferedId = (<chevre.factory.event.screeningEvent.IOffer | undefined>event.offers)?.itemOffered?.id;
|
|
40
|
-
const itemOfferedName = (<any>event.offers)?.itemOffered?.name?.ja;
|
|
41
|
-
|
|
42
|
-
if (typeof itemOfferedName === 'string' && itemOfferedName.length > 0) {
|
|
43
|
-
console.log(
|
|
44
|
-
'already exist...', event.project.id, event.id, event.startDate, itemOfferedId, i);
|
|
45
|
-
} else {
|
|
46
|
-
const existingProducts = await productRepo.search({
|
|
47
|
-
limit: 1,
|
|
48
|
-
page: 1,
|
|
49
|
-
project: { id: { $eq: event.project.id } },
|
|
50
|
-
id: { $eq: itemOfferedId }
|
|
51
|
-
});
|
|
52
|
-
const existingProduct = existingProducts.shift();
|
|
53
|
-
if (existingProduct === undefined) {
|
|
54
|
-
// throw new Error(`product not found ${event.id}`);
|
|
55
|
-
// no op
|
|
56
|
-
} else {
|
|
57
|
-
const newItemOfferedName: string = (typeof existingProduct.name === 'string')
|
|
58
|
-
? existingProduct.name
|
|
59
|
-
: String(existingProduct.name?.ja);
|
|
60
|
-
console.log(
|
|
61
|
-
'updating event...', event.project.id, event.id, event.startDate, itemOfferedId, newItemOfferedName, i);
|
|
62
|
-
await eventRepo.updatePartiallyById({
|
|
63
|
-
id: event.id,
|
|
64
|
-
attributes: <any>{
|
|
65
|
-
typeOf: event.typeOf,
|
|
66
|
-
'offers.itemOffered.name': { ja: newItemOfferedName }
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
updateCount += 1;
|
|
71
|
-
console.log(
|
|
72
|
-
'updated', event.project.id, event.id, event.startDate, itemOfferedId, i);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
console.log(i, 'events checked');
|
|
77
|
-
console.log(updateCount, 'events updated');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
main()
|
|
81
|
-
.then()
|
|
82
|
-
.catch(console.error);
|