@chevre/domain 21.17.0-alpha.15 → 21.17.0-alpha.17

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,40 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ const project = { id: String(process.env.PROJECT_ID) };
7
+
8
+ async function main() {
9
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
10
+
11
+ const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);
12
+
13
+ let result = await offerCatalogItemRepo.save({
14
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
15
+ typeOf: 'OfferCatalog',
16
+ // id?: string;
17
+ identifier: 'sample',
18
+ name: { ja: 'sample', en: 'sample' },
19
+ description: { ja: 'sample', en: 'sample' },
20
+ itemListElement: [],
21
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService }
22
+ });
23
+ console.log(result);
24
+
25
+ result = await offerCatalogItemRepo.save({
26
+ project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
27
+ typeOf: 'OfferCatalog',
28
+ id: result.id,
29
+ identifier: 'sample',
30
+ name: { ja: 'sample', en: 'sample' },
31
+ description: { ja: 'sample', en: 'sample' },
32
+ itemListElement: [],
33
+ itemOffered: { typeOf: chevre.factory.product.ProductType.EventService }
34
+ });
35
+ console.log(result);
36
+ }
37
+
38
+ main()
39
+ .then(console.log)
40
+ .catch(console.error);
@@ -15,11 +15,17 @@ export declare class MongoRepository {
15
15
  private readonly offerCatalogItemModel;
16
16
  constructor(connection: Connection);
17
17
  static CREATE_MONGO_CONDITIONS(params: factory.offerCatalog.ISearchConditions): any[];
18
- save(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
18
+ save(params: factory.offerCatalog.IOfferCatalog & {
19
+ $unset?: any;
20
+ }): Promise<{
21
+ id: string;
22
+ }>;
19
23
  /**
20
24
  * プロジェクトとコードから冪等保管
21
25
  */
22
- saveByIdentifier(params: factory.offerCatalog.IOfferCatalog): Promise<factory.offerCatalog.IOfferCatalog>;
26
+ saveByIdentifier(params: factory.offerCatalog.IOfferCatalog): Promise<{
27
+ id: string;
28
+ }>;
23
29
  /**
24
30
  * 同期日時を更新する
25
31
  */
@@ -107,18 +107,18 @@ class MongoRepository {
107
107
  return __awaiter(this, void 0, void 0, function* () {
108
108
  let doc;
109
109
  if (typeof params.id !== 'string' || params.id.length === 0) {
110
- const { id } = params, creatingDoc = __rest(params, ["id"]);
110
+ const { id, $unset } = params, creatingDoc = __rest(params, ["id", "$unset"]);
111
111
  doc = yield this.offerCatalogItemModel.create(creatingDoc);
112
112
  }
113
113
  else {
114
- const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
115
- doc = yield this.offerCatalogItemModel.findOneAndUpdate({ _id: { $eq: params.id } }, updateFields, { upsert: false, new: true })
114
+ const { id, identifier, project, typeOf, $unset } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf", "$unset"]);
115
+ doc = yield this.offerCatalogItemModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert: false, new: true, projection: { _id: 1 } })
116
116
  .exec();
117
117
  }
118
118
  if (doc === null) {
119
119
  throw new factory.errors.NotFound(this.offerCatalogItemModel.modelName);
120
120
  }
121
- return doc.toObject();
121
+ return { id: doc.id };
122
122
  });
123
123
  }
124
124
  /**
@@ -135,7 +135,7 @@ class MongoRepository {
135
135
  $setOnInsert: { identifier, project, typeOf }
136
136
  }, { upsert: true, new: true })
137
137
  .exec();
138
- return doc.toObject();
138
+ return { id: doc.id };
139
139
  });
140
140
  }
141
141
  /**
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.17.0-alpha.15"
120
+ "version": "21.17.0-alpha.17"
121
121
  }