@chevre/domain 23.0.0-alpha.3 → 23.0.0-alpha.30

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.
Files changed (81) hide show
  1. package/example/src/chevre/assetTransaction/processReserve.ts +102 -40
  2. package/example/src/chevre/categoryCode/checkUniqueness.ts +69 -0
  3. package/example/src/chevre/event/checkEventAdditionalPropertyUniqueness.ts +108 -0
  4. package/example/src/chevre/event/migrateEventAdditionalProperty2identifier.ts +121 -0
  5. package/example/src/chevre/event/updateSellerMakesOffersByIdentifier.ts +106 -0
  6. package/example/src/chevre/note/findNotes.ts +34 -0
  7. package/example/src/chevre/note/upsertNotesByIdentifier.ts +10 -5
  8. package/example/src/chevre/offerCatalog/updateManyOfferCatalogsByIds.ts +49 -0
  9. package/example/src/chevre/paymentServices/findPaymentServices.ts +37 -0
  10. package/example/src/chevre/product/findHasOfferCatalog.ts +31 -0
  11. package/example/src/chevre/reIndex.ts +2 -3
  12. package/example/src/chevre/roles/addAdminNotePermissionIfNotExists.ts +48 -0
  13. package/example/src/chevre/roles/{addAdminProductOfferPermissionIfNotExists.ts → addAdminPaymentServiceReadPermissionIfNotExists.ts} +20 -19
  14. package/example/src/chevre/roles/addAdminProductHasOfferCatalogReadPermissionIfNotExists.ts +33 -0
  15. package/example/src/chevre/roles/addAdminSellerEventIfNotExists.ts +48 -0
  16. package/example/src/chevre/roles/removeConsolePermissionIfExists.ts +1 -1
  17. package/example/src/chevre/roles/removePermissionIfExists.ts +1 -6
  18. package/example/src/chevre/unsetUnnecessaryFields.ts +5 -7
  19. package/example/src/objectId.ts +12 -0
  20. package/example/src/signPayload.ts +12 -7
  21. package/lib/chevre/errorHandler.d.ts +6 -2
  22. package/lib/chevre/errorHandler.js +18 -2
  23. package/lib/chevre/repo/categoryCode.d.ts +26 -14
  24. package/lib/chevre/repo/categoryCode.js +53 -42
  25. package/lib/chevre/repo/event.d.ts +25 -11
  26. package/lib/chevre/repo/event.js +60 -35
  27. package/lib/chevre/repo/eventSellerMakesOffer.d.ts +24 -39
  28. package/lib/chevre/repo/eventSellerMakesOffer.js +88 -43
  29. package/lib/chevre/repo/issuer.js +9 -5
  30. package/lib/chevre/repo/mongoose/schemas/categoryCode.js +48 -42
  31. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.d.ts +10 -0
  32. package/lib/chevre/repo/mongoose/schemas/movieTicketTypes.js +107 -0
  33. package/lib/chevre/repo/mongoose/schemas/note.js +9 -0
  34. package/lib/chevre/repo/mongoose/schemas/product.d.ts +4 -4
  35. package/lib/chevre/repo/mongoose/schemas/product.js +2 -2
  36. package/lib/chevre/repo/movieTicketType.d.ts +57 -0
  37. package/lib/chevre/repo/movieTicketType.js +253 -0
  38. package/lib/chevre/repo/note.d.ts +2 -9
  39. package/lib/chevre/repo/note.js +52 -18
  40. package/lib/chevre/repo/noteAboutOrder.d.ts +4 -0
  41. package/lib/chevre/repo/noteAboutOrder.js +17 -0
  42. package/lib/chevre/repo/offerCatalog.d.ts +17 -2
  43. package/lib/chevre/repo/offerCatalog.js +5 -2
  44. package/lib/chevre/repo/product.js +15 -14
  45. package/lib/chevre/repo/productHasOfferCatalog.d.ts +43 -0
  46. package/lib/chevre/repo/productHasOfferCatalog.js +71 -0
  47. package/lib/chevre/repository.d.ts +10 -0
  48. package/lib/chevre/repository.js +28 -2
  49. package/lib/chevre/service/assetTransaction/reserve/start.js +2 -2
  50. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.d.ts +15 -0
  51. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateIssuedOfferIfExists.js +159 -0
  52. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +16 -0
  53. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +184 -0
  54. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +4 -1
  55. package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +25 -138
  56. package/lib/chevre/service/event.js +1 -1
  57. package/lib/chevre/service/offer/event/importFromCOA.js +1 -1
  58. package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +3 -3
  59. package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +3 -3
  60. package/lib/chevre/service/offer/onEventChanged.js +26 -30
  61. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.d.ts +39 -0
  62. package/lib/chevre/service/payment/any/authorize/fixTransactionNumber.js +86 -0
  63. package/lib/chevre/service/payment/any/{handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts → authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.d.ts} +4 -4
  64. package/lib/chevre/service/payment/any/{handlePrePublishedPaymentMethodIdOnAuthorizing.js → authorize/handlePrePublishedPaymentMethodIdOnAuthorizing.js} +1 -1
  65. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.d.ts +25 -0
  66. package/lib/chevre/service/payment/any/publishPaymentUrl/fixTransactionNumberOnPublishPaymentUrl.js +51 -0
  67. package/lib/chevre/service/payment/any/verifyTicketTokenAsNeeded.d.ts +2 -2
  68. package/lib/chevre/service/payment/any.js +91 -70
  69. package/lib/chevre/service/project.d.ts +3 -0
  70. package/lib/chevre/service/project.js +2 -1
  71. package/lib/chevre/service/task/createEvent/createEventBySchedule/factory.js +19 -105
  72. package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +1 -1
  73. package/lib/chevre/service/task/onResourceUpdated.js +1 -1
  74. package/package.json +4 -4
  75. package/example/src/chevre/aggregateEventSellerMakesOffer.ts +0 -32
  76. package/example/src/chevre/event/migrateEventIdentifier4ttts.ts +0 -96
  77. package/example/src/chevre/searchCategoryCodesByAggregate.ts +0 -31
  78. package/example/src/chevre/searchOfferCatalogItems.ts +0 -59
  79. package/example/src/chevre/searchPaymentServices.ts +0 -32
  80. package/example/src/chevre/unsetUnnecessaryFieldsInAction.ts +0 -50
  81. package/example/src/chevre/unsetUnnecessaryFieldsInTransaction.ts +0 -46
@@ -0,0 +1,253 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.MovieTicketTypeRepo = void 0;
24
+ // tslint:disable-next-line:no-implicit-dependencies
25
+ const mongoose_1 = require("mongoose");
26
+ // import { createSchema, modelName } from './mongoose/schemas/categoryCode';
27
+ const movieTicketTypes_1 = require("./mongoose/schemas/movieTicketTypes");
28
+ const factory = require("../factory");
29
+ const settings_1 = require("../settings");
30
+ const AVAILABLE_PROJECT_FIELDS = [
31
+ 'codeValue', 'color', 'image', 'inCodeSet', 'name', 'paymentMethod', 'project', 'typeOf'
32
+ ];
33
+ /**
34
+ * 決済カード区分リポジトリ
35
+ */
36
+ class MovieTicketTypeRepo {
37
+ constructor(connection) {
38
+ this.categoryCodeModel = connection.model(movieTicketTypes_1.modelName, (0, movieTicketTypes_1.createSchema)());
39
+ }
40
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
41
+ static CREATE_MONGO_CONDITIONS(params) {
42
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
43
+ const andConditions = [
44
+ {
45
+ 'inCodeSet.identifier': {
46
+ $eq: factory.movieTicketType.CategorySetIdentifier.MovieTicketType
47
+ }
48
+ }
49
+ ];
50
+ // tslint:disable-next-line:no-single-line-block-comment
51
+ /* istanbul ignore else */
52
+ if (params.project !== undefined && params.project !== null) {
53
+ if (params.project.id !== undefined && params.project.id !== null) {
54
+ if (typeof params.project.id.$eq === 'string') {
55
+ andConditions.push({
56
+ 'project.id': {
57
+ $eq: params.project.id.$eq
58
+ }
59
+ });
60
+ }
61
+ }
62
+ }
63
+ const idEq = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$eq;
64
+ if (typeof idEq === 'string') {
65
+ // andConditions.push({ _id: { $eq: idEq } });
66
+ andConditions.push({ _id: { $eq: new mongoose_1.Types.ObjectId(idEq) } });
67
+ }
68
+ const idIn = (_b = params.id) === null || _b === void 0 ? void 0 : _b.$in;
69
+ if (Array.isArray(idIn)) {
70
+ // andConditions.push({ _id: { $in: idIn } });
71
+ andConditions.push({ _id: { $in: idIn.map((id) => new mongoose_1.Types.ObjectId(id)) } });
72
+ }
73
+ // tslint:disable-next-line:no-single-line-block-comment
74
+ /* istanbul ignore else */
75
+ if (params.name !== undefined && params.name !== null) {
76
+ if (typeof params.name.$regex === 'string' && params.name.$regex.length > 0) {
77
+ andConditions.push({
78
+ $or: [
79
+ {
80
+ 'name.ja': {
81
+ $exists: true,
82
+ $regex: new RegExp(params.name.$regex)
83
+ }
84
+ },
85
+ {
86
+ 'name.en': {
87
+ $exists: true,
88
+ $regex: new RegExp(params.name.$regex)
89
+ }
90
+ }
91
+ ]
92
+ });
93
+ }
94
+ }
95
+ const codeValueEq = (_c = params.codeValue) === null || _c === void 0 ? void 0 : _c.$eq;
96
+ if (typeof codeValueEq === 'string') {
97
+ andConditions.push({ codeValue: { $eq: codeValueEq } });
98
+ }
99
+ const codeValueIn = (_d = params.codeValue) === null || _d === void 0 ? void 0 : _d.$in;
100
+ if (Array.isArray(codeValueIn)) {
101
+ andConditions.push({ codeValue: { $in: codeValueIn } });
102
+ }
103
+ // tslint:disable-next-line:no-single-line-block-comment
104
+ /* istanbul ignore else */
105
+ if (params.inCodeSet !== undefined && params.inCodeSet !== null) {
106
+ if (params.inCodeSet.identifier !== undefined && params.inCodeSet.identifier !== null) {
107
+ if (typeof params.inCodeSet.identifier.$eq === 'string') {
108
+ andConditions.push({
109
+ 'inCodeSet.identifier': {
110
+ $eq: params.inCodeSet.identifier.$eq
111
+ }
112
+ });
113
+ }
114
+ }
115
+ }
116
+ const inCodeSetIdentifierIn = (_f = (_e = params.inCodeSet) === null || _e === void 0 ? void 0 : _e.identifier) === null || _f === void 0 ? void 0 : _f.$in;
117
+ if (Array.isArray(inCodeSetIdentifierIn)) {
118
+ andConditions.push({
119
+ 'inCodeSet.identifier': {
120
+ $in: inCodeSetIdentifierIn
121
+ }
122
+ });
123
+ }
124
+ const paymentMethodTypeOfEq = (_h = (_g = params.paymentMethod) === null || _g === void 0 ? void 0 : _g.typeOf) === null || _h === void 0 ? void 0 : _h.$eq;
125
+ if (typeof paymentMethodTypeOfEq === 'string') {
126
+ andConditions.push({
127
+ 'paymentMethod.typeOf': {
128
+ $exists: true,
129
+ $eq: paymentMethodTypeOfEq
130
+ }
131
+ });
132
+ }
133
+ const paymentMethodTypeOfIn = (_k = (_j = params.paymentMethod) === null || _j === void 0 ? void 0 : _j.typeOf) === null || _k === void 0 ? void 0 : _k.$in;
134
+ if (Array.isArray(paymentMethodTypeOfIn)) {
135
+ andConditions.push({
136
+ 'paymentMethod.typeOf': {
137
+ $exists: true,
138
+ $in: paymentMethodTypeOfIn
139
+ }
140
+ });
141
+ }
142
+ return andConditions;
143
+ }
144
+ static CREATE_AGGREGATE_PROJECTION(inclusion) {
145
+ let projectStage = {
146
+ _id: 0,
147
+ id: { $toString: '$_id' },
148
+ project: '$project',
149
+ typeOf: '$typeOf',
150
+ color: '$color',
151
+ image: '$image',
152
+ codeValue: '$codeValue',
153
+ inCodeSet: '$inCodeSet',
154
+ name: '$name',
155
+ paymentMethod: '$paymentMethod'
156
+ };
157
+ if (inclusion.length > 0) {
158
+ projectStage = { _id: 0 };
159
+ inclusion.forEach((field) => {
160
+ switch (field) {
161
+ // case '_id':
162
+ case 'id':
163
+ projectStage.id = { $toString: '$_id' };
164
+ break;
165
+ default:
166
+ projectStage[field] = `$${field}`;
167
+ }
168
+ });
169
+ }
170
+ return projectStage;
171
+ }
172
+ /**
173
+ * 決済カード区分検索
174
+ */
175
+ projectMovieTicketTypeFields(params,
176
+ /**
177
+ * 空の場合無効
178
+ */
179
+ inclusion) {
180
+ return __awaiter(this, void 0, void 0, function* () {
181
+ const conditions = MovieTicketTypeRepo.CREATE_MONGO_CONDITIONS(params);
182
+ let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
183
+ if (Array.isArray(inclusion) && inclusion.length > 0) {
184
+ positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
185
+ }
186
+ const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
187
+ const query = this.categoryCodeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
188
+ if (typeof params.limit === 'number' && params.limit > 0) {
189
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
190
+ query.limit(params.limit)
191
+ .skip(params.limit * (page - 1));
192
+ }
193
+ // tslint:disable-next-line:no-single-line-block-comment
194
+ /* istanbul ignore else */
195
+ if (params.sort !== undefined) {
196
+ query.sort(params.sort);
197
+ }
198
+ return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
199
+ .lean() // 2024-08-19~
200
+ .exec();
201
+ });
202
+ }
203
+ saveMovieTicketType(params) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ let savedId;
206
+ // let doc: HydratedDocument<{ _id: Types.ObjectId }> | null;
207
+ if (typeof params.id !== 'string') {
208
+ const _a = params.attributes, { id, $unset } = _a, creatingDoc = __rest(_a, ["id", "$unset"]);
209
+ const createResult = yield this.categoryCodeModel.create(creatingDoc);
210
+ // doc = createResult;
211
+ if (typeof createResult.id !== 'string') {
212
+ throw new factory.errors.Internal(`failed in creating ${creatingDoc.typeOf} unexpectedly`);
213
+ }
214
+ savedId = createResult.id;
215
+ }
216
+ else {
217
+ // 上書き禁止属性を除外(2022-08-24~)
218
+ const _b = params.attributes, { id, codeValue, inCodeSet, project, typeOf, $unset } = _b, updateFields = __rest(_b, ["id", "codeValue", "inCodeSet", "project", "typeOf", "$unset"]);
219
+ const doc = yield this.categoryCodeModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: updateFields }, ($unset !== undefined) ? { $unset } : undefined), { upsert: false, new: true, projection: { _id: 1 } })
220
+ .exec();
221
+ if (doc === null) {
222
+ throw new factory.errors.NotFound(this.categoryCodeModel.modelName);
223
+ }
224
+ savedId = params.id;
225
+ }
226
+ // if (doc === null) {
227
+ // throw new factory.errors.NotFound(this.categoryCodeModel.modelName);
228
+ // }
229
+ return { id: savedId };
230
+ });
231
+ }
232
+ /**
233
+ * 削除する
234
+ */
235
+ deleteMovieTicketTypeById(params) {
236
+ return __awaiter(this, void 0, void 0, function* () {
237
+ yield this.categoryCodeModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
238
+ .exec();
239
+ });
240
+ }
241
+ /**
242
+ * プロジェクト指定で削除する
243
+ */
244
+ deleteMovieTicketTypesByProject(params) {
245
+ return __awaiter(this, void 0, void 0, function* () {
246
+ yield this.categoryCodeModel.deleteMany({
247
+ 'project.id': { $eq: params.project.id }
248
+ })
249
+ .exec();
250
+ });
251
+ }
252
+ }
253
+ exports.MovieTicketTypeRepo = MovieTicketTypeRepo;
@@ -15,6 +15,8 @@ export declare class NoteRepo {
15
15
  })[]>;
16
16
  /**
17
17
  * メモ識別子をキーにして冪等置換
18
+ * 主題+識別子でユニーク必須
19
+ * 編集の場合、存在検証される
18
20
  */
19
21
  upsertNotesByIdentifier(params: {
20
22
  $set: Pick<INoteDigitalDocument, 'about' | 'creator' | 'identifier' | 'project' | 'provider' | 'text' | 'version' | 'hasDigitalDocumentPermission'> & {
@@ -32,15 +34,6 @@ export declare class NoteRepo {
32
34
  id: string;
33
35
  }[];
34
36
  } | void>;
35
- /**
36
- * 既知のメモIDリストからメモを削除する
37
- */
38
- deleteNotesByIds(params: {
39
- project: {
40
- id: string;
41
- };
42
- ids: string[];
43
- }): Promise<DeleteResult | void>;
44
37
  /**
45
38
  * 主題リソースから全メモを削除する
46
39
  */
@@ -35,7 +35,7 @@ class NoteRepo {
35
35
  this.noteModel = connection.model(note_1.modelName, (0, note_1.createSchema)());
36
36
  }
37
37
  static CREATE_MONGO_CONDITIONS(params) {
38
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
39
39
  const andConditions = [];
40
40
  const idIn = (_a = params.id) === null || _a === void 0 ? void 0 : _a.$in;
41
41
  if (Array.isArray(idIn)) {
@@ -77,6 +77,10 @@ class NoteRepo {
77
77
  if (Array.isArray(identifierIn)) {
78
78
  andConditions.push({ identifier: { $in: identifierIn } });
79
79
  }
80
+ const audienceTypeEq = (_v = (_u = (_t = params.hasDigitalDocumentPermission) === null || _t === void 0 ? void 0 : _t.grantee) === null || _u === void 0 ? void 0 : _u.audienceType) === null || _v === void 0 ? void 0 : _v.$eq;
81
+ if (typeof audienceTypeEq === 'string') {
82
+ andConditions.push({ 'hasDigitalDocumentPermission.grantee.audienceType': { $exists: true, $eq: audienceTypeEq } });
83
+ }
80
84
  return andConditions;
81
85
  }
82
86
  findNotes(params, inclusion) {
@@ -107,25 +111,33 @@ class NoteRepo {
107
111
  }
108
112
  /**
109
113
  * メモ識別子をキーにして冪等置換
114
+ * 主題+識別子でユニーク必須
115
+ * 編集の場合、存在検証される
110
116
  */
117
+ // tslint:disable-next-line:max-func-body-length
111
118
  upsertNotesByIdentifier(params, options) {
112
119
  return __awaiter(this, void 0, void 0, function* () {
113
120
  const now = new Date();
114
121
  const { update } = options;
115
122
  const bulkWriteOps = [];
116
123
  const queryFilters = [];
124
+ let uniqueIdentifiers = [];
117
125
  if (Array.isArray(params)) {
118
126
  params.forEach(({ $set }) => {
119
127
  const { about, creator, identifier, project, provider, text, version, hasDigitalDocumentPermission } = $set;
120
- if (typeof identifier !== 'string' || identifier.length === 0) {
128
+ if (typeof about.id !== 'string' || about.id === '') {
129
+ throw new factory.errors.ArgumentNull('about.id');
130
+ }
131
+ if (typeof identifier !== 'string' || identifier === '') {
121
132
  throw new factory.errors.ArgumentNull('identifier');
122
133
  }
123
- if (typeof version !== 'string' || version.length === 0) {
134
+ if (typeof version !== 'string' || version === '') {
124
135
  throw new factory.errors.ArgumentNull('version');
125
136
  }
126
137
  if (typeof text !== 'string') {
127
138
  throw new factory.errors.ArgumentNull('text');
128
139
  }
140
+ uniqueIdentifiers.push(`${about.id}:${identifier}`);
129
141
  // リソースのユニークネスを保証するfilter
130
142
  const filter = {
131
143
  'project.id': { $eq: project.id },
@@ -167,6 +179,25 @@ class NoteRepo {
167
179
  });
168
180
  }
169
181
  if (bulkWriteOps.length > 0) {
182
+ // 主題+識別子でユニーク検証
183
+ uniqueIdentifiers = [...new Set(uniqueIdentifiers)];
184
+ if (uniqueIdentifiers.length !== bulkWriteOps.length) {
185
+ throw new factory.errors.Argument('identifier', '(about.id + identifier)s must be unique');
186
+ }
187
+ if (update === true) {
188
+ // 編集の場合、存在検証
189
+ const modifyingNotes = yield this.noteModel.find({ $or: queryFilters }, {
190
+ _id: 0,
191
+ id: { $toString: '$_id' }
192
+ })
193
+ .lean()
194
+ .exec();
195
+ // tslint:disable-next-line:no-console
196
+ console.log('NoteRepo.upsertNotesByIdentifier:', params.length, 'params ->', modifyingNotes.length, 'modifyingNotes found.', JSON.stringify(modifyingNotes));
197
+ if (modifyingNotes.length !== bulkWriteOps.length) {
198
+ throw new factory.errors.NotFound(factory.creativeWorkType.NoteDigitalDocument);
199
+ }
200
+ }
170
201
  const bulkWriteResult = yield this.noteModel.bulkWrite(bulkWriteOps, { ordered: false });
171
202
  // modifiedの場合upsertedIdsに含まれないので、idを検索する
172
203
  const modifiedNotes = yield this.noteModel.find({ $or: queryFilters }, {
@@ -179,21 +210,24 @@ class NoteRepo {
179
210
  }
180
211
  });
181
212
  }
182
- /**
183
- * 既知のメモIDリストからメモを削除する
184
- */
185
- deleteNotesByIds(params) {
186
- return __awaiter(this, void 0, void 0, function* () {
187
- const { project, ids } = params;
188
- if (Array.isArray(ids) && ids.length > 0) {
189
- return this.noteModel.deleteMany({
190
- 'project.id': { $eq: project.id },
191
- _id: { $in: ids }
192
- })
193
- .exec();
194
- }
195
- });
196
- }
213
+ // /**
214
+ // * 既知のメモIDリストからメモを削除する
215
+ // */
216
+ // public async deleteNotesByIds(params: {
217
+ // project: { id: string };
218
+ // ids: string[];
219
+ // }): Promise<DeleteResult | void> {
220
+ // const { project, ids } = params;
221
+ // if (Array.isArray(ids) && ids.length > 0) {
222
+ // return this.noteModel.deleteMany(
223
+ // {
224
+ // 'project.id': { $eq: project.id },
225
+ // _id: { $in: ids }
226
+ // }
227
+ // )
228
+ // .exec();
229
+ // }
230
+ // }
197
231
  /**
198
232
  * 主題リソースから全メモを削除する
199
233
  */
@@ -26,5 +26,9 @@ export declare class NoteAboutOrderRepo {
26
26
  id: string;
27
27
  attributes: Pick<INoteAboutOrder, 'text' | 'editor'>;
28
28
  }): Promise<void>;
29
+ unsetUnnecessaryFields(params: {
30
+ filter: FilterQuery<factory.creativeWork.noteDigitalDocument.INoteAboutOrder>;
31
+ $unset: any;
32
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
29
33
  }
30
34
  export {};
@@ -175,5 +175,22 @@ class NoteAboutOrderRepo {
175
175
  }
176
176
  });
177
177
  }
178
+ // public getCursor(conditions: FilterQuery<factory.creativeWork.noteDigitalDocument.INoteAboutOrder>, projection: any) {
179
+ // return this.noteModel.find(
180
+ // {
181
+ // ...conditions,
182
+ // 'about.typeOf': { $eq: factory.order.OrderType.Order }
183
+ // },
184
+ // projection
185
+ // )
186
+ // .sort({ dateCreated: factory.sortType.Ascending })
187
+ // .cursor();
188
+ // }
189
+ unsetUnnecessaryFields(params) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ return this.noteModel.updateMany(Object.assign(Object.assign({}, params.filter), { 'about.typeOf': { $eq: factory.order.OrderType.Order } }), { $unset: params.$unset }, { timestamps: false })
192
+ .exec();
193
+ });
194
+ }
178
195
  }
179
196
  exports.NoteAboutOrderRepo = NoteAboutOrderRepo;
@@ -48,13 +48,28 @@ export declare class OfferCatalogRepo {
48
48
  id: string;
49
49
  dateSynced: Date;
50
50
  }): Promise<void>;
51
- updateManyById(params: {
51
+ /**
52
+ * オファーカタログIDリストからitemListElementをまとめて編集する
53
+ */
54
+ updateManyOfferCatalogsByIds(params: {
52
55
  id: {
53
56
  $in: string[];
54
57
  };
58
+ itemOffered: {
59
+ typeOf: {
60
+ $eq: factory.product.ProductType;
61
+ };
62
+ };
55
63
  $push: {
56
64
  itemListElement: {
57
- $each: factory.offerCatalog.IItemListElement[];
65
+ /**
66
+ * ひとまず要素がOfferのみに対応
67
+ */
68
+ $each: factory.offerCatalog.IItemListElementAsAggregateOffer[];
69
+ /**
70
+ * カタログ内最大要素数
71
+ * 指定した数でsliceされる
72
+ */
58
73
  $slice: number;
59
74
  };
60
75
  };
@@ -252,13 +252,16 @@ class OfferCatalogRepo {
252
252
  .exec();
253
253
  });
254
254
  }
255
- updateManyById(params) {
255
+ /**
256
+ * オファーカタログIDリストからitemListElementをまとめて編集する
257
+ */
258
+ updateManyOfferCatalogsByIds(params) {
256
259
  return __awaiter(this, void 0, void 0, function* () {
257
260
  if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
258
261
  return;
259
262
  }
260
263
  const pushItemListElementIds = params.$push.itemListElement.$each.map((element) => element.id);
261
- yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in } }, (pushItemListElementIds.length > 0)
264
+ yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in }, 'itemOffered.typeOf': { $exists: true, $eq: params.itemOffered.typeOf.$eq } }, (pushItemListElementIds.length > 0)
262
265
  // itemListElementのユニークネスを保証する
263
266
  ? {
264
267
  'itemListElement.id': {
@@ -48,7 +48,7 @@ class ProductRepo {
48
48
  }
49
49
  // tslint:disable-next-line:max-func-body-length
50
50
  static CREATE_MONGO_CONDITIONS(params) {
51
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
51
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
52
52
  // MongoDB検索条件
53
53
  const andConditions = [];
54
54
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
@@ -111,15 +111,16 @@ class ProductRepo {
111
111
  productID: { $regex: new RegExp(productIDRegex) }
112
112
  });
113
113
  }
114
- const offersElemMatch = (_m = params.offers) === null || _m === void 0 ? void 0 : _m.$elemMatch;
115
- if (offersElemMatch !== undefined && offersElemMatch !== null) {
116
- andConditions.push({
117
- offers: {
118
- $elemMatch: offersElemMatch
119
- }
120
- });
121
- }
122
- const serviceOutputTypeOfEq = (_p = (_o = params.serviceOutput) === null || _o === void 0 ? void 0 : _o.typeOf) === null || _p === void 0 ? void 0 : _p.$eq;
114
+ // discontinue product.offers
115
+ // const offersElemMatch = params.offers?.$elemMatch;
116
+ // if (offersElemMatch !== undefined && offersElemMatch !== null) {
117
+ // andConditions.push({
118
+ // offers: {
119
+ // $elemMatch: offersElemMatch
120
+ // }
121
+ // });
122
+ // }
123
+ const serviceOutputTypeOfEq = (_o = (_m = params.serviceOutput) === null || _m === void 0 ? void 0 : _m.typeOf) === null || _o === void 0 ? void 0 : _o.$eq;
123
124
  if (typeof serviceOutputTypeOfEq === 'string') {
124
125
  andConditions.push({
125
126
  'serviceOutput.typeOf': {
@@ -128,7 +129,7 @@ class ProductRepo {
128
129
  }
129
130
  });
130
131
  }
131
- const serviceOutputAmountCurrencyEq = (_s = (_r = (_q = params.serviceOutput) === null || _q === void 0 ? void 0 : _q.amount) === null || _r === void 0 ? void 0 : _r.currency) === null || _s === void 0 ? void 0 : _s.$eq;
132
+ const serviceOutputAmountCurrencyEq = (_r = (_q = (_p = params.serviceOutput) === null || _p === void 0 ? void 0 : _p.amount) === null || _q === void 0 ? void 0 : _q.currency) === null || _r === void 0 ? void 0 : _r.$eq;
132
133
  if (typeof serviceOutputAmountCurrencyEq === 'string') {
133
134
  andConditions.push({
134
135
  'serviceOutput.amount.currency': {
@@ -137,7 +138,7 @@ class ProductRepo {
137
138
  }
138
139
  });
139
140
  }
140
- const serviceTypeCodeValueEq = (_u = (_t = params.serviceType) === null || _t === void 0 ? void 0 : _t.codeValue) === null || _u === void 0 ? void 0 : _u.$eq;
141
+ const serviceTypeCodeValueEq = (_t = (_s = params.serviceType) === null || _s === void 0 ? void 0 : _s.codeValue) === null || _t === void 0 ? void 0 : _t.$eq;
141
142
  if (typeof serviceTypeCodeValueEq === 'string') {
142
143
  andConditions.push({
143
144
  'serviceType.codeValue': {
@@ -146,7 +147,7 @@ class ProductRepo {
146
147
  }
147
148
  });
148
149
  }
149
- const nameRegex = (_v = params.name) === null || _v === void 0 ? void 0 : _v.$regex;
150
+ const nameRegex = (_u = params.name) === null || _u === void 0 ? void 0 : _u.$regex;
150
151
  if (typeof nameRegex === 'string' && nameRegex.length > 0) {
151
152
  const nameRegexExp = new RegExp(nameRegex);
152
153
  andConditions.push({
@@ -156,7 +157,7 @@ class ProductRepo {
156
157
  ]
157
158
  });
158
159
  }
159
- const additionalPropertyElemMatchNameEq = (_w = params.additionalPropertyMatch) === null || _w === void 0 ? void 0 : _w.nameEq;
160
+ const additionalPropertyElemMatchNameEq = (_v = params.additionalPropertyMatch) === null || _v === void 0 ? void 0 : _v.nameEq;
160
161
  if (typeof additionalPropertyElemMatchNameEq === 'string') {
161
162
  andConditions.push({
162
163
  additionalProperty: {
@@ -0,0 +1,43 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ interface IOfferCatalogAsFindResult {
4
+ /**
5
+ * カタログID
6
+ */
7
+ id: string;
8
+ /**
9
+ * 対象オファー
10
+ */
11
+ aggregateElement: {
12
+ itemOffered: {
13
+ /**
14
+ * プロダクトID
15
+ */
16
+ id: string;
17
+ typeOf: factory.product.ProductType;
18
+ };
19
+ };
20
+ }
21
+ /**
22
+ * プロダクトオファーカタログリポジトリ
23
+ */
24
+ export declare class ProductHasOfferCatalogRepo {
25
+ private readonly productModel;
26
+ constructor(connection: Connection);
27
+ findOfferCatalogs(params: {
28
+ limit?: number;
29
+ page?: number;
30
+ project?: {
31
+ id?: {
32
+ $eq?: string;
33
+ };
34
+ };
35
+ product?: {
36
+ id?: {
37
+ $eq?: string;
38
+ $in?: string[];
39
+ };
40
+ };
41
+ }): Promise<IOfferCatalogAsFindResult[]>;
42
+ }
43
+ export {};