@chevre/domain 20.1.0 → 20.2.0-alpha.0

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,7 @@
1
+ import * as mongoose from 'mongoose';
2
+ declare const modelName = "Trip";
3
+ /**
4
+ * トリップスキーマ
5
+ */
6
+ declare const schema: mongoose.Schema<mongoose.Document<any, any, any>, mongoose.Model<mongoose.Document<any, any, any>, any, any>, undefined, {}>;
7
+ export { modelName, schema };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = exports.modelName = void 0;
4
+ const mongoose = require("mongoose");
5
+ const modelName = 'Trip';
6
+ exports.modelName = modelName;
7
+ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
8
+ /**
9
+ * トリップスキーマ
10
+ */
11
+ const schema = new mongoose.Schema({
12
+ project: mongoose.SchemaTypes.Mixed,
13
+ typeOf: {
14
+ type: String,
15
+ required: true
16
+ }
17
+ }, {
18
+ collection: 'trips',
19
+ id: true,
20
+ read: 'primaryPreferred',
21
+ writeConcern: writeConcern,
22
+ strict: false,
23
+ useNestedStrict: true,
24
+ timestamps: {
25
+ createdAt: 'createdAt',
26
+ updatedAt: 'updatedAt'
27
+ },
28
+ toJSON: {
29
+ getters: false,
30
+ virtuals: false,
31
+ minimize: false,
32
+ versionKey: false
33
+ },
34
+ toObject: {
35
+ getters: false,
36
+ virtuals: true,
37
+ minimize: false,
38
+ versionKey: false
39
+ }
40
+ });
41
+ exports.schema = schema;
42
+ mongoose.model(modelName, schema)
43
+ .on('index',
44
+ // tslint:disable-next-line:no-single-line-block-comment
45
+ /* istanbul ignore next */
46
+ (error) => {
47
+ if (error !== undefined) {
48
+ // tslint:disable-next-line:no-console
49
+ console.error(error);
50
+ }
51
+ });
@@ -35,7 +35,7 @@ class MongoRepository {
35
35
  static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params) {
36
36
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
37
37
  // MongoDB検索条件
38
- const andConditions = [];
38
+ const andConditions = [{ typeOf: { $eq: factory.placeType.MovieTheater } }];
39
39
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
40
40
  if (typeof projectIdEq === 'string') {
41
41
  andConditions.push({
@@ -0,0 +1,54 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ export declare type ISearchConditions<T extends factory.tripType> = factory.trip.ISearchConditions<T>;
4
+ export interface IAttributes4patchUpdate<T extends factory.tripType> {
5
+ typeOf: T;
6
+ }
7
+ /**
8
+ * トリップリポジトリ
9
+ */
10
+ export declare class MongoRepository {
11
+ private readonly tripModel;
12
+ constructor(connection: Connection);
13
+ static CREATE_MONGO_CONDITIONS<T extends factory.tripType>(conditions: ISearchConditions<T>): any[];
14
+ createMany<T extends factory.tripType>(params: factory.trip.ITrip<T>[]): Promise<factory.trip.ITrip<T>[]>;
15
+ updatePartiallyById<T extends factory.tripType>(params: {
16
+ id: string;
17
+ attributes: IAttributes4patchUpdate<T>;
18
+ }): Promise<factory.trip.ITrip<T>>;
19
+ /**
20
+ * イベントを保管する
21
+ */
22
+ save<T extends factory.tripType>(params: {
23
+ id?: string;
24
+ attributes: factory.trip.ITrip<T>;
25
+ $unset?: {
26
+ [key: string]: number;
27
+ };
28
+ upsert?: boolean;
29
+ }): Promise<factory.trip.ITrip<T>>;
30
+ saveMany<T extends factory.tripType>(params: {
31
+ id?: string;
32
+ attributes: factory.trip.ITrip<T>;
33
+ $unset?: {
34
+ [key: string]: number;
35
+ };
36
+ upsert?: boolean;
37
+ }[]): Promise<void>;
38
+ search<T extends factory.tripType>(params: ISearchConditions<T>, projection?: {
39
+ [key: string]: number;
40
+ }): Promise<factory.trip.ITrip<T>[]>;
41
+ findById<T extends factory.tripType>(params: {
42
+ id: string;
43
+ }, projection?: {
44
+ [key: string]: number;
45
+ }): Promise<factory.trip.ITrip<T>>;
46
+ deleteById(params: {
47
+ id: string;
48
+ }): Promise<void>;
49
+ deleteByProject(params: {
50
+ project: {
51
+ id: string;
52
+ };
53
+ }): Promise<void>;
54
+ }
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.MongoRepository = void 0;
24
+ const factory = require("../factory");
25
+ const trip_1 = require("./mongoose/model/trip");
26
+ /**
27
+ * トリップリポジトリ
28
+ */
29
+ class MongoRepository {
30
+ constructor(connection) {
31
+ this.tripModel = connection.model(trip_1.modelName);
32
+ }
33
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
34
+ static CREATE_MONGO_CONDITIONS(conditions) {
35
+ var _a, _b, _c;
36
+ const andConditions = [{ typeOf: { $eq: conditions.typeOf } }];
37
+ const projectIdEq = (_b = (_a = conditions.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
38
+ if (typeof projectIdEq === 'string') {
39
+ andConditions.push({
40
+ 'project.id': { $eq: projectIdEq }
41
+ });
42
+ }
43
+ const idIn = (_c = conditions.id) === null || _c === void 0 ? void 0 : _c.$in;
44
+ if (Array.isArray(idIn)) {
45
+ andConditions.push({
46
+ _id: { $in: idIn }
47
+ });
48
+ }
49
+ return andConditions;
50
+ }
51
+ createMany(params) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const docs = yield this.tripModel.insertMany(params.map((p) => {
54
+ return Object.assign({}, p);
55
+ }));
56
+ return docs.map((doc) => doc.toObject());
57
+ });
58
+ }
59
+ updatePartiallyById(params) {
60
+ return __awaiter(this, void 0, void 0, function* () {
61
+ let doc;
62
+ const _a = params.attributes, { typeOf } = _a, updateFields = __rest(_a, ["typeOf"]);
63
+ doc = yield this.tripModel.findOneAndUpdate({
64
+ _id: params.id,
65
+ typeOf: params.attributes.typeOf
66
+ }, {
67
+ $set: updateFields
68
+ }, { upsert: false, new: true })
69
+ .exec();
70
+ if (doc === null) {
71
+ throw new factory.errors.NotFound(this.tripModel.modelName);
72
+ }
73
+ return doc.toObject();
74
+ });
75
+ }
76
+ /**
77
+ * イベントを保管する
78
+ */
79
+ save(params) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ let doc;
82
+ if (typeof params.id !== 'string') {
83
+ doc = yield this.tripModel.create(Object.assign({}, params.attributes));
84
+ }
85
+ else {
86
+ const upsert = params.upsert === true;
87
+ // 上書き禁止属性を除外
88
+ const _a = params.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
89
+ doc = yield this.tripModel.findOneAndUpdate({
90
+ _id: params.id,
91
+ typeOf: params.attributes.typeOf
92
+ }, Object.assign({ $setOnInsert: {
93
+ typeOf: params.attributes.typeOf,
94
+ project: params.attributes.project,
95
+ identifier: params.attributes.identifier
96
+ }, $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert, new: true })
97
+ .exec();
98
+ }
99
+ if (doc === null) {
100
+ throw new factory.errors.NotFound(this.tripModel.modelName);
101
+ }
102
+ return doc.toObject();
103
+ });
104
+ }
105
+ saveMany(params) {
106
+ return __awaiter(this, void 0, void 0, function* () {
107
+ const bulkWriteOps = [];
108
+ if (Array.isArray(params)) {
109
+ params.forEach((p) => {
110
+ if (typeof p.id !== 'string') {
111
+ bulkWriteOps.push({
112
+ insertOne: {
113
+ document: Object.assign({}, p.attributes)
114
+ }
115
+ });
116
+ }
117
+ else {
118
+ const upsert = p.upsert === true;
119
+ if (p.attributes.typeOf === factory.tripType.BusTrip) {
120
+ // 上書き禁止属性を除外
121
+ const _a = p.attributes, { identifier, project, typeOf } = _a, updateFields = __rest(_a, ["identifier", "project", "typeOf"]);
122
+ bulkWriteOps.push({
123
+ updateOne: {
124
+ filter: {
125
+ _id: p.id,
126
+ typeOf: p.attributes.typeOf
127
+ },
128
+ // upsertの場合、createがありうるので属性を除外しない
129
+ update: Object.assign({ $setOnInsert: {
130
+ typeOf: p.attributes.typeOf,
131
+ project: p.attributes.project,
132
+ identifier: p.attributes.identifier
133
+ // ...(typeof p.attributes.remainingAttendeeCapacity === 'number')
134
+ // ? { remainingAttendeeCapacity: p.attributes.remainingAttendeeCapacity }
135
+ // : undefined
136
+ }, $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
137
+ upsert
138
+ }
139
+ });
140
+ }
141
+ else if (p.attributes.typeOf === factory.tripType.BusTripSeries) {
142
+ // 上書き禁止属性を除外
143
+ const _b = p.attributes, { identifier, project, typeOf } = _b, updateFields = __rest(_b, ["identifier", "project", "typeOf"]);
144
+ bulkWriteOps.push({
145
+ updateOne: {
146
+ filter: {
147
+ _id: p.id,
148
+ typeOf: p.attributes.typeOf
149
+ },
150
+ // upsertの場合、createがありうるので属性を除外しない
151
+ update: Object.assign({ $setOnInsert: {
152
+ typeOf: p.attributes.typeOf,
153
+ project: p.attributes.project,
154
+ identifier: p.attributes.identifier
155
+ }, $set: updateFields }, (p.$unset !== undefined) ? { $unset: p.$unset } : undefined),
156
+ upsert
157
+ }
158
+ });
159
+ }
160
+ }
161
+ });
162
+ }
163
+ if (bulkWriteOps.length > 0) {
164
+ yield this.tripModel.bulkWrite(bulkWriteOps, { ordered: false });
165
+ }
166
+ });
167
+ }
168
+ search(params, projection) {
169
+ return __awaiter(this, void 0, void 0, function* () {
170
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
171
+ const query = this.tripModel.find({ $and: conditions }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
172
+ if (typeof params.limit === 'number') {
173
+ const page = (typeof params.page === 'number') ? params.page : 1;
174
+ query.limit(params.limit)
175
+ .skip(params.limit * (page - 1));
176
+ }
177
+ // tslint:disable-next-line:no-single-line-block-comment
178
+ /* istanbul ignore else */
179
+ if (params.sort !== undefined) {
180
+ query.sort(params.sort);
181
+ }
182
+ // const explainResult = await query.explain()
183
+ // .exec();
184
+ // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
185
+ // console.log(explainResult[0].executionStats.allPlansExecution);
186
+ // console.log(explainResult[0].queryPlanner?.winningPlan);
187
+ // console.log(explainResult[0].queryPlanner?.winningPlan?.inputStage?.inputStage?.inputStage);
188
+ // console.log(explainResult);
189
+ // return [];
190
+ return query.setOptions({ maxTimeMS: 10000 })
191
+ .exec()
192
+ .then((docs) => docs.map((doc) => doc.toObject()));
193
+ });
194
+ }
195
+ findById(params, projection) {
196
+ return __awaiter(this, void 0, void 0, function* () {
197
+ const doc = yield this.tripModel.findOne({
198
+ _id: params.id
199
+ }, Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
200
+ .exec();
201
+ if (doc === null) {
202
+ throw new factory.errors.NotFound(this.tripModel.modelName);
203
+ }
204
+ return doc.toObject();
205
+ });
206
+ }
207
+ deleteById(params) {
208
+ return __awaiter(this, void 0, void 0, function* () {
209
+ yield this.tripModel.findOneAndDelete({ _id: params.id })
210
+ .exec();
211
+ });
212
+ }
213
+ deleteByProject(params) {
214
+ return __awaiter(this, void 0, void 0, function* () {
215
+ yield this.tripModel.deleteMany({
216
+ 'project.id': { $eq: params.project.id }
217
+ })
218
+ .exec();
219
+ });
220
+ }
221
+ }
222
+ exports.MongoRepository = MongoRepository;
@@ -36,6 +36,7 @@ import { MongoRepository as TaskRepo } from './repo/task';
36
36
  import { MongoRepository as TelemetryRepo } from './repo/telemetry';
37
37
  import { MongoRepository as TransactionRepo } from './repo/transaction';
38
38
  import { RedisRepository as TransactionNumberRepo } from './repo/transactionNumber';
39
+ import { MongoRepository as TripRepo } from './repo/trip';
39
40
  import { RedisRepository as RegisterServiceActionInProgress } from './repo/action/registerServiceInProgress';
40
41
  import { RedisRepository as ConfirmationNumberRepo } from './repo/confirmationNumber';
41
42
  import { RedisRepository as OrderNumberRepo } from './repo/orderNumber';
@@ -184,6 +185,8 @@ export declare class Transaction extends TransactionRepo {
184
185
  }
185
186
  export declare class TransactionNumber extends TransactionNumberRepo {
186
187
  }
188
+ export declare class Trip extends TripRepo {
189
+ }
187
190
  export declare namespace itemAvailability {
188
191
  class ScreeningEvent extends ScreeningEventItemAvailabilityRepo {
189
192
  }
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rateLimit = exports.itemAvailability = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
3
+ exports.rateLimit = exports.itemAvailability = exports.Trip = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = void 0;
4
4
  // tslint:disable:max-classes-per-file completed-docs
5
5
  /**
6
6
  * リポジトリ
7
7
  */
8
8
  const account_1 = require("./repo/account");
9
- // import { MongoRepository as AccountActionRepo } from './repo/accountAction';
10
9
  const accountingReport_1 = require("./repo/accountingReport");
11
10
  const accountTitle_1 = require("./repo/accountTitle");
12
11
  const accountTransaction_1 = require("./repo/accountTransaction");
@@ -41,6 +40,7 @@ const task_1 = require("./repo/task");
41
40
  const telemetry_1 = require("./repo/telemetry");
42
41
  const transaction_1 = require("./repo/transaction");
43
42
  const transactionNumber_1 = require("./repo/transactionNumber");
43
+ const trip_1 = require("./repo/trip");
44
44
  const registerServiceInProgress_1 = require("./repo/action/registerServiceInProgress");
45
45
  const confirmationNumber_1 = require("./repo/confirmationNumber");
46
46
  const orderNumber_1 = require("./repo/orderNumber");
@@ -230,6 +230,9 @@ exports.Transaction = Transaction;
230
230
  class TransactionNumber extends transactionNumber_1.RedisRepository {
231
231
  }
232
232
  exports.TransactionNumber = TransactionNumber;
233
+ class Trip extends trip_1.MongoRepository {
234
+ }
235
+ exports.Trip = Trip;
233
236
  var itemAvailability;
234
237
  (function (itemAvailability) {
235
238
  class ScreeningEvent extends screeningEvent_1.RedisRepository {
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.280.0",
12
+ "@chevre/factory": "4.281.0-alpha.0",
13
13
  "@cinerino/sdk": "3.135.0-alpha.6",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.1.0"
123
+ "version": "20.2.0-alpha.0"
124
124
  }