@chevre/domain 22.1.0-alpha.7 → 22.1.0-alpha.8

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,56 @@
1
+ // tslint:disable:no-implicit-dependencies no-console
2
+ import * as mongoose from 'mongoose';
3
+ import { chevre } from '../../../lib/index';
4
+
5
+ const project = { id: String(process.env.PROJECT_ID) };
6
+
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const priceSpecificationRepo = await chevre.repository.PriceSpecification.createInstance(mongoose.connection);
11
+
12
+ // const saveResult = await priceSpecificationRepo.save({
13
+ // id: '5e3cdce826c69900127e9d79',
14
+ // attributes: {
15
+ // project: {
16
+ // typeOf: chevre.factory.organizationType.Project,
17
+ // id: project.id
18
+ // },
19
+ // typeOf: chevre.factory.priceSpecificationType.CategoryCodeChargeSpecification,
20
+ // price: 50,
21
+ // priceCurrency: chevre.factory.priceCurrency.JPY,
22
+ // name: {
23
+ // ja: 'ミールクーポン加算料金'
24
+ // },
25
+ // appliesToCategoryCode: [{
26
+ // typeOf: 'CategoryCode',
27
+ // codeValue: 'Meal',
28
+ // inCodeSet: {
29
+ // typeOf: 'CategoryCodeSet',
30
+ // identifier: chevre.factory.categoryCode.CategorySetIdentifier.SeatingType
31
+ // }
32
+ // }],
33
+ // valueAddedTaxIncluded: true
34
+ // }
35
+ // });
36
+ // console.dir(saveResult, { depth: null });
37
+ // console.log('saved');
38
+
39
+ const limit = 10;
40
+ const page = 1;
41
+ const priceSpecs = await priceSpecificationRepo.search({
42
+ limit,
43
+ page,
44
+ project: { id: { $eq: project.id } },
45
+ typeOf: chevre.factory.priceSpecificationType.CategoryCodeChargeSpecification
46
+ });
47
+ // tslint:disable-next-line:no-null-keyword
48
+ console.dir(priceSpecs, { depth: null });
49
+ console.log(priceSpecs.length, 'aggregations found');
50
+ }
51
+
52
+ main()
53
+ .then(() => {
54
+ console.log('success!');
55
+ })
56
+ .catch(console.error);
@@ -30,10 +30,12 @@ const schemaOptions = {
30
30
  writeConcern: writeConcern_1.writeConcern,
31
31
  strict: true,
32
32
  strictQuery: false,
33
- timestamps: {
34
- createdAt: 'createdAt',
35
- updatedAt: 'updatedAt'
36
- },
33
+ // timestamps: {
34
+ // createdAt: 'createdAt',
35
+ // updatedAt: 'updatedAt'
36
+ // },
37
+ timestamps: false,
38
+ versionKey: false,
37
39
  toJSON: {
38
40
  getters: false,
39
41
  virtuals: false,
@@ -39,7 +39,7 @@ export declare class PriceSpecificationRepo {
39
39
  save<T extends factory.priceSpecificationType>(params: {
40
40
  id?: string;
41
41
  attributes: factory.priceSpecification.IPriceSpecification<T>;
42
- }): Promise<factory.priceSpecification.IPriceSpecification<T>>;
42
+ }): Promise<Pick<factory.priceSpecification.IPriceSpecification<T>, 'id'>>;
43
43
  /**
44
44
  * 削除する
45
45
  */
@@ -166,9 +166,22 @@ class PriceSpecificationRepo {
166
166
  return __awaiter(this, void 0, void 0, function* () {
167
167
  const conditions = PriceSpecificationRepo.CREATE_MONGO_CONDITIONS(params);
168
168
  const query = this.priceSpecificationModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
169
- __v: 0,
170
- createdAt: 0,
171
- updatedAt: 0
169
+ _id: 0,
170
+ id: { $toString: '$_id' },
171
+ project: 1,
172
+ typeOf: 1,
173
+ name: 1,
174
+ price: 1,
175
+ priceCurrency: 1,
176
+ validFrom: 1,
177
+ validThrough: 1,
178
+ valueAddedTaxIncluded: 1,
179
+ appliesToCategoryCode: 1,
180
+ appliesToMovieTicket: 1,
181
+ appliesToVideoFormat: 1
182
+ // __v: 0,
183
+ // createdAt: 0,
184
+ // updatedAt: 0
172
185
  });
173
186
  if (typeof params.limit === 'number' && params.limit > 0) {
174
187
  const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
@@ -184,25 +197,41 @@ class PriceSpecificationRepo {
184
197
  // console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
185
198
  // return;
186
199
  return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
187
- .exec()
188
- .then((docs) => docs.map((doc) => doc.toObject()));
200
+ .lean() // lean(2024-08-06~)
201
+ .exec();
189
202
  });
190
203
  }
191
204
  findById(params) {
192
205
  return __awaiter(this, void 0, void 0, function* () {
193
- const doc = yield this.priceSpecificationModel.findOne({ _id: params.id }, {
194
- __v: 0,
195
- createdAt: 0,
196
- updatedAt: 0
206
+ const doc = yield this.priceSpecificationModel.findOne({ _id: { $eq: params.id } }, {
207
+ _id: 0,
208
+ id: { $toString: '$_id' },
209
+ project: 1,
210
+ typeOf: 1,
211
+ name: 1,
212
+ price: 1,
213
+ priceCurrency: 1,
214
+ validFrom: 1,
215
+ validThrough: 1,
216
+ valueAddedTaxIncluded: 1,
217
+ appliesToCategoryCode: 1,
218
+ appliesToMovieTicket: 1,
219
+ appliesToVideoFormat: 1
220
+ // __v: 0,
221
+ // createdAt: 0,
222
+ // updatedAt: 0
197
223
  })
224
+ .lean() // lean(2024-08-06~)
198
225
  .exec();
199
226
  if (doc === null) {
200
227
  throw new factory.errors.NotFound(this.priceSpecificationModel.modelName);
201
228
  }
202
- return doc.toObject();
229
+ return doc;
230
+ // return doc.toObject();
203
231
  });
204
232
  }
205
233
  save(params) {
234
+ var _a;
206
235
  return __awaiter(this, void 0, void 0, function* () {
207
236
  let doc;
208
237
  if (typeof params.id !== 'string') {
@@ -210,14 +239,15 @@ class PriceSpecificationRepo {
210
239
  }
211
240
  else {
212
241
  // 上書き禁止属性を除外(2022-08-24~)
213
- const _a = params.attributes, { id, project, typeOf } = _a, updateFields = __rest(_a, ["id", "project", "typeOf"]);
214
- doc = yield this.priceSpecificationModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
242
+ const _b = params.attributes, { id, project, typeOf } = _b, updateFields = __rest(_b, ["id", "project", "typeOf"]);
243
+ doc = yield this.priceSpecificationModel.findOneAndUpdate({ _id: { $eq: params.id } }, updateFields, { upsert: false, new: true, projection: { _id: 1 } })
244
+ .lean() // lean(2024-08-06~)
215
245
  .exec();
216
246
  }
217
247
  if (doc === null) {
218
248
  throw new factory.errors.NotFound(this.priceSpecificationModel.modelName);
219
249
  }
220
- return doc.toObject();
250
+ return { id: (_a = doc._id) === null || _a === void 0 ? void 0 : _a.toString() };
221
251
  });
222
252
  }
223
253
  /**
@@ -225,7 +255,7 @@ class PriceSpecificationRepo {
225
255
  */
226
256
  deleteById(params) {
227
257
  return __awaiter(this, void 0, void 0, function* () {
228
- yield this.priceSpecificationModel.findOneAndRemove({ _id: params.id })
258
+ yield this.priceSpecificationModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
229
259
  .exec();
230
260
  });
231
261
  }
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "22.1.0-alpha.7"
113
+ "version": "22.1.0-alpha.8"
114
114
  }