@chevre/domain 23.0.0-alpha.19 → 23.0.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.
- package/example/src/chevre/event/updateSellerMakesOffersByIdentifier.ts +106 -0
- package/lib/chevre/repo/event.d.ts +10 -11
- package/lib/chevre/repo/event.js +28 -24
- package/lib/chevre/repo/eventSellerMakesOffer.d.ts +18 -0
- package/lib/chevre/repo/eventSellerMakesOffer.js +54 -0
- package/package.json +1 -1
- package/example/src/chevre/event/updateEventSellerMakesOffer.ts +0 -100
|
@@ -0,0 +1,106 @@
|
|
|
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 { EVENT_IDENTTIFIER } = process.env;
|
|
9
|
+
|
|
10
|
+
async function main() {
|
|
11
|
+
if (typeof EVENT_IDENTTIFIER !== 'string') {
|
|
12
|
+
throw new Error('environment variables required');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
16
|
+
|
|
17
|
+
const eventSellerMakesOfferRepo = await chevre.repository.EventSellerMakesOffer.createInstance(mongoose.connection);
|
|
18
|
+
const availabilityEnds = moment('2025-10-26T05:20:00.000Z')
|
|
19
|
+
.toDate();
|
|
20
|
+
const availabilityStarts = moment('2025-10-23T15:00:00.000Z')
|
|
21
|
+
.toDate();
|
|
22
|
+
const validFrom = moment('2025-10-12T15:00:00.000Z')
|
|
23
|
+
.toDate();
|
|
24
|
+
const validThrough = moment('2025-10-26T05:20:00.000Z')
|
|
25
|
+
.toDate();
|
|
26
|
+
const result = await eventSellerMakesOfferRepo.updateSellerMakesOffersByEventIdentifier([
|
|
27
|
+
{
|
|
28
|
+
$set: {
|
|
29
|
+
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
|
|
30
|
+
identifier: EVENT_IDENTTIFIER,
|
|
31
|
+
offers: {
|
|
32
|
+
seller: {
|
|
33
|
+
makesOffer: [
|
|
34
|
+
{
|
|
35
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
36
|
+
availableAtOrFrom: {
|
|
37
|
+
id: '3eo6okferrsdpfd9j2ce1iv9k7'
|
|
38
|
+
},
|
|
39
|
+
availabilityEnds,
|
|
40
|
+
availabilityStarts,
|
|
41
|
+
validFrom,
|
|
42
|
+
validThrough
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
46
|
+
availableAtOrFrom: {
|
|
47
|
+
id: '51qbjcfr72h62m06vtv5kkhgje'
|
|
48
|
+
},
|
|
49
|
+
availabilityEnds,
|
|
50
|
+
availabilityStarts,
|
|
51
|
+
validFrom,
|
|
52
|
+
validThrough
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
56
|
+
availableAtOrFrom: {
|
|
57
|
+
id: '5h3gs22mu9j3ok7o63uog9o9i3'
|
|
58
|
+
},
|
|
59
|
+
availabilityEnds,
|
|
60
|
+
availabilityStarts,
|
|
61
|
+
validFrom,
|
|
62
|
+
validThrough
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
66
|
+
availableAtOrFrom: {
|
|
67
|
+
id: '66e7p2g713675v96nrhdm975kg'
|
|
68
|
+
},
|
|
69
|
+
availabilityEnds,
|
|
70
|
+
availabilityStarts,
|
|
71
|
+
validFrom,
|
|
72
|
+
validThrough
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
76
|
+
availableAtOrFrom: {
|
|
77
|
+
id: '7divuoimobsfgq95tp1csorjqq'
|
|
78
|
+
},
|
|
79
|
+
availabilityEnds,
|
|
80
|
+
availabilityStarts,
|
|
81
|
+
validFrom,
|
|
82
|
+
validThrough
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
typeOf: chevre.factory.offerType.Offer,
|
|
86
|
+
availableAtOrFrom: {
|
|
87
|
+
id: 'ckevmf3fueqcunnideu6artt'
|
|
88
|
+
},
|
|
89
|
+
availabilityEnds,
|
|
90
|
+
availabilityStarts,
|
|
91
|
+
validFrom,
|
|
92
|
+
validThrough
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
]);
|
|
100
|
+
// tslint:disable-next-line:no-null-keyword
|
|
101
|
+
console.dir(result, { depth: null });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
main()
|
|
105
|
+
.then(console.log)
|
|
106
|
+
.catch(console.error);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BulkWriteResult } from 'mongodb';
|
|
2
|
-
import { Connection,
|
|
2
|
+
import { Connection, FilterQuery } from 'mongoose';
|
|
3
3
|
import * as factory from '../factory';
|
|
4
4
|
import * as EventFactory from '../factory/event';
|
|
5
5
|
export interface IAttributes4patchUpdate {
|
|
@@ -140,19 +140,18 @@ export declare class EventRepo {
|
|
|
140
140
|
attributes: IAttributes4patchUpdate;
|
|
141
141
|
}): Promise<void>;
|
|
142
142
|
/**
|
|
143
|
-
*
|
|
143
|
+
* 単一イベント編集
|
|
144
144
|
*/
|
|
145
|
-
|
|
146
|
-
id
|
|
147
|
-
attributes: factory.event.screeningEvent.IAttributes
|
|
145
|
+
updateEventById(params: {
|
|
146
|
+
id: string;
|
|
147
|
+
attributes: factory.event.screeningEvent.IAttributes & {
|
|
148
|
+
id?: never;
|
|
149
|
+
};
|
|
148
150
|
/**
|
|
149
151
|
* ドキュメント作成時には無視される
|
|
150
152
|
*/
|
|
151
153
|
$unset?: IUnset;
|
|
152
|
-
|
|
153
|
-
}): Promise<{
|
|
154
|
-
id: string;
|
|
155
|
-
}>;
|
|
154
|
+
}): Promise<void>;
|
|
156
155
|
/**
|
|
157
156
|
* sskts専用
|
|
158
157
|
*/
|
|
@@ -338,7 +337,7 @@ export declare class EventRepo {
|
|
|
338
337
|
validationErrors: import("mongoose").Error[];
|
|
339
338
|
} | undefined;
|
|
340
339
|
}>;
|
|
341
|
-
getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
340
|
+
getCursor(conditions: FilterQuery<any>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
342
341
|
_id: string;
|
|
343
342
|
aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
|
|
344
343
|
}> & import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
@@ -346,7 +345,7 @@ export declare class EventRepo {
|
|
|
346
345
|
aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
|
|
347
346
|
} & Required<{
|
|
348
347
|
_id: string;
|
|
349
|
-
}>, import("mongoose").QueryOptions<Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
348
|
+
}>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
|
350
349
|
_id: string;
|
|
351
350
|
aggregateOffer?: factory.event.screeningEvent.IAggregateOffer;
|
|
352
351
|
}> & import("@chevre/factory/lib/event/screeningEvent").IAttributes & {
|
package/lib/chevre/repo/event.js
CHANGED
|
@@ -480,36 +480,41 @@ class EventRepo {
|
|
|
480
480
|
});
|
|
481
481
|
}
|
|
482
482
|
/**
|
|
483
|
-
*
|
|
483
|
+
* 単一イベント編集
|
|
484
484
|
*/
|
|
485
|
-
|
|
485
|
+
updateEventById(params) {
|
|
486
486
|
return __awaiter(this, void 0, void 0, function* () {
|
|
487
|
-
let savedEventId;
|
|
488
487
|
let doc;
|
|
489
|
-
const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"])
|
|
488
|
+
const _a = params.attributes, { identifier, project, typeOf, organizer, aggregateReservation, maximumAttendeeCapacity, remainingAttendeeCapacity, checkInCount, attendeeCount, coaInfo } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf", "organizer", "aggregateReservation", "maximumAttendeeCapacity", "remainingAttendeeCapacity", "checkInCount", "attendeeCount", "coaInfo"])
|
|
489
|
+
// maximumPhysicalAttendeeCapacity, additionalProperty,
|
|
490
|
+
// eventStatus, location, name, superEvent, offers,
|
|
491
|
+
// doorTime, endDate, startDate
|
|
492
|
+
;
|
|
490
493
|
if (typeof typeOf !== 'string' || typeOf.length === 0) {
|
|
491
494
|
throw new factory.errors.ArgumentNull('attributes.typeOf');
|
|
492
495
|
}
|
|
496
|
+
if (typeof params.id !== 'string' || params.id === '') {
|
|
497
|
+
throw new factory.errors.ArgumentNull('id');
|
|
498
|
+
}
|
|
493
499
|
try {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
//
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
},
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
}
|
|
500
|
+
doc = yield this.eventModel.findOneAndUpdate({
|
|
501
|
+
_id: { $eq: params.id },
|
|
502
|
+
typeOf: { $eq: typeOf }
|
|
503
|
+
}, Object.assign({
|
|
504
|
+
// 編集のためのみのメソッドになったので、setOnInsertは廃止(2025-10-27~)
|
|
505
|
+
// 上書き禁止属性を除外(2022-08-24~)
|
|
506
|
+
// $setOnInsert: {
|
|
507
|
+
// typeOf,
|
|
508
|
+
// project,
|
|
509
|
+
// ...(typeof identifier === 'string' && identifier !== '') ? { identifier } : undefined
|
|
510
|
+
// },
|
|
511
|
+
$set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), {
|
|
512
|
+
upsert: false,
|
|
513
|
+
new: true,
|
|
514
|
+
projection: { _id: 1 }
|
|
515
|
+
})
|
|
516
|
+
.lean()
|
|
517
|
+
.exec();
|
|
513
518
|
}
|
|
514
519
|
catch (error) {
|
|
515
520
|
if (yield (0, errorHandler_1.isMongoError)(error)) {
|
|
@@ -522,7 +527,6 @@ class EventRepo {
|
|
|
522
527
|
if (doc === null) {
|
|
523
528
|
throw new factory.errors.NotFound(this.eventModel.modelName);
|
|
524
529
|
}
|
|
525
|
-
return { id: savedEventId }; // optimize(2024-07-31~)
|
|
526
530
|
});
|
|
527
531
|
}
|
|
528
532
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BulkWriteResult } from 'mongodb';
|
|
1
2
|
import type { Connection } from 'mongoose';
|
|
2
3
|
import * as factory from '../factory';
|
|
3
4
|
/**
|
|
@@ -18,4 +19,21 @@ export declare class EventSellerMakesOfferRepo {
|
|
|
18
19
|
id: string;
|
|
19
20
|
};
|
|
20
21
|
}): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* イベントコードをキーにして複数編集
|
|
24
|
+
* 2025-10-27~
|
|
25
|
+
*/
|
|
26
|
+
updateSellerMakesOffersByEventIdentifier(params: {
|
|
27
|
+
$set: Pick<factory.event.screeningEvent.IAttributes, 'project'> & {
|
|
28
|
+
identifier: string;
|
|
29
|
+
offers: {
|
|
30
|
+
seller: Pick<factory.event.screeningEvent.ISeller, 'makesOffer'>;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}[]): Promise<{
|
|
34
|
+
bulkWriteResult: BulkWriteResult;
|
|
35
|
+
modifiedEvents: {
|
|
36
|
+
id: string;
|
|
37
|
+
}[];
|
|
38
|
+
} | void>;
|
|
21
39
|
}
|
|
@@ -60,5 +60,59 @@ class EventSellerMakesOfferRepo {
|
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* イベントコードをキーにして複数編集
|
|
65
|
+
* 2025-10-27~
|
|
66
|
+
*/
|
|
67
|
+
updateSellerMakesOffersByEventIdentifier(params) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const bulkWriteOps = [];
|
|
70
|
+
const queryFilters = [];
|
|
71
|
+
if (Array.isArray(params)) {
|
|
72
|
+
params.forEach(({ $set }) => {
|
|
73
|
+
const { project, identifier, offers } = $set;
|
|
74
|
+
if (typeof identifier !== 'string' || identifier.length === 0) {
|
|
75
|
+
throw new factory.errors.ArgumentNull('identifier');
|
|
76
|
+
}
|
|
77
|
+
const sellerMakesOffer = offers.seller.makesOffer;
|
|
78
|
+
if (!Array.isArray(sellerMakesOffer)) {
|
|
79
|
+
throw new factory.errors.Argument('offers.seller.makesOffer', 'offers.seller.makesOffer must be an array');
|
|
80
|
+
}
|
|
81
|
+
// リソースのユニークネスを保証するfilter
|
|
82
|
+
const filter = {
|
|
83
|
+
'project.id': { $eq: project.id },
|
|
84
|
+
identifier: { $exists: true, $eq: identifier }
|
|
85
|
+
};
|
|
86
|
+
queryFilters.push({
|
|
87
|
+
'project.id': { $eq: project.id },
|
|
88
|
+
identifier: { $exists: true, $eq: identifier }
|
|
89
|
+
});
|
|
90
|
+
const setFields = {
|
|
91
|
+
'offers.seller.makesOffer': sellerMakesOffer
|
|
92
|
+
};
|
|
93
|
+
const updateQuery = {
|
|
94
|
+
$set: setFields
|
|
95
|
+
};
|
|
96
|
+
const updateOne = {
|
|
97
|
+
filter,
|
|
98
|
+
update: updateQuery,
|
|
99
|
+
upsert: false
|
|
100
|
+
};
|
|
101
|
+
bulkWriteOps.push({ updateOne });
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
if (bulkWriteOps.length > 0) {
|
|
105
|
+
const bulkWriteResult = yield this.eventModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
106
|
+
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
107
|
+
const modifiedEvents = yield this.eventModel.find({ $or: queryFilters }, {
|
|
108
|
+
_id: 0,
|
|
109
|
+
id: { $toString: '$_id' }
|
|
110
|
+
})
|
|
111
|
+
.lean()
|
|
112
|
+
.exec();
|
|
113
|
+
return { bulkWriteResult, modifiedEvents };
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
63
117
|
}
|
|
64
118
|
exports.EventSellerMakesOfferRepo = EventSellerMakesOfferRepo;
|
package/package.json
CHANGED
|
@@ -1,100 +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
|
-
const { EVENT_ID } = process.env;
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
if (typeof EVENT_ID !== 'string') {
|
|
12
|
-
throw new Error('environment variables required');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
16
|
-
|
|
17
|
-
const eventSellerMakesOfferRepo = await chevre.repository.EventSellerMakesOffer.createInstance(mongoose.connection);
|
|
18
|
-
const availabilityEnds = moment('2025-10-26T05:20:00.000Z')
|
|
19
|
-
.toDate();
|
|
20
|
-
const availabilityStarts = moment('2025-10-23T15:00:00.000Z')
|
|
21
|
-
.toDate();
|
|
22
|
-
const validFrom = moment('2025-10-12T15:00:00.000Z')
|
|
23
|
-
.toDate();
|
|
24
|
-
const validThrough = moment('2025-10-26T05:20:00.000Z')
|
|
25
|
-
.toDate();
|
|
26
|
-
const result = await eventSellerMakesOfferRepo.updateOffersByEventId(
|
|
27
|
-
{
|
|
28
|
-
project: { id: project.id },
|
|
29
|
-
offers: [
|
|
30
|
-
{
|
|
31
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
32
|
-
availableAtOrFrom: {
|
|
33
|
-
id: '3eo6okferrsdpfd9j2ce1iv9k7'
|
|
34
|
-
},
|
|
35
|
-
availabilityEnds,
|
|
36
|
-
availabilityStarts,
|
|
37
|
-
validFrom,
|
|
38
|
-
validThrough
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
42
|
-
availableAtOrFrom: {
|
|
43
|
-
id: '51qbjcfr72h62m06vtv5kkhgje'
|
|
44
|
-
},
|
|
45
|
-
availabilityEnds,
|
|
46
|
-
availabilityStarts,
|
|
47
|
-
validFrom,
|
|
48
|
-
validThrough
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
52
|
-
availableAtOrFrom: {
|
|
53
|
-
id: '5h3gs22mu9j3ok7o63uog9o9i3'
|
|
54
|
-
},
|
|
55
|
-
availabilityEnds,
|
|
56
|
-
availabilityStarts,
|
|
57
|
-
validFrom,
|
|
58
|
-
validThrough
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
62
|
-
availableAtOrFrom: {
|
|
63
|
-
id: '66e7p2g713675v96nrhdm975kg'
|
|
64
|
-
},
|
|
65
|
-
availabilityEnds,
|
|
66
|
-
availabilityStarts,
|
|
67
|
-
validFrom,
|
|
68
|
-
validThrough
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
72
|
-
availableAtOrFrom: {
|
|
73
|
-
id: '7divuoimobsfgq95tp1csorjqq'
|
|
74
|
-
},
|
|
75
|
-
availabilityEnds,
|
|
76
|
-
availabilityStarts,
|
|
77
|
-
validFrom,
|
|
78
|
-
validThrough
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
typeOf: chevre.factory.offerType.Offer,
|
|
82
|
-
availableAtOrFrom: {
|
|
83
|
-
id: 'ckevmf3fueqcunnideu6artt'
|
|
84
|
-
},
|
|
85
|
-
availabilityEnds,
|
|
86
|
-
availabilityStarts,
|
|
87
|
-
validFrom,
|
|
88
|
-
validThrough
|
|
89
|
-
}
|
|
90
|
-
],
|
|
91
|
-
itemOffered: { id: EVENT_ID }
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
// tslint:disable-next-line:no-null-keyword
|
|
95
|
-
console.dir(result, { depth: null });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
main()
|
|
99
|
-
.then(console.log)
|
|
100
|
-
.catch(console.error);
|