@chevre/domain 23.0.0-alpha.17 → 23.0.0-alpha.18
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,100 @@
|
|
|
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);
|
|
@@ -1,54 +1,21 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
2
|
import * as factory from '../factory';
|
|
3
|
-
type IAggregateMakesOfferResult = Pick<factory.event.screeningEvent.ISellerMakesOffer, 'availabilityEnds' | 'availabilityStarts' | 'validFrom' | 'validThrough'> & {
|
|
4
|
-
itemOffered: {
|
|
5
|
-
serviceOutput: {
|
|
6
|
-
reservationFor: {
|
|
7
|
-
/**
|
|
8
|
-
* イベントID
|
|
9
|
-
*/
|
|
10
|
-
id: string;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
3
|
/**
|
|
16
|
-
*
|
|
4
|
+
* イベントのアプリケーションオファーリポジトリ
|
|
17
5
|
*/
|
|
18
6
|
export declare class EventSellerMakesOfferRepo {
|
|
19
7
|
private readonly eventModel;
|
|
20
8
|
constructor(connection: Connection);
|
|
21
9
|
/**
|
|
22
|
-
*
|
|
10
|
+
* 単一イベントのmakesOfferを更新する
|
|
23
11
|
*/
|
|
24
|
-
|
|
25
|
-
limit?: number;
|
|
26
|
-
page?: number;
|
|
12
|
+
updateOffersByEventId(params: {
|
|
27
13
|
project: {
|
|
28
|
-
id:
|
|
29
|
-
$eq: string;
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* アプリケーション(指定必須)
|
|
34
|
-
*/
|
|
35
|
-
availableAtOrFrom: {
|
|
36
|
-
id: {
|
|
37
|
-
$eq: string;
|
|
38
|
-
};
|
|
14
|
+
id: string;
|
|
39
15
|
};
|
|
16
|
+
offers: factory.event.screeningEvent.ISellerMakesOffer[];
|
|
40
17
|
itemOffered: {
|
|
41
|
-
|
|
42
|
-
reservationFor: {
|
|
43
|
-
/**
|
|
44
|
-
* イベントID
|
|
45
|
-
*/
|
|
46
|
-
id: {
|
|
47
|
-
$in?: string[];
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
};
|
|
18
|
+
id: string;
|
|
51
19
|
};
|
|
52
|
-
}): Promise<
|
|
20
|
+
}): Promise<void>;
|
|
53
21
|
}
|
|
54
|
-
export {};
|
|
@@ -11,62 +11,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EventSellerMakesOfferRepo = void 0;
|
|
13
13
|
const factory = require("../factory");
|
|
14
|
-
|
|
14
|
+
// import { MONGO_MAX_TIME_MS } from '../settings';
|
|
15
15
|
const event_1 = require("./mongoose/schemas/event");
|
|
16
|
+
// type IMatchStage = PipelineStage.Match;
|
|
17
|
+
// type IAggregateMakesOfferResult = Pick<
|
|
18
|
+
// factory.event.screeningEvent.ISellerMakesOffer,
|
|
19
|
+
// 'availabilityEnds' | 'availabilityStarts' | 'validFrom' | 'validThrough'
|
|
20
|
+
// > & {
|
|
21
|
+
// itemOffered: {
|
|
22
|
+
// serviceOutput: {
|
|
23
|
+
// reservationFor: {
|
|
24
|
+
// /**
|
|
25
|
+
// * イベントID
|
|
26
|
+
// */
|
|
27
|
+
// id: string;
|
|
28
|
+
// };
|
|
29
|
+
// };
|
|
30
|
+
// };
|
|
31
|
+
// };
|
|
16
32
|
/**
|
|
17
|
-
*
|
|
33
|
+
* イベントのアプリケーションオファーリポジトリ
|
|
18
34
|
*/
|
|
19
35
|
class EventSellerMakesOfferRepo {
|
|
20
36
|
constructor(connection) {
|
|
21
37
|
this.eventModel = connection.model(event_1.modelName, (0, event_1.createSchema)());
|
|
22
38
|
}
|
|
23
39
|
/**
|
|
24
|
-
*
|
|
40
|
+
* 単一イベントのmakesOfferを更新する
|
|
25
41
|
*/
|
|
26
|
-
|
|
42
|
+
updateOffersByEventId(params) {
|
|
27
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const matchStages = [
|
|
34
|
-
{ $match: { 'project.id': { $eq: conditions.project.id.$eq } } },
|
|
35
|
-
{ $match: { 'offers.seller.makesOffer.availableAtOrFrom.id': { $exists: true, $eq: availableAtOrFrom.id.$eq } } }
|
|
36
|
-
];
|
|
37
|
-
const reservationForIdIn = conditions.itemOffered.serviceOutput.reservationFor.id.$in;
|
|
38
|
-
if (Array.isArray(reservationForIdIn)) {
|
|
39
|
-
matchStages.push({ $match: { _id: { $in: reservationForIdIn } } });
|
|
40
|
-
}
|
|
41
|
-
const aggregate = this.eventModel.aggregate([
|
|
42
|
-
{ $unwind: '$offers.seller.makesOffer' },
|
|
43
|
-
...matchStages,
|
|
44
|
-
{ $sort: { _id: factory.sortType.Ascending } },
|
|
45
|
-
{
|
|
46
|
-
$project: {
|
|
47
|
-
_id: 0,
|
|
48
|
-
availabilityEnds: '$offers.seller.makesOffer.availabilityEnds',
|
|
49
|
-
availabilityStarts: '$offers.seller.makesOffer.availabilityStarts',
|
|
50
|
-
validFrom: '$offers.seller.makesOffer.validFrom',
|
|
51
|
-
validThrough: '$offers.seller.makesOffer.validThrough',
|
|
52
|
-
itemOffered: {
|
|
53
|
-
serviceOutput: {
|
|
54
|
-
reservationFor: {
|
|
55
|
-
id: { $toString: '$_id' }
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
44
|
+
const { offers, itemOffered, project } = params;
|
|
45
|
+
const updateQuery = {
|
|
46
|
+
$set: {
|
|
47
|
+
'offers.seller.makesOffer': offers
|
|
60
48
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
.
|
|
49
|
+
};
|
|
50
|
+
const updateFilter = {
|
|
51
|
+
_id: { $eq: itemOffered.id },
|
|
52
|
+
'project.id': { $eq: project.id }
|
|
53
|
+
};
|
|
54
|
+
const queryOptions = { upsert: false, new: false, projection: { _id: 1 } };
|
|
55
|
+
const doc = yield this.eventModel.findOneAndUpdate(updateFilter, updateQuery, queryOptions)
|
|
56
|
+
.lean()
|
|
69
57
|
.exec();
|
|
58
|
+
if (doc === null) {
|
|
59
|
+
throw new factory.errors.NotFound(this.eventModel.modelName);
|
|
60
|
+
}
|
|
70
61
|
});
|
|
71
62
|
}
|
|
72
63
|
}
|
package/package.json
CHANGED
|
@@ -1,32 +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
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
-
|
|
11
|
-
const eventSellerMakesOfferRepo = await chevre.repository.EventSellerMakesOffer.createInstance(mongoose.connection);
|
|
12
|
-
const result = await eventSellerMakesOfferRepo.aggregateMakesOffer(
|
|
13
|
-
{
|
|
14
|
-
limit: 10,
|
|
15
|
-
page: 1,
|
|
16
|
-
// id: { $eq: 'bm0f0cadu' },
|
|
17
|
-
// typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
18
|
-
project: { id: { $eq: project.id } },
|
|
19
|
-
availableAtOrFrom: { id: { $eq: '3eo6okferrsdpfd9j2ce1iv9k7' } },
|
|
20
|
-
itemOffered: {
|
|
21
|
-
serviceOutput: { reservationFor: { id: { $in: ['bm0f0cadu', 'blco2394l'] } } }
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
);
|
|
25
|
-
// tslint:disable-next-line:no-null-keyword
|
|
26
|
-
console.dir(result, { depth: null });
|
|
27
|
-
console.dir(result.length, 'results found');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
main()
|
|
31
|
-
.then(console.log)
|
|
32
|
-
.catch(console.error);
|