@chevre/domain 20.4.0-alpha.19 → 20.4.0-alpha.20

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.
@@ -6,31 +6,14 @@ import { chevre } from '../../../lib/index';
6
6
  async function main() {
7
7
  await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
8
 
9
- // const accountRepo = new chevre.repository.Account(mongoose.connection);
10
- // const permitRepo = new chevre.repository.ServiceOutput(mongoose.connection);
11
- const eventRepo = new chevre.repository.Event(mongoose.connection);
9
+ const offerRepo = new chevre.repository.Offer(mongoose.connection);
12
10
 
13
11
  let updateResult: any;
14
- // updateResult = await accountRepo.unsetUnnecessaryFields({
15
- // filter: { status: { $exists: true } },
16
- // $unset: { status: 1 }
17
- // });
18
- // console.log('accounts unset.', updateResult);
19
- // updateResult = await permitRepo.unsetUnnecessaryFields({
20
- // filter: { 'paymentAccount.project': { $exists: true } },
21
- // $unset: { 'paymentAccount.project': 1 }
22
- // });
23
- // console.log('permits unset', updateResult);
24
- // updateResult = await permitRepo.unsetUnnecessaryFields({
25
- // filter: { 'issuedThrough.project': { $exists: true } },
26
- // $unset: { 'issuedThrough.project': 1 }
27
- // });
28
- // console.log('permits unset', updateResult);
29
- updateResult = await eventRepo.unsetUnnecessaryFields({
30
- filter: { hasOfferCatalog: { $exists: true } },
31
- $unset: { hasOfferCatalog: 1 }
12
+ updateResult = await offerRepo.unsetUnnecessaryFields({
13
+ filter: { 'category.project': { $exists: true } },
14
+ $unset: { 'category.project': 1 }
32
15
  });
33
- console.log('events unset', updateResult);
16
+ console.log('offers unset', updateResult);
34
17
  }
35
18
 
36
19
  main()
@@ -638,14 +638,14 @@ class MongoRepository {
638
638
  return __awaiter(this, void 0, void 0, function* () {
639
639
  const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
640
640
  const positiveProjectionExists = (projection !== undefined && projection !== null)
641
- ? Object.keys(projection)
642
- .some((key) => projection[key] !== 0)
641
+ ? Object.values(projection)
642
+ .some((value) => value !== 0)
643
643
  : false;
644
644
  const query = this.eventModel.find({ $and: conditions },
645
645
  // :1対応(2023-01-25~)
646
646
  (positiveProjectionExists)
647
647
  ? projection
648
- : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection));
648
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
649
649
  if (typeof params.limit === 'number') {
650
650
  const page = (typeof params.page === 'number') ? params.page : 1;
651
651
  query.limit(params.limit)
@@ -680,14 +680,14 @@ class MongoRepository {
680
680
  findById(params, projection) {
681
681
  return __awaiter(this, void 0, void 0, function* () {
682
682
  const positiveProjectionExists = (projection !== undefined && projection !== null)
683
- ? Object.keys(projection)
684
- .some((key) => projection[key] !== 0)
683
+ ? Object.values(projection)
684
+ .some((value) => value !== 0)
685
685
  : false;
686
686
  const doc = yield this.eventModel.findOne({ _id: params.id },
687
687
  // :1対応(2023-01-25~)
688
688
  (positiveProjectionExists)
689
689
  ? projection
690
- : Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection))
690
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }))
691
691
  .exec();
692
692
  if (doc === null) {
693
693
  throw new factory.errors.NotFound(this.eventModel.modelName);
@@ -1,7 +1,7 @@
1
1
  import { Connection } from 'mongoose';
2
2
  import * as factory from '../factory';
3
3
  interface IProjection {
4
- [key: string]: 0;
4
+ [key: string]: 0 | 1;
5
5
  }
6
6
  /**
7
7
  * オファーリポジトリ
@@ -56,5 +56,9 @@ export declare class MongoRepository {
56
56
  };
57
57
  }): Promise<void>;
58
58
  getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
59
+ unsetUnnecessaryFields(params: {
60
+ filter: any;
61
+ $unset: any;
62
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
59
63
  }
60
64
  export {};
@@ -407,7 +407,13 @@ class MongoRepository {
407
407
  search(params, projection) {
408
408
  return __awaiter(this, void 0, void 0, function* () {
409
409
  const conditions = MongoRepository.CREATE_OFFER_MONGO_CONDITIONS(params);
410
- const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
410
+ const positiveProjectionExists = (projection !== undefined && projection !== null)
411
+ ? Object.values(projection)
412
+ .some((value) => value !== 0)
413
+ : false;
414
+ const query = this.offerModel.find((conditions.length > 0) ? { $and: conditions } : {}, (positiveProjectionExists)
415
+ ? projection
416
+ : Object.assign(Object.assign({}, projection), { __v: 0, createdAt: 0, updatedAt: 0 }));
411
417
  if (typeof params.limit === 'number') {
412
418
  const page = (typeof params.page === 'number') ? params.page : 1;
413
419
  query.limit(params.limit)
@@ -496,5 +502,11 @@ class MongoRepository {
496
502
  .sort({ 'priceSpecification.price': factory.sortType.Descending })
497
503
  .cursor();
498
504
  }
505
+ unsetUnnecessaryFields(params) {
506
+ return __awaiter(this, void 0, void 0, function* () {
507
+ return this.offerModel.updateMany(params.filter, { $unset: params.$unset })
508
+ .exec();
509
+ });
510
+ }
499
511
  }
500
512
  exports.MongoRepository = MongoRepository;
package/package.json CHANGED
@@ -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.4.0-alpha.19"
123
+ "version": "20.4.0-alpha.20"
124
124
  }