@chevre/domain 21.4.0-alpha.2 → 21.4.0-alpha.3

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.
@@ -16,6 +16,12 @@ async function main() {
16
16
  });
17
17
  console.log(offers);
18
18
  console.log(offers.length);
19
+
20
+ // await productOfferRepo.deleteOne({
21
+ // project: { id: PROJECT_ID },
22
+ // seller: { id: 'xxx' },
23
+ // itemOffered: { id: 'xxx' }
24
+ // });
19
25
  }
20
26
 
21
27
  main()
@@ -17,16 +17,18 @@ export declare class MongoRepository {
17
17
  $eq?: string;
18
18
  };
19
19
  };
20
- id?: {
21
- $eq?: string;
20
+ itemOffered?: {
21
+ id?: {
22
+ $eq?: string;
23
+ };
22
24
  };
23
25
  seller?: {
24
26
  id?: {
25
27
  $eq?: string;
26
28
  };
27
29
  };
28
- }): Promise<(Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'> & {
29
- offers: Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'>;
30
+ }): Promise<(Pick<factory.product.IOffer, 'availabilityEnds' | 'availabilityStarts' | 'seller' | 'validFrom' | 'validThrough'> & {
31
+ itemOffered: Pick<factory.product.IProduct, 'id' | 'name' | 'typeOf'>;
30
32
  })[]>;
31
33
  create(params: factory.product.IOffer & {
32
34
  project: {
@@ -54,4 +56,17 @@ export declare class MongoRepository {
54
56
  }): Promise<{
55
57
  id: string;
56
58
  }>;
59
+ deleteOne(params: Pick<factory.product.IOffer, 'seller'> & {
60
+ project: {
61
+ id: string;
62
+ };
63
+ itemOffered: {
64
+ /**
65
+ * プロダクトID
66
+ */
67
+ id: string;
68
+ };
69
+ }): Promise<{
70
+ id: string;
71
+ }>;
57
72
  }
@@ -25,7 +25,7 @@ class MongoRepository {
25
25
  * プロダクトオファー検索
26
26
  */
27
27
  search(params) {
28
- var _a, _b, _c, _d, _e;
28
+ var _a, _b, _c, _d, _e, _f;
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
30
  const matchStages = [{
31
31
  $match: {
@@ -41,11 +41,11 @@ class MongoRepository {
41
41
  if (typeof projectIdEq === 'string') {
42
42
  matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
43
43
  }
44
- const idEq = (_c = params.id) === null || _c === void 0 ? void 0 : _c.$eq;
45
- if (typeof idEq === 'string') {
46
- matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(idEq) } } });
44
+ const itemOfferedIdEq = (_d = (_c = params.itemOffered) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
45
+ if (typeof itemOfferedIdEq === 'string') {
46
+ matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(itemOfferedIdEq) } } });
47
47
  }
48
- const sellerIdEq = (_e = (_d = params.seller) === null || _d === void 0 ? void 0 : _d.id) === null || _e === void 0 ? void 0 : _e.$eq;
48
+ const sellerIdEq = (_f = (_e = params.seller) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
49
49
  if (typeof sellerIdEq === 'string') {
50
50
  matchStages.push({ $match: { 'offers.seller.id': { $exists: true, $eq: sellerIdEq } } });
51
51
  }
@@ -60,16 +60,16 @@ class MongoRepository {
60
60
  {
61
61
  $project: {
62
62
  _id: 0,
63
- offers: {
64
- availabilityEnds: '$offers.availabilityEnds',
65
- availabilityStarts: '$offers.availabilityStarts',
66
- validFrom: '$offers.validFrom',
67
- validThrough: '$offers.validThrough',
68
- seller: '$offers.seller'
63
+ itemOffered: {
64
+ id: { $toString: '$_id' },
65
+ name: '$name',
66
+ typeOf: '$typeOf'
69
67
  },
70
- id: { $toString: '$_id' },
71
- name: '$name',
72
- typeOf: '$typeOf'
68
+ availabilityEnds: '$offers.availabilityEnds',
69
+ availabilityStarts: '$offers.availabilityStarts',
70
+ validFrom: '$offers.validFrom',
71
+ validThrough: '$offers.validThrough',
72
+ seller: '$offers.seller'
73
73
  }
74
74
  }
75
75
  ]);
@@ -158,5 +158,28 @@ class MongoRepository {
158
158
  return doc.toObject();
159
159
  });
160
160
  }
161
+ deleteOne(params) {
162
+ var _a;
163
+ return __awaiter(this, void 0, void 0, function* () {
164
+ const sellerId = (_a = params.seller) === null || _a === void 0 ? void 0 : _a.id;
165
+ if (typeof sellerId !== 'string' || sellerId.length === 0) {
166
+ throw new factory.errors.ArgumentNull('seller.id');
167
+ }
168
+ const doc = yield this.productModel.findOneAndUpdate({
169
+ 'project.id': { $eq: params.project.id },
170
+ _id: { $eq: params.itemOffered.id },
171
+ 'offers.seller.id': { $exists: true, $eq: sellerId }
172
+ }, {
173
+ $pull: { offers: { 'seller.id': { $exists: true, $eq: sellerId } } }
174
+ }, {
175
+ projection: { _id: 1 }
176
+ })
177
+ .exec();
178
+ if (doc === null) {
179
+ throw new factory.errors.NotFound('Product');
180
+ }
181
+ return doc.toObject();
182
+ });
183
+ }
161
184
  }
162
185
  exports.MongoRepository = MongoRepository;
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.4.0-alpha.2"
120
+ "version": "21.4.0-alpha.3"
121
121
  }