@chevre/domain 20.3.0-alpha.0 → 20.3.0-alpha.2

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.
@@ -12,9 +12,10 @@ async function main() {
12
12
  const catalogs = await offerCatalogRepo.search({
13
13
  limit: 100,
14
14
  page: 1,
15
- id: { $in: ['0001'] },
15
+ // id: { $in: ['0001'] },
16
16
  itemListElement: {
17
17
  id: {
18
+ $all: ['901', '3001']
18
19
  // $in: ['1001'],
19
20
  // $nin: ['1005']
20
21
  }
@@ -0,0 +1,40 @@
1
+ // tslint:disable:no-console no-magic-numbers
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection);
10
+
11
+ await offerCatalogRepo.updateManyById({
12
+ id: { $in: ['0002'] },
13
+ $pull: {
14
+ itemListElement: {
15
+ $elemMatch: {
16
+ id: {
17
+ $in: [
18
+ // 'al96nqj7z',
19
+ // 'akxecjgeu'
20
+ ]
21
+ }
22
+ }
23
+ }
24
+ },
25
+ $push: {
26
+ itemListElement: {
27
+ $each: [
28
+ { typeOf: chevre.factory.offerType.Offer, id: 'al96nqj7z' },
29
+ { typeOf: chevre.factory.offerType.Offer, id: 'akxecjgeu' }
30
+ ],
31
+ $slice: 200
32
+ }
33
+ }
34
+ });
35
+ console.log('updated');
36
+ }
37
+
38
+ main()
39
+ .then(console.log)
40
+ .catch(console.error);
@@ -8,6 +8,26 @@ export declare class MongoRepository {
8
8
  constructor(connection: Connection);
9
9
  static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
10
10
  save(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
11
+ updateManyById(params: {
12
+ id: {
13
+ $in: string[];
14
+ };
15
+ $push: {
16
+ itemListElement: {
17
+ $each: factory.offerCatalog.IItemListElement[];
18
+ $slice: number;
19
+ };
20
+ };
21
+ $pull: {
22
+ itemListElement: {
23
+ $elemMatch: {
24
+ id: {
25
+ $in: string[];
26
+ };
27
+ };
28
+ };
29
+ };
30
+ }): Promise<void>;
11
31
  findById(params: {
12
32
  id: string;
13
33
  }): Promise<factory.offerCatalog.IOfferCatalog>;
@@ -33,7 +33,7 @@ class MongoRepository {
33
33
  }
34
34
  // tslint:disable-next-line:max-func-body-length
35
35
  static CREATE_MONGO_CONDITIONS(params) {
36
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
36
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
37
37
  // MongoDB検索条件
38
38
  const andConditions = [];
39
39
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -87,7 +87,16 @@ class MongoRepository {
87
87
  }
88
88
  });
89
89
  }
90
- const itemOfferedTypeOfEq = (_m = (_l = params.itemOffered) === null || _l === void 0 ? void 0 : _l.typeOf) === null || _m === void 0 ? void 0 : _m.$eq;
90
+ const itemListElementIdAll = (_m = (_l = params.itemListElement) === null || _l === void 0 ? void 0 : _l.id) === null || _m === void 0 ? void 0 : _m.$all;
91
+ if (Array.isArray(itemListElementIdAll)) {
92
+ andConditions.push({
93
+ 'itemListElement.id': {
94
+ $exists: true,
95
+ $all: itemListElementIdAll
96
+ }
97
+ });
98
+ }
99
+ const itemOfferedTypeOfEq = (_p = (_o = params.itemOffered) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
91
100
  if (typeof itemOfferedTypeOfEq === 'string') {
92
101
  andConditions.push({
93
102
  'itemOffered.typeOf': {
@@ -96,7 +105,7 @@ class MongoRepository {
96
105
  }
97
106
  });
98
107
  }
99
- const itemOfferedServiceTypeCodeValueEq = (_q = (_p = (_o = params.itemOffered) === null || _o === void 0 ? void 0 : _o.serviceType) === null || _p === void 0 ? void 0 : _p.codeValue) === null || _q === void 0 ? void 0 : _q.$eq;
108
+ const itemOfferedServiceTypeCodeValueEq = (_s = (_r = (_q = params.itemOffered) === null || _q === void 0 ? void 0 : _q.serviceType) === null || _r === void 0 ? void 0 : _r.codeValue) === null || _s === void 0 ? void 0 : _s.$eq;
100
109
  if (typeof itemOfferedServiceTypeCodeValueEq === 'string') {
101
110
  andConditions.push({
102
111
  'itemOffered.serviceType.codeValue': {
@@ -105,7 +114,7 @@ class MongoRepository {
105
114
  }
106
115
  });
107
116
  }
108
- const additionalPropertyElemMatch = (_r = params.additionalProperty) === null || _r === void 0 ? void 0 : _r.$elemMatch;
117
+ const additionalPropertyElemMatch = (_t = params.additionalProperty) === null || _t === void 0 ? void 0 : _t.$elemMatch;
109
118
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
110
119
  andConditions.push({
111
120
  additionalProperty: {
@@ -135,6 +144,40 @@ class MongoRepository {
135
144
  return doc.toObject();
136
145
  });
137
146
  }
147
+ updateManyById(params) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
150
+ return;
151
+ }
152
+ const pushItemListElementIds = params.$push.itemListElement.$each.map((element) => element.id);
153
+ yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in } }, (pushItemListElementIds.length > 0)
154
+ // itemListElementのユニークネスを保証する
155
+ ? {
156
+ 'itemListElement.id': {
157
+ $nin: pushItemListElementIds
158
+ }
159
+ }
160
+ : undefined), Object.assign(Object.assign({}, (pushItemListElementIds.length > 0)
161
+ ? {
162
+ $push: {
163
+ itemListElement: {
164
+ $each: params.$push.itemListElement.$each,
165
+ $slice: params.$push.itemListElement.$slice
166
+ }
167
+ }
168
+ }
169
+ : undefined), (params.$pull.itemListElement.$elemMatch.id.$in.length > 0)
170
+ ? {
171
+ $pull: {
172
+ itemListElement: {
173
+ id: { $in: params.$pull.itemListElement.$elemMatch.id.$in }
174
+ }
175
+ }
176
+ }
177
+ : undefined))
178
+ .exec();
179
+ });
180
+ }
138
181
  findById(params) {
139
182
  return __awaiter(this, void 0, void 0, function* () {
140
183
  const doc = yield this.offerCatalogModel.findOne({
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.287.0",
12
+ "@chevre/factory": "4.288.0-alpha.0",
13
13
  "@cinerino/sdk": "3.138.1",
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.3.0-alpha.0"
123
+ "version": "20.3.0-alpha.2"
124
124
  }