@chevre/domain 21.15.0-alpha.6 → 21.15.0-alpha.7

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.
@@ -24,6 +24,7 @@
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import { AnyExpression, Connection, FilterQuery } from 'mongoose';
26
26
  import * as factory from '../factory';
27
+ type IKeyOfProjection = keyof factory.categoryCode.ICategoryCode | '_id';
27
28
  /**
28
29
  * 区分リポジトリ
29
30
  */
@@ -31,21 +32,17 @@ export declare class MongoRepository {
31
32
  private readonly categoryCodeModel;
32
33
  constructor(connection: Connection);
33
34
  static CREATE_MONGO_CONDITIONS(params: factory.categoryCode.ISearchConditions): FilterQuery<factory.categoryCode.ICategoryCode>[];
34
- static CREATE_AGGREGATE_PROJECTION(inclusion: string[], exclusion: (keyof factory.categoryCode.ICategoryCode)[]): {
35
+ static CREATE_AGGREGATE_PROJECTION(inclusion: string[], exclusion: IKeyOfProjection[]): {
35
36
  [field: string]: AnyExpression;
36
37
  };
37
- count(params: factory.categoryCode.ISearchConditions): Promise<number>;
38
38
  /**
39
39
  * 集計検索(publicな属性検索が目的)
40
40
  */
41
- searchByAggregate(conditions: factory.categoryCode.ISearchConditions, inclusion: (keyof factory.categoryCode.ICategoryCode)[], exclusion: (keyof factory.categoryCode.ICategoryCode)[]): Promise<factory.categoryCode.ICategoryCode[]>;
41
+ searchByAggregate(conditions: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.categoryCode.ICategoryCode[]>;
42
42
  /**
43
43
  * 検索
44
44
  */
45
- search(params: factory.categoryCode.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<factory.categoryCode.ICategoryCode[]>;
46
- findById(params: {
47
- id: string;
48
- }): Promise<factory.categoryCode.ICategoryCode>;
45
+ search(params: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.categoryCode.ICategoryCode[]>;
49
46
  save(params: {
50
47
  id?: string;
51
48
  attributes: factory.categoryCode.ICategoryCode;
@@ -70,3 +67,4 @@ export declare class MongoRepository {
70
67
  }): Promise<void>;
71
68
  getCursor(conditions: FilterQuery<factory.categoryCode.ICategoryCode>, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
72
69
  }
70
+ export {};
@@ -154,14 +154,14 @@ class MongoRepository {
154
154
  static CREATE_AGGREGATE_PROJECTION(inclusion, exclusion) {
155
155
  const projectStage = {
156
156
  _id: 0,
157
- // id: { $toString: '$_id' },
157
+ id: { $toString: '$_id' },
158
158
  project: '$project',
159
159
  typeOf: '$typeOf',
160
160
  additionalProperty: '$additionalProperty',
161
161
  color: '$color',
162
162
  image: '$image',
163
163
  codeValue: '$codeValue',
164
- // inCodeSet: '$inCodeSet',
164
+ inCodeSet: '$inCodeSet',
165
165
  name: '$name',
166
166
  paymentMethod: '$paymentMethod'
167
167
  };
@@ -178,14 +178,6 @@ class MongoRepository {
178
178
  }
179
179
  return projectStage;
180
180
  }
181
- count(params) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
184
- return this.categoryCodeModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
185
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
186
- .exec();
187
- });
188
- }
189
181
  /**
190
182
  * 集計検索(publicな属性検索が目的)
191
183
  */
@@ -253,20 +245,6 @@ class MongoRepository {
253
245
  .then((docs) => docs.map((doc) => doc.toObject()));
254
246
  });
255
247
  }
256
- findById(params) {
257
- return __awaiter(this, void 0, void 0, function* () {
258
- const doc = yield this.categoryCodeModel.findOne({ _id: params.id }, {
259
- __v: 0,
260
- createdAt: 0,
261
- updatedAt: 0
262
- })
263
- .exec();
264
- if (doc === null) {
265
- throw new factory.errors.NotFound(this.categoryCodeModel.modelName);
266
- }
267
- return doc.toObject();
268
- });
269
- }
270
248
  save(params) {
271
249
  return __awaiter(this, void 0, void 0, function* () {
272
250
  let doc;
@@ -23,15 +23,16 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import type { BulkWriteResult } from 'mongodb';
26
- import type { Connection } from 'mongoose';
26
+ import { Connection, FilterQuery } from 'mongoose';
27
27
  import * as factory from '../factory';
28
+ type IKeyOfProjection = keyof factory.creativeWork.movie.ICreativeWork | '_id';
28
29
  /**
29
30
  * コンテンツリポジトリ
30
31
  */
31
32
  export declare class MongoRepository {
32
33
  private readonly creativeWorkModel;
33
34
  constructor(connection: Connection);
34
- static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.movie.ISearchConditions): any[];
35
+ static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.movie.ISearchConditions): FilterQuery<import("@chevre/factory/lib/creativeWork/movie").ICreativeWork>[];
35
36
  /**
36
37
  * コンテンツを保管する
37
38
  */
@@ -42,13 +43,10 @@ export declare class MongoRepository {
42
43
  upsertMoviesByIdentifier(params: {
43
44
  attributes: factory.creativeWork.movie.ICreativeWork;
44
45
  }[]): Promise<BulkWriteResult | void>;
45
- findMovieById(params: {
46
- id: string;
47
- }): Promise<factory.creativeWork.movie.ICreativeWork>;
48
46
  /**
49
47
  * コンテンツを検索する
50
48
  */
51
- searchMovies(params: factory.creativeWork.movie.ISearchConditions, inclusion: string[], exclusion: string[]): Promise<factory.creativeWork.movie.ICreativeWork[]>;
49
+ searchMovies(params: factory.creativeWork.movie.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.creativeWork.movie.ICreativeWork[]>;
52
50
  /**
53
51
  * コンテンツを削除する
54
52
  */
@@ -60,9 +58,10 @@ export declare class MongoRepository {
60
58
  id: string;
61
59
  };
62
60
  }): Promise<void>;
63
- getCursor(conditions: any, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
61
+ getCursor(conditions: FilterQuery<factory.creativeWork.movie.ICreativeWork>, projection: any): import("mongoose").Cursor<any, import("mongoose").QueryOptions<any>>;
64
62
  unsetUnnecessaryFields(params: {
65
- filter: any;
63
+ filter: FilterQuery<factory.creativeWork.movie.ICreativeWork>;
66
64
  $unset: any;
67
65
  }): Promise<import("mongodb").UpdateResult>;
68
66
  }
67
+ export {};
@@ -21,6 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  exports.MongoRepository = void 0;
24
+ const mongoose_1 = require("mongoose");
24
25
  const creativeWork_1 = require("./mongoose/schemas/creativeWork");
25
26
  const factory = require("../factory");
26
27
  const settings_1 = require("../settings");
@@ -34,111 +35,65 @@ class MongoRepository {
34
35
  // tslint:disable-next-line:max-func-body-length
35
36
  static CREATE_MONGO_CONDITIONS(params) {
36
37
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
37
- // MongoDB検索条件
38
38
  const andConditions = [
39
- {
40
- typeOf: factory.creativeWorkType.Movie
41
- }
39
+ { typeOf: { $eq: factory.creativeWorkType.Movie } }
42
40
  ];
43
41
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
44
42
  if (typeof projectIdEq === 'string') {
45
- andConditions.push({
46
- 'project.id': {
47
- $eq: projectIdEq
48
- }
49
- });
43
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
50
44
  }
51
45
  const contentRatingEq = (_c = params.contentRating) === null || _c === void 0 ? void 0 : _c.$eq;
52
46
  if (typeof contentRatingEq === 'string') {
53
- andConditions.push({
54
- contentRating: {
55
- $exists: true,
56
- $eq: contentRatingEq
57
- }
58
- });
47
+ andConditions.push({ contentRating: { $exists: true, $eq: contentRatingEq } });
59
48
  }
60
49
  const distributorCodeValueEq = (_e = (_d = params.distributor) === null || _d === void 0 ? void 0 : _d.codeValue) === null || _e === void 0 ? void 0 : _e.$eq;
61
50
  if (typeof distributorCodeValueEq === 'string') {
62
- andConditions.push({
63
- 'distributor.codeValue': {
64
- $exists: true,
65
- $eq: distributorCodeValueEq
66
- }
67
- });
51
+ andConditions.push({ 'distributor.codeValue': { $exists: true, $eq: distributorCodeValueEq } });
68
52
  }
69
53
  const idEq = (_f = params.id) === null || _f === void 0 ? void 0 : _f.$eq;
70
54
  if (typeof idEq === 'string') {
71
- andConditions.push({ _id: { $eq: idEq } });
55
+ // andConditions.push({ _id: { $eq: idEq } });
56
+ andConditions.push({ _id: { $eq: new mongoose_1.Types.ObjectId(idEq) } });
72
57
  }
73
58
  const idIn = (_g = params.id) === null || _g === void 0 ? void 0 : _g.$in;
74
59
  if (Array.isArray(idIn)) {
75
- andConditions.push({ _id: { $in: idIn } });
60
+ // andConditions.push({ _id: { $in: idIn } });
61
+ andConditions.push({ _id: { $in: idIn.map((id) => new mongoose_1.Types.ObjectId(id)) } });
76
62
  }
77
63
  if (typeof params.identifier === 'string') {
78
64
  if (params.identifier.length > 0) {
79
- andConditions.push({
80
- identifier: { $regex: new RegExp(params.identifier) }
81
- });
65
+ andConditions.push({ identifier: { $regex: new RegExp(params.identifier) } });
82
66
  }
83
67
  }
84
68
  else {
85
69
  const identifierEq = (_h = params.identifier) === null || _h === void 0 ? void 0 : _h.$eq;
86
70
  if (typeof identifierEq === 'string') {
87
- andConditions.push({
88
- identifier: { $eq: identifierEq }
89
- });
71
+ andConditions.push({ identifier: { $eq: identifierEq } });
90
72
  }
91
73
  const identifierIn = (_j = params.identifier) === null || _j === void 0 ? void 0 : _j.$in;
92
74
  if (Array.isArray(identifierIn)) {
93
- andConditions.push({
94
- identifier: { $in: identifierIn }
95
- });
75
+ andConditions.push({ identifier: { $in: identifierIn } });
96
76
  }
97
77
  }
98
78
  if (typeof params.name === 'string' && params.name.length > 0) {
99
79
  // 多言語名称対応(2022-07-11~)
100
80
  andConditions.push({
101
81
  $or: [
102
- {
103
- name: {
104
- $exists: true,
105
- $regex: new RegExp(params.name)
106
- }
107
- },
108
- {
109
- 'name.ja': {
110
- $exists: true,
111
- $regex: new RegExp(params.name)
112
- }
113
- },
114
- {
115
- 'name.en': {
116
- $exists: true,
117
- $regex: new RegExp(params.name)
118
- }
119
- }
82
+ { name: { $exists: true, $regex: new RegExp(params.name) } },
83
+ { 'name.ja': { $exists: true, $regex: new RegExp(params.name) } },
84
+ { 'name.en': { $exists: true, $regex: new RegExp(params.name) } }
120
85
  ]
121
86
  });
122
87
  }
123
88
  // tslint:disable-next-line:no-single-line-block-comment
124
89
  /* istanbul ignore else */
125
90
  if (params.datePublishedFrom !== undefined) {
126
- andConditions.push({
127
- datePublished: {
128
- $exists: true,
129
- $gte: params.datePublishedFrom
130
- }
131
- });
91
+ andConditions.push({ datePublished: { $exists: true, $gte: params.datePublishedFrom } });
132
92
  }
133
93
  // tslint:disable-next-line:no-single-line-block-comment
134
94
  /* istanbul ignore else */
135
95
  if (params.datePublishedThrough !== undefined) {
136
- andConditions.push({
137
- datePublished: {
138
- $exists: true,
139
- $lte: params.datePublishedThrough
140
- }
141
- });
96
+ andConditions.push({ datePublished: { $exists: true, $lte: params.datePublishedThrough } });
142
97
  }
143
98
  const offersAvailableFrom = (_k = params.offers) === null || _k === void 0 ? void 0 : _k.availableFrom;
144
99
  if (offersAvailableFrom instanceof Date) {
@@ -171,7 +126,7 @@ class MongoRepository {
171
126
  else {
172
127
  // 上書き禁止属性を除外(2022-08-24~)
173
128
  const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
174
- doc = yield this.creativeWorkModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
129
+ doc = yield this.creativeWorkModel.findOneAndUpdate({ _id: { $eq: params.id } }, updateFields, { upsert: false, new: true })
175
130
  .exec();
176
131
  }
177
132
  if (doc === null) {
@@ -216,20 +171,6 @@ class MongoRepository {
216
171
  }
217
172
  });
218
173
  }
219
- findMovieById(params) {
220
- return __awaiter(this, void 0, void 0, function* () {
221
- const doc = yield this.creativeWorkModel.findOne({ _id: params.id }, {
222
- __v: 0,
223
- createdAt: 0,
224
- updatedAt: 0
225
- })
226
- .exec();
227
- if (doc === null) {
228
- throw new factory.errors.NotFound(this.creativeWorkModel.modelName);
229
- }
230
- return doc.toObject();
231
- });
232
- }
233
174
  /**
234
175
  * コンテンツを検索する
235
176
  */
@@ -276,7 +217,7 @@ class MongoRepository {
276
217
  */
277
218
  deleteMovie(params) {
278
219
  return __awaiter(this, void 0, void 0, function* () {
279
- yield this.creativeWorkModel.findOneAndRemove({ _id: params.id })
220
+ yield this.creativeWorkModel.findOneAndRemove({ _id: { $eq: params.id } })
280
221
  .exec();
281
222
  });
282
223
  }
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  "postversion": "git push origin --tags",
118
118
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
119
119
  },
120
- "version": "21.15.0-alpha.6"
120
+ "version": "21.15.0-alpha.7"
121
121
  }