@chevre/domain 20.4.0-alpha.0 → 20.4.0-alpha.10

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 (51) hide show
  1. package/example/src/chevre/createManyEventsIfNotExist.ts +10 -10
  2. package/example/src/chevre/migrateMoneyTransferPendingTransactionIdentifier.ts +96 -0
  3. package/example/src/chevre/unsetUnnecessaryFields.ts +26 -0
  4. package/lib/chevre/repo/account.d.ts +4 -10
  5. package/lib/chevre/repo/account.js +72 -60
  6. package/lib/chevre/repo/accountTransaction.d.ts +0 -1
  7. package/lib/chevre/repo/accountTransaction.js +1 -1
  8. package/lib/chevre/repo/assetTransaction.d.ts +1 -0
  9. package/lib/chevre/repo/assetTransaction.js +5 -0
  10. package/lib/chevre/repo/comment.d.ts +31 -0
  11. package/lib/chevre/repo/comment.js +113 -0
  12. package/lib/chevre/repo/event.js +7 -1
  13. package/lib/chevre/repo/mongoose/model/{accountAction.d.ts → comments.d.ts} +2 -2
  14. package/lib/chevre/repo/mongoose/model/comments.js +82 -0
  15. package/lib/chevre/repo/mongoose/model/order.js +8 -2
  16. package/lib/chevre/repo/order.d.ts +6 -0
  17. package/lib/chevre/repo/order.js +58 -14
  18. package/lib/chevre/repo/serviceOutput.d.ts +4 -0
  19. package/lib/chevre/repo/serviceOutput.js +6 -0
  20. package/lib/chevre/repository.d.ts +6 -3
  21. package/lib/chevre/repository.js +8 -5
  22. package/lib/chevre/service/account.d.ts +0 -8
  23. package/lib/chevre/service/account.js +16 -37
  24. package/lib/chevre/service/accountTransaction/deposit.js +2 -5
  25. package/lib/chevre/service/accountTransaction/factory.js +36 -40
  26. package/lib/chevre/service/accountTransaction/transfer.js +4 -6
  27. package/lib/chevre/service/accountTransaction/withdraw.js +2 -5
  28. package/lib/chevre/service/accountTransaction.js +1 -1
  29. package/lib/chevre/service/assetTransaction/moneyTransfer.js +19 -11
  30. package/lib/chevre/service/assetTransaction/pay.js +17 -11
  31. package/lib/chevre/service/assetTransaction/registerService/factory.js +9 -4
  32. package/lib/chevre/service/delivery.js +12 -3
  33. package/lib/chevre/service/event.js +3 -23
  34. package/lib/chevre/service/moneyTransfer.d.ts +1 -1
  35. package/lib/chevre/service/moneyTransfer.js +8 -9
  36. package/lib/chevre/service/offer/moneyTransfer/authorize.js +0 -1
  37. package/lib/chevre/service/offer/moneyTransfer/returnMoneyTransfer.js +0 -1
  38. package/lib/chevre/service/payment/paymentCard.d.ts +6 -2
  39. package/lib/chevre/service/payment/paymentCard.js +16 -8
  40. package/lib/chevre/service/permit.d.ts +5 -1
  41. package/lib/chevre/service/permit.js +18 -11
  42. package/lib/chevre/service/transaction/moneyTransfer.js +0 -1
  43. package/lib/chevre/settings.d.ts +1 -0
  44. package/lib/chevre/settings.js +2 -2
  45. package/package.json +3 -3
  46. package/example/src/chevre/migrateAccountTitleAdditionalProperties.ts +0 -157
  47. package/example/src/chevre/migrateProjectSubscription.ts +0 -51
  48. package/example/src/chevre/migrateSection.ts +0 -105
  49. package/lib/chevre/repo/accountAction.d.ts +0 -42
  50. package/lib/chevre/repo/accountAction.js +0 -474
  51. package/lib/chevre/repo/mongoose/model/accountAction.js +0 -177
@@ -31,16 +31,16 @@ async function main() {
31
31
  .toDate(),
32
32
  endDate: moment('2023-02-01T06:00:00.000Z')
33
33
  .toDate(),
34
- workPerformed: {
35
- typeOf: chevre.factory.creativeWorkType.Movie,
36
- identifier: '1622100',
37
- id: '5bfb841d5a78d7948369980a',
38
- name: {
39
- en: 'Pet',
40
- ja: 'ペット'
41
- },
42
- duration: 'PT2H3M'
43
- },
34
+ // workPerformed: {
35
+ // typeOf: chevre.factory.creativeWorkType.Movie,
36
+ // identifier: '1622100',
37
+ // id: '5bfb841d5a78d7948369980a',
38
+ // name: {
39
+ // en: 'Pet',
40
+ // ja: 'ペット'
41
+ // },
42
+ // duration: 'PT2H3M'
43
+ // },
44
44
  location: {
45
45
  typeOf: chevre.factory.placeType.ScreeningRoom,
46
46
  branchCode: '10',
@@ -0,0 +1,96 @@
1
+ // tslint:disable:no-console
2
+ import * as moment from 'moment';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../lib/index';
6
+
7
+ const project = { id: String(process.env.PROJECT_ID) };
8
+
9
+ // tslint:disable-next-line:max-func-body-length
10
+ async function main() {
11
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
+
13
+ const accountTransactionRepo = new chevre.repository.AccountTransaction(mongoose.connection);
14
+ const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
15
+
16
+ const cursor = assetTransactionRepo.getCursor(
17
+ {
18
+ 'project.id': { $eq: project.id },
19
+ typeOf: { $eq: chevre.factory.assetTransactionType.MoneyTransfer },
20
+ startDate: {
21
+ $gte: moment('2023-02-17T15:00:00Z')
22
+ .toDate()
23
+ }
24
+ // _id: { $eq: 'al6aff83w' }
25
+ },
26
+ {
27
+ // _id: 1,
28
+ }
29
+ );
30
+ console.log('assetTransactions found');
31
+
32
+ let i = 0;
33
+ let updateCount = 0;
34
+ // tslint:disable-next-line:max-func-body-length
35
+ await cursor.eachAsync(async (doc) => {
36
+ i += 1;
37
+ const moneyTransferTransaction: chevre.factory.assetTransaction.moneyTransfer.ITransaction = doc.toObject();
38
+
39
+ const description = moneyTransferTransaction.object.description;
40
+ if (description !== '鑑賞' && description !== '受け取り') {
41
+ console.log(
42
+ 'no operation needed',
43
+ description,
44
+ moneyTransferTransaction.project.id,
45
+ moneyTransferTransaction.transactionNumber,
46
+ moneyTransferTransaction.startDate
47
+ );
48
+ } else {
49
+ const pendingTransactionIdentifier = moneyTransferTransaction.object.pendingTransaction?.identifier;
50
+ if (typeof pendingTransactionIdentifier === 'string' && pendingTransactionIdentifier.length > 0) {
51
+ console.log(
52
+ 'pendingTransactionIdentifier found',
53
+ description,
54
+ moneyTransferTransaction.project.id,
55
+ moneyTransferTransaction.transactionNumber,
56
+ moneyTransferTransaction.startDate
57
+ );
58
+ } else {
59
+ // 口座取引からidentifierを取得
60
+ const accountTransaction =
61
+ await accountTransactionRepo.findByTransactionNumber({ transactionNumber: moneyTransferTransaction.transactionNumber });
62
+ console.log(
63
+ 'updating identifier...',
64
+ accountTransaction.identifier,
65
+ description,
66
+ moneyTransferTransaction.project.id,
67
+ moneyTransferTransaction.transactionNumber,
68
+ moneyTransferTransaction.startDate
69
+ );
70
+ if (typeof accountTransaction.identifier === 'string') {
71
+ await assetTransactionRepo.findByIdAndUpdate({
72
+ id: moneyTransferTransaction.id,
73
+ update: {
74
+ 'object.pendingTransaction.identifier': accountTransaction.identifier
75
+ }
76
+ });
77
+ }
78
+ console.log(
79
+ 'ientifier updated',
80
+ accountTransaction.identifier,
81
+ description,
82
+ moneyTransferTransaction.project.id,
83
+ moneyTransferTransaction.transactionNumber,
84
+ moneyTransferTransaction.startDate
85
+ );
86
+ updateCount += 1;
87
+ }
88
+ }
89
+ });
90
+ console.log(i, 'assetTransactions checked');
91
+ console.log(updateCount, 'assetTransactions updated');
92
+ }
93
+
94
+ main()
95
+ .then()
96
+ .catch(console.error);
@@ -0,0 +1,26 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../lib/index';
5
+
6
+ async function main() {
7
+ await mongoose.connect(<string>process.env.MONGOLAB_URI);
8
+
9
+ const accountRepo = new chevre.repository.Account(mongoose.connection);
10
+ const permitRepo = new chevre.repository.ServiceOutput(mongoose.connection);
11
+
12
+ let updateResult = await accountRepo.unsetUnnecessaryFields({
13
+ filter: { status: { $exists: true } },
14
+ $unset: { status: 1 }
15
+ });
16
+ console.log('accounts unset.', updateResult);
17
+ updateResult = await permitRepo.unsetUnnecessaryFields({
18
+ filter: { 'paymentAccount.accountType': { $exists: true } },
19
+ $unset: { 'paymentAccount.accountType': 1 }
20
+ });
21
+ console.log('permits unset', updateResult);
22
+ }
23
+
24
+ main()
25
+ .then()
26
+ .catch(console.error);
@@ -45,16 +45,6 @@ export declare class MongoRepository {
45
45
  /**
46
46
  * 口座を解約する
47
47
  */
48
- close(params: {
49
- /**
50
- * 口座番号
51
- */
52
- accountNumber: string;
53
- /**
54
- * 解約日時
55
- */
56
- closeDate: Date;
57
- }): Promise<void>;
58
48
  /**
59
49
  * 口座番号で検索する
60
50
  */
@@ -134,4 +124,8 @@ export declare class MongoRepository {
134
124
  * 口座を検索する
135
125
  */
136
126
  search(params: factory.account.ISearchConditions): Promise<factory.account.IAccount[]>;
127
+ unsetUnnecessaryFields(params: {
128
+ filter: any;
129
+ $unset: any;
130
+ }): Promise<import("mongoose").UpdateWriteOpResult>;
137
131
  }
@@ -10,11 +10,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MongoRepository = exports.modelName = void 0;
13
- const createDebug = require("debug");
14
13
  const account_1 = require("./mongoose/model/account");
15
14
  Object.defineProperty(exports, "modelName", { enumerable: true, get: function () { return account_1.modelName; } });
16
15
  const factory = require("../factory");
17
- const debug = createDebug('chevre-domain:repository');
18
16
  /**
19
17
  * 口座リポジトリ
20
18
  */
@@ -93,11 +91,11 @@ class MongoRepository {
93
91
  }
94
92
  // tslint:disable-next-line:no-single-line-block-comment
95
93
  /* istanbul ignore else */
96
- if (Array.isArray(params.statuses) && params.statuses.length > 0) {
97
- andConditions.push({
98
- status: { $in: params.statuses }
99
- });
100
- }
94
+ // if (Array.isArray(params.statuses) && params.statuses.length > 0) {
95
+ // andConditions.push({
96
+ // status: { $in: params.statuses }
97
+ // });
98
+ // }
101
99
  const nameRegex = (_d = params.name) === null || _d === void 0 ? void 0 : _d.$regex;
102
100
  // tslint:disable-next-line:no-single-line-block-comment
103
101
  /* istanbul ignore else */
@@ -159,8 +157,8 @@ class MongoRepository {
159
157
  balance: p.initialBalance,
160
158
  availableBalance: p.initialBalance,
161
159
  pendingTransactions: [],
162
- openDate: p.openDate,
163
- status: factory.account.AccountStatusType.Opened
160
+ openDate: p.openDate
161
+ // status: factory.account.AccountStatusType.Opened
164
162
  };
165
163
  });
166
164
  // const doc = await this.accountModel.create(account);
@@ -179,39 +177,47 @@ class MongoRepository {
179
177
  /**
180
178
  * 口座を解約する
181
179
  */
182
- close(params) {
183
- return __awaiter(this, void 0, void 0, function* () {
184
- debug('closing account...');
185
- const doc = yield this.accountModel.findOneAndUpdate({
186
- accountNumber: params.accountNumber,
187
- pendingTransactions: { $size: 0 },
188
- status: factory.account.AccountStatusType.Opened
189
- }, {
190
- closeDate: params.closeDate,
191
- status: factory.account.AccountStatusType.Closed
192
- }, {
193
- new: true
194
- })
195
- .exec();
196
- // NotFoundであれば口座状態確認
197
- if (doc === null) {
198
- const account = yield this.findByAccountNumber({
199
- accountNumber: params.accountNumber
200
- });
201
- if (account.status === factory.account.AccountStatusType.Closed) {
202
- // すでに口座解約済の場合
203
- return;
204
- }
205
- else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
206
- // 進行中取引が存在する場合の場合
207
- throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
208
- }
209
- else {
210
- throw new factory.errors.NotFound(this.accountModel.modelName);
211
- }
212
- }
213
- });
214
- }
180
+ // public async close(params: {
181
+ // /**
182
+ // * 口座番号
183
+ // */
184
+ // accountNumber: string;
185
+ // /**
186
+ // * 解約日時
187
+ // */
188
+ // closeDate: Date;
189
+ // }) {
190
+ // const doc = await this.accountModel.findOneAndUpdate(
191
+ // {
192
+ // accountNumber: params.accountNumber,
193
+ // pendingTransactions: { $size: 0 },
194
+ // status: factory.account.AccountStatusType.Opened
195
+ // },
196
+ // {
197
+ // closeDate: params.closeDate,
198
+ // status: factory.account.AccountStatusType.Closed
199
+ // },
200
+ // {
201
+ // new: true
202
+ // }
203
+ // )
204
+ // .exec();
205
+ // // NotFoundであれば口座状態確認
206
+ // if (doc === null) {
207
+ // const account = await this.findByAccountNumber({
208
+ // accountNumber: params.accountNumber
209
+ // });
210
+ // if (account.status === factory.account.AccountStatusType.Closed) {
211
+ // // すでに口座解約済の場合
212
+ // return;
213
+ // } else if (Array.isArray(account.pendingTransactions) && account.pendingTransactions.length > 0) {
214
+ // // 進行中取引が存在する場合の場合
215
+ // throw new factory.errors.Argument('accountNumber', 'Pending transactions exist');
216
+ // } else {
217
+ // throw new factory.errors.NotFound(this.accountModel.modelName);
218
+ // }
219
+ // }
220
+ // }
215
221
  /**
216
222
  * 口座番号で検索する
217
223
  */
@@ -233,7 +239,7 @@ class MongoRepository {
233
239
  */
234
240
  authorizeAmount(params) {
235
241
  return __awaiter(this, void 0, void 0, function* () {
236
- const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber, status: factory.account.AccountStatusType.Opened }, (params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
242
+ const doc = yield this.accountModel.findOneAndUpdate(Object.assign({ accountNumber: params.accountNumber }, (params.force === true) ? undefined : { availableBalance: { $gte: params.amount } } // 利用可能金額確認
237
243
  ), {
238
244
  $inc: { availableBalance: -params.amount },
239
245
  $push: { pendingTransactions: params.transaction } // 進行中取引追加
@@ -244,11 +250,11 @@ class MongoRepository {
244
250
  const account = yield this.findByAccountNumber({
245
251
  accountNumber: params.accountNumber
246
252
  });
247
- if (account.status === factory.account.AccountStatusType.Closed) {
248
- // 口座解約済の場合
249
- throw new factory.errors.Argument('accountNumber', 'Account already closed');
250
- }
251
- else if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
253
+ // if (account.status === factory.account.AccountStatusType.Closed) {
254
+ // // 口座解約済の場合
255
+ // throw new factory.errors.Argument('accountNumber', 'Account already closed');
256
+ // } else
257
+ if (typeof account.availableBalance === 'number' && account.availableBalance < params.amount) {
252
258
  // 残高不足の場合
253
259
  throw new factory.errors.Argument('accountNumber', 'Insufficient balance');
254
260
  }
@@ -264,22 +270,22 @@ class MongoRepository {
264
270
  startTransaction(params) {
265
271
  return __awaiter(this, void 0, void 0, function* () {
266
272
  const doc = yield this.accountModel.findOneAndUpdate({
267
- accountNumber: params.accountNumber,
268
- status: factory.account.AccountStatusType.Opened // 開いている口座
273
+ accountNumber: params.accountNumber
274
+ // status: factory.account.AccountStatusType.Opened // 開いている口座
269
275
  }, { $push: { pendingTransactions: params.transaction } })
270
276
  .exec();
271
277
  // NotFoundであれば口座状態確認
272
278
  if (doc === null) {
273
- const account = yield this.findByAccountNumber({
274
- accountNumber: params.accountNumber
275
- });
276
- if (account.status === factory.account.AccountStatusType.Closed) {
277
- // 口座解約済の場合
278
- throw new factory.errors.Argument('accountNumber', 'Account already closed');
279
- }
280
- else {
281
- throw new factory.errors.NotFound(this.accountModel.modelName);
282
- }
279
+ // const account = await this.findByAccountNumber({
280
+ // accountNumber: params.accountNumber
281
+ // });
282
+ // if (account.status === factory.account.AccountStatusType.Closed) {
283
+ // // 口座解約済の場合
284
+ // throw new factory.errors.Argument('accountNumber', 'Account already closed');
285
+ // } else {
286
+ // throw new factory.errors.NotFound(this.accountModel.modelName);
287
+ // }
288
+ throw new factory.errors.NotFound(this.accountModel.modelName);
283
289
  }
284
290
  });
285
291
  }
@@ -419,5 +425,11 @@ class MongoRepository {
419
425
  .then((docs) => docs.map((doc) => doc.toObject()));
420
426
  });
421
427
  }
428
+ unsetUnnecessaryFields(params) {
429
+ return __awaiter(this, void 0, void 0, function* () {
430
+ return this.accountModel.updateMany(params.filter, { $unset: params.$unset })
431
+ .exec();
432
+ });
433
+ }
422
434
  }
423
435
  exports.MongoRepository = MongoRepository;
@@ -34,7 +34,6 @@ export declare class MongoRepository {
34
34
  confirm<T extends factory.account.transactionType>(params: {
35
35
  typeOf?: T;
36
36
  id: string;
37
- result: factory.account.transaction.IResult;
38
37
  potentialActions: factory.account.transaction.IPotentialActions;
39
38
  }): Promise<factory.account.transaction.ITransaction<T>>;
40
39
  /**
@@ -154,7 +154,7 @@ class MongoRepository {
154
154
  const doc = yield this.transactionModel.findOneAndUpdate(Object.assign({ _id: params.id, status: factory.transactionStatusType.InProgress }, (typeof params.typeOf === 'string') ? { typeOf: params.typeOf } : undefined), {
155
155
  status: factory.transactionStatusType.Confirmed,
156
156
  endDate: new Date(),
157
- result: params.result,
157
+ // result: params.result, // resultを更新
158
158
  potentialActions: params.potentialActions
159
159
  }, { new: true })
160
160
  .exec();
@@ -144,6 +144,7 @@ export declare class MongoRepository {
144
144
  findByIdAndDelete(params: {
145
145
  id: string;
146
146
  }): Promise<void>;
147
+ getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
147
148
  aggregateAssetTransaction(params: {
148
149
  project?: {
149
150
  id?: {
@@ -536,6 +536,11 @@ class MongoRepository {
536
536
  .exec();
537
537
  });
538
538
  }
539
+ getCursor(conditions, projection) {
540
+ return this.transactionModel.find(conditions, projection)
541
+ .sort({ startDate: factory.sortType.Ascending })
542
+ .cursor();
543
+ }
539
544
  aggregateAssetTransaction(params) {
540
545
  return __awaiter(this, void 0, void 0, function* () {
541
546
  const statuses = yield Promise.all([
@@ -0,0 +1,31 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ /**
4
+ * コメントリポジトリ
5
+ */
6
+ export declare class MongoRepository {
7
+ private readonly commentModel;
8
+ constructor(connection: Connection);
9
+ static CREATE_MONGO_CONDITIONS(params: factory.creativeWork.comment.ISearchConditions): any[];
10
+ /**
11
+ * 検索
12
+ */
13
+ search(params: factory.creativeWork.comment.ISearchConditions): Promise<factory.creativeWork.comment.IComment[]>;
14
+ findById(params: {
15
+ id: string;
16
+ }): Promise<factory.creativeWork.comment.IComment>;
17
+ create(params: factory.creativeWork.comment.IComment): Promise<factory.creativeWork.comment.IComment>;
18
+ updateById(params: {
19
+ id?: string;
20
+ attributes: {
21
+ text: string;
22
+ };
23
+ }): Promise<void>;
24
+ /**
25
+ * 削除する
26
+ */
27
+ deleteById(params: {
28
+ id: string;
29
+ }): Promise<void>;
30
+ getCursor(conditions: any, projection: any): import("mongoose").QueryCursor<any>;
31
+ }
@@ -0,0 +1,113 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MongoRepository = void 0;
13
+ const comments_1 = require("./mongoose/model/comments");
14
+ const factory = require("../factory");
15
+ /**
16
+ * コメントリポジトリ
17
+ */
18
+ class MongoRepository {
19
+ constructor(connection) {
20
+ this.commentModel = connection.model(comments_1.modelName);
21
+ }
22
+ static CREATE_MONGO_CONDITIONS(params) {
23
+ var _a, _b, _c, _d, _e, _f;
24
+ const andConditions = [];
25
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
26
+ if (typeof projectIdEq === 'string') {
27
+ andConditions.push({ 'project.id': { $eq: projectIdEq } });
28
+ }
29
+ const aboutIdEq = (_d = (_c = params.about) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
30
+ if (typeof aboutIdEq === 'string') {
31
+ andConditions.push({ 'about.id': { $exists: true, $eq: aboutIdEq } });
32
+ }
33
+ const aboutIdIn = (_f = (_e = params.about) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$in;
34
+ if (Array.isArray(aboutIdIn)) {
35
+ andConditions.push({ 'about.id': { $exists: true, $in: aboutIdIn } });
36
+ }
37
+ return andConditions;
38
+ }
39
+ /**
40
+ * 検索
41
+ */
42
+ search(params) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
45
+ const query = this.commentModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
46
+ __v: 0,
47
+ createdAt: 0,
48
+ updatedAt: 0
49
+ });
50
+ if (typeof params.limit === 'number') {
51
+ const page = (typeof params.page === 'number') ? params.page : 1;
52
+ query.limit(params.limit)
53
+ .skip(params.limit * (page - 1));
54
+ }
55
+ // tslint:disable-next-line:no-single-line-block-comment
56
+ /* istanbul ignore else */
57
+ if (params.sort !== undefined) {
58
+ query.sort(params.sort);
59
+ }
60
+ return query.setOptions({ maxTimeMS: 10000 })
61
+ .exec()
62
+ .then((docs) => docs.map((doc) => doc.toObject()));
63
+ });
64
+ }
65
+ findById(params) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const doc = yield this.commentModel.findOne({ _id: params.id }, {
68
+ __v: 0,
69
+ createdAt: 0,
70
+ updatedAt: 0
71
+ })
72
+ .exec();
73
+ if (doc === null) {
74
+ throw new factory.errors.NotFound(this.commentModel.modelName);
75
+ }
76
+ return doc.toObject();
77
+ });
78
+ }
79
+ create(params) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const creatingDoc = Object.assign({ about: params.about, author: params.author, dateCreated: new Date(), project: params.project, text: params.text, typeOf: factory.creativeWorkType.Comment }, (Array.isArray(params.additionalProperty)) ? { additionalProperty: params.additionalProperty } : undefined);
82
+ const doc = yield this.commentModel.create(creatingDoc);
83
+ return doc.toObject();
84
+ });
85
+ }
86
+ updateById(params) {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ const updateFields = {
89
+ $set: Object.assign({ dateModified: new Date() }, (typeof params.attributes.text === 'string') ? { text: params.attributes.text } : undefined)
90
+ };
91
+ const doc = yield this.commentModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
92
+ .exec();
93
+ if (doc === null) {
94
+ throw new factory.errors.NotFound(this.commentModel.modelName);
95
+ }
96
+ });
97
+ }
98
+ /**
99
+ * 削除する
100
+ */
101
+ deleteById(params) {
102
+ return __awaiter(this, void 0, void 0, function* () {
103
+ yield this.commentModel.findOneAndRemove({ _id: params.id })
104
+ .exec();
105
+ });
106
+ }
107
+ getCursor(conditions, projection) {
108
+ return this.commentModel.find(conditions, projection)
109
+ .sort({ codeValue: factory.sortType.Ascending })
110
+ .cursor();
111
+ }
112
+ }
113
+ exports.MongoRepository = MongoRepository;
@@ -466,10 +466,14 @@ class MongoRepository {
466
466
  if (Array.isArray(params)) {
467
467
  params.forEach((creatingEventParams) => {
468
468
  var _a, _b;
469
+ if (creatingEventParams.attributes.typeOf !== factory.eventType.ScreeningEvent) {
470
+ throw new factory.errors.NotImplemented(`${factory.eventType.ScreeningEventSeries} not implemented`);
471
+ }
469
472
  const additionalPropertyValue = (_b = (_a = creatingEventParams.attributes.additionalProperty) === null || _a === void 0 ? void 0 : _a.find((property) => property.name === creatingEventParams.filter.name)) === null || _b === void 0 ? void 0 : _b.value;
470
473
  if (typeof additionalPropertyValue !== 'string') {
471
474
  throw new factory.errors.NotFound('additionalProperty.value');
472
475
  }
476
+ const _c = creatingEventParams.attributes, { eventStatus } = _c, setOnInsertFields = __rest(_c, ["eventStatus"]);
473
477
  bulkWriteOps.push({
474
478
  updateOne: {
475
479
  filter: {
@@ -481,7 +485,9 @@ class MongoRepository {
481
485
  }
482
486
  },
483
487
  update: {
484
- $setOnInsert: Object.assign({ _id: uniqid() }, creatingEventParams.attributes)
488
+ $setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { _id: uniqid() }),
489
+ // 変更可能な属性のみ上書き
490
+ $set: { eventStatus }
485
491
  },
486
492
  upsert: true
487
493
  }
@@ -1,7 +1,7 @@
1
1
  import * as mongoose from 'mongoose';
2
- declare const modelName = "AccountAction";
2
+ declare const modelName = "Comment";
3
3
  /**
4
- * アクションスキーマ
4
+ * コメントスキーマ
5
5
  */
6
6
  declare const schema: mongoose.Schema<mongoose.Document<any, any, any>, mongoose.Model<mongoose.Document<any, any, any>, any, any>, undefined, {}>;
7
7
  export { modelName, schema };