@chevre/domain 21.13.0-alpha.7 → 21.13.0-alpha.9

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 (43) hide show
  1. package/lib/chevre/repo/creativeWork.d.ts +7 -1
  2. package/lib/chevre/repo/creativeWork.js +36 -8
  3. package/lib/chevre/repo/event.d.ts +4 -4
  4. package/lib/chevre/repo/reservation.d.ts +2 -2
  5. package/lib/chevre/service/event.d.ts +3 -0
  6. package/lib/chevre/service/event.js +24 -3
  7. package/lib/chevre/service/task/importEventsFromCOA.js +2 -0
  8. package/lib/chevre/settings.d.ts +0 -1
  9. package/lib/chevre/settings.js +1 -5
  10. package/package.json +2 -2
  11. package/example/src/chevre/assetTransaction/searchGMOTrade.ts +0 -27
  12. package/example/src/chevre/countDelayedTasks.ts +0 -22
  13. package/example/src/chevre/countDelayedTransactions.ts +0 -60
  14. package/example/src/chevre/countMoneyTransferTransaction.ts +0 -36
  15. package/example/src/chevre/countOffers.ts +0 -32
  16. package/example/src/chevre/createDeleteTransactionTasks.ts +0 -108
  17. package/example/src/chevre/createDeleteTransactionTasksIfNotExist.ts +0 -98
  18. package/example/src/chevre/createDeleteTransactionTasksOfDeletedPeople.ts +0 -126
  19. package/example/src/chevre/createManyEventsIfNotExist.ts +0 -365
  20. package/example/src/chevre/iam/searchMemberOfIdsByMemberId.ts +0 -31
  21. package/example/src/chevre/iam/searchProjectIdsByMemberId.ts +0 -32
  22. package/example/src/chevre/offer/searchAllByIdsAndOfferCatalogId.ts +0 -34
  23. package/example/src/chevre/offer/searchEventTicketOffers.ts +0 -54
  24. package/example/src/chevre/offer/searchOffersByCatalog.ts +0 -40
  25. package/example/src/chevre/processPay.ts +0 -90
  26. package/example/src/chevre/processRegisterMembership.ts +0 -110
  27. package/example/src/chevre/processRegisterPaymentCard.ts +0 -98
  28. package/example/src/chevre/processReserve.ts +0 -114
  29. package/example/src/chevre/publishConfirmationNumber.ts +0 -27
  30. package/example/src/chevre/publishPermitOwnershipInfoToken.ts +0 -56
  31. package/example/src/chevre/reIndex.ts +0 -25
  32. package/example/src/chevre/redisConfig.ts +0 -32
  33. package/example/src/chevre/saveTasks.ts +0 -41
  34. package/example/src/chevre/searchAbortedTasks.ts +0 -34
  35. package/example/src/chevre/searchAcceptedOfferIds.ts +0 -23
  36. package/example/src/chevre/searchOffersFromAggregateOffer.ts +0 -168
  37. package/example/src/chevre/searchOrdersWithUnwoundOffers.ts +0 -35
  38. package/example/src/chevre/searchReservationNumbersByOrderNumbers.ts +0 -58
  39. package/example/src/chevre/task/executeTasks.ts +0 -26
  40. package/example/src/chevre/unsetContainsInPlaceFromMovieTheater.ts +0 -41
  41. package/example/src/chevre/updateOfferCatalogs.ts +0 -40
  42. package/example/src/chevre/updateTransaction.ts +0 -38
  43. package/example/src/playOnMoment.ts +0 -24
@@ -22,6 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
+ import type { BulkWriteResult } from 'mongodb';
25
26
  import type { Connection } from 'mongoose';
26
27
  import * as factory from '../factory';
27
28
  /**
@@ -35,10 +36,15 @@ export declare class MongoRepository {
35
36
  * コンテンツを保管する
36
37
  */
37
38
  saveMovie(params: factory.creativeWork.movie.ICreativeWork): Promise<any>;
39
+ /**
40
+ * コードをキーにして冪等作成
41
+ */
42
+ upsertMoviesByIdentifier(params: {
43
+ attributes: factory.creativeWork.movie.ICreativeWork;
44
+ }[]): Promise<BulkWriteResult | void>;
38
45
  findMovieById(params: {
39
46
  id: string;
40
47
  }): Promise<factory.creativeWork.movie.ICreativeWork>;
41
- countMovies(params: factory.creativeWork.movie.ISearchConditions): Promise<number>;
42
48
  /**
43
49
  * コンテンツを検索する
44
50
  */
@@ -180,6 +180,42 @@ class MongoRepository {
180
180
  return doc.toObject();
181
181
  });
182
182
  }
183
+ /**
184
+ * コードをキーにして冪等作成
185
+ */
186
+ upsertMoviesByIdentifier(params) {
187
+ return __awaiter(this, void 0, void 0, function* () {
188
+ const bulkWriteOps = [];
189
+ if (Array.isArray(params)) {
190
+ params.forEach((creatingMovieParams) => {
191
+ const _a = creatingMovieParams.attributes, { typeOf, project, identifier, duration, name, additionalProperty, contentRating, headline, distributor, thumbnailUrl, datePublished } = _a, setOnInsertFields = __rest(_a, ["typeOf", "project", "identifier", "duration", "name", "additionalProperty", "contentRating", "headline", "distributor", "thumbnailUrl", "datePublished"]);
192
+ if (typeof identifier !== 'string' || identifier.length === 0) {
193
+ throw new factory.errors.ArgumentNull('identifier');
194
+ }
195
+ bulkWriteOps.push({
196
+ updateOne: {
197
+ filter: {
198
+ typeOf: typeOf,
199
+ 'project.id': { $eq: project.id },
200
+ identifier: { $eq: identifier }
201
+ },
202
+ update: {
203
+ $setOnInsert: Object.assign(Object.assign({}, setOnInsertFields), { typeOf,
204
+ project,
205
+ identifier }),
206
+ // 変更可能な属性のみ上書き
207
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (name !== undefined) ? { name } : undefined), (contentRating !== undefined) ? { contentRating } : undefined), (duration !== undefined) ? { duration } : undefined), (headline !== undefined) ? { headline } : undefined), (datePublished !== undefined) ? { datePublished } : undefined), (distributor !== undefined) ? { distributor } : undefined), (typeof thumbnailUrl === 'string') ? { thumbnailUrl } : undefined), (Array.isArray(additionalProperty)) ? { additionalProperty } : []),
208
+ upsert: true
209
+ }
210
+ }
211
+ });
212
+ });
213
+ }
214
+ if (bulkWriteOps.length > 0) {
215
+ return this.creativeWorkModel.bulkWrite(bulkWriteOps, { ordered: false });
216
+ }
217
+ });
218
+ }
183
219
  findMovieById(params) {
184
220
  return __awaiter(this, void 0, void 0, function* () {
185
221
  const doc = yield this.creativeWorkModel.findOne({ _id: params.id }, {
@@ -194,14 +230,6 @@ class MongoRepository {
194
230
  return doc.toObject();
195
231
  });
196
232
  }
197
- countMovies(params) {
198
- return __awaiter(this, void 0, void 0, function* () {
199
- const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
200
- return this.creativeWorkModel.countDocuments({ $and: conditions })
201
- .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
202
- .exec();
203
- });
204
- }
205
233
  /**
206
234
  * コンテンツを検索する
207
235
  */
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import type { BulkWriteResult as BulkWriteOpResultObject } from 'mongodb';
25
+ import type { BulkWriteResult } from 'mongodb';
26
26
  import type { Connection } from 'mongoose';
27
27
  import * as factory from '../factory';
28
28
  import * as EventFactory from '../factory/event';
@@ -106,7 +106,7 @@ export declare class MongoRepository {
106
106
  name: string;
107
107
  };
108
108
  }[]): Promise<{
109
- bulkWriteResult: BulkWriteOpResultObject;
109
+ bulkWriteResult: BulkWriteResult;
110
110
  modifiedEvents: {
111
111
  id: string;
112
112
  }[];
@@ -116,7 +116,7 @@ export declare class MongoRepository {
116
116
  */
117
117
  createScreeningEventSeriesIfNotExistByWorkPerformed(params: {
118
118
  attributes: factory.event.IAttributes<factory.eventType.ScreeningEventSeries>;
119
- }[]): Promise<BulkWriteOpResultObject | void>;
119
+ }[]): Promise<BulkWriteResult | void>;
120
120
  /**
121
121
  * イベント部分更新
122
122
  */
@@ -275,7 +275,7 @@ export declare class MongoRepository {
275
275
  updateAggregationById<T extends factory.eventType>(params: {
276
276
  id: string;
277
277
  }, update: IUpdateAggregateReservationParams | IUpdateAggregateUseActionsParams): Promise<factory.event.IEvent<T>>;
278
- bulkWrite(bulkWriteOps: any[]): Promise<BulkWriteOpResultObject & {
278
+ bulkWrite(bulkWriteOps: any[]): Promise<BulkWriteResult & {
279
279
  mongoose?: {
280
280
  validationErrors: import("mongoose").Error[];
281
281
  } | undefined;
@@ -22,7 +22,7 @@
22
22
  /// <reference types="mongoose/types/validation" />
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
- import { BulkWriteResult as BulkWriteOpResultObject } from 'mongodb';
25
+ import type { BulkWriteResult } from 'mongodb';
26
26
  import type { Connection, UpdateWriteOpResult } from 'mongoose';
27
27
  import * as factory from '../factory';
28
28
  export interface IUpdatePartiallyParams {
@@ -63,7 +63,7 @@ export declare class MongoRepository {
63
63
  reservationFor: factory.assetTransaction.reserve.IReservationFor;
64
64
  underName?: factory.reservation.IUnderName<factory.reservationType.EventReservation>;
65
65
  broker?: factory.reservation.IBroker<factory.reservationType>;
66
- }): Promise<BulkWriteOpResultObject | void>;
66
+ }): Promise<BulkWriteResult | void>;
67
67
  /**
68
68
  * 予約取消
69
69
  */
@@ -1,5 +1,6 @@
1
1
  import type { MongoRepository as ActionRepo } from '../repo/action';
2
2
  import type { MongoRepository as CategoryCodeRepo } from '../repo/categoryCode';
3
+ import type { MongoRepository as CreativeWorkRepo } from '../repo/creativeWork';
3
4
  import type { MongoRepository as EventRepo } from '../repo/event';
4
5
  import type { MongoRepository as PlaceRepo } from '../repo/place';
5
6
  import type { MongoRepository as ProjectRepo } from '../repo/project';
@@ -32,9 +33,11 @@ export declare function importFromCOA(params: {
32
33
  * 施設コンテンツを保管するかどうか
33
34
  */
34
35
  saveScreeningEventSeries: boolean;
36
+ saveScreeningEventSeriesPeriodInMonth: number;
35
37
  }): (repos: {
36
38
  action: ActionRepo;
37
39
  categoryCode: CategoryCodeRepo;
40
+ creativeWork: CreativeWorkRepo;
38
41
  event: EventRepo;
39
42
  place: PlaceRepo;
40
43
  seller: SellerRepo;
@@ -24,7 +24,6 @@ const factory = require("../factory");
24
24
  const createEvent_1 = require("./event/createEvent");
25
25
  Object.defineProperty(exports, "createEvent", { enumerable: true, get: function () { return createEvent_1.createEvent; } });
26
26
  const offer_1 = require("./offer");
27
- const settings_1 = require("../settings");
28
27
  const debug = createDebug('chevre-domain:service:event');
29
28
  const coaAuthClient = new COA.auth.RefreshToken({
30
29
  endpoint: credentials_1.credentials.coa.endpoint,
@@ -139,6 +138,7 @@ function importFromCOA(params) {
139
138
  movieTheater,
140
139
  project: project,
141
140
  saveScreeningEventSeries: params.saveScreeningEventSeries,
141
+ saveScreeningEventSeriesPeriodInMonth: params.saveScreeningEventSeriesPeriodInMonth,
142
142
  seller: { id: seller.id }
143
143
  })(repos);
144
144
  savedScreeningEventSeriesCount = savedEventsCount;
@@ -200,6 +200,7 @@ function importFromCOA(params) {
200
200
  }
201
201
  exports.importFromCOA = importFromCOA;
202
202
  function saveScreeningEventSeries(params) {
203
+ // tslint:disable-next-line:max-func-body-length
203
204
  return (repos) => __awaiter(this, void 0, void 0, function* () {
204
205
  const project = params.project;
205
206
  const masterService = new COA.service.Master({
@@ -245,13 +246,16 @@ function saveScreeningEventSeries(params) {
245
246
  seller: params.seller
246
247
  });
247
248
  });
249
+ const COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH = (typeof params.saveScreeningEventSeriesPeriodInMonth === 'number')
250
+ ? params.saveScreeningEventSeriesPeriodInMonth
251
+ // tslint:disable-next-line:no-magic-numbers
252
+ : 3;
248
253
  let savedEventsCount = 0;
249
254
  // saveScreeningEventSeries:trueの場合のみ保管(2022-10-10~)
250
255
  if (params.saveScreeningEventSeries === true) {
251
256
  // 更新対象が無限に増えるのを防ぐためにstartDateでフィルター
252
257
  const someMonthsAgo = moment()
253
- // tslint:disable-next-line:no-magic-numbers
254
- .add(-settings_1.COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH, 'months'); // to settings(2023-10-18~)
258
+ .add(-COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH, 'months');
255
259
  const saveParams = screeningEventSerieses
256
260
  .filter((screeningEventSeries) => {
257
261
  return moment(screeningEventSeries.startDate)
@@ -268,6 +272,23 @@ function saveScreeningEventSeries(params) {
268
272
  yield repos.event.saveMany(saveParams);
269
273
  debug('saved', saveParams.length, 'ScreeningEventSeries');
270
274
  savedEventsCount = saveParams.length;
275
+ // コンテンツ永続化(2023-10-23~)
276
+ try {
277
+ yield repos.creativeWork.upsertMoviesByIdentifier(saveParams.map((saveScreeningEventSeriesParams) => {
278
+ var _a;
279
+ return {
280
+ attributes: Object.assign(Object.assign({ typeOf: factory.creativeWorkType.Movie, project: params.project, identifier: saveScreeningEventSeriesParams.attributes.workPerformed.identifier, name: { ja: (_a = saveScreeningEventSeriesParams.attributes.workPerformed.name) === null || _a === void 0 ? void 0 : _a.ja }, offers: { typeOf: factory.offerType.Offer } }, (typeof saveScreeningEventSeriesParams.attributes.workPerformed.contentRating === 'string')
281
+ ? { contentRating: saveScreeningEventSeriesParams.attributes.workPerformed.contentRating }
282
+ : undefined), (typeof saveScreeningEventSeriesParams.attributes.workPerformed.duration === 'string')
283
+ ? { duration: saveScreeningEventSeriesParams.attributes.workPerformed.duration }
284
+ : undefined)
285
+ };
286
+ }));
287
+ }
288
+ catch (error) {
289
+ // tslint:disable-next-line:no-console
290
+ console.error('failed in upsertMoviesByIdentifier', error);
291
+ }
271
292
  }
272
293
  return { screeningEventSerieses, savedEventsCount };
273
294
  });
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.call = void 0;
13
13
  const action_1 = require("../../repo/action");
14
14
  const categoryCode_1 = require("../../repo/categoryCode");
15
+ const creativeWork_1 = require("../../repo/creativeWork");
15
16
  const event_1 = require("../../repo/event");
16
17
  const place_1 = require("../../repo/place");
17
18
  const seller_1 = require("../../repo/seller");
@@ -24,6 +25,7 @@ function call(data) {
24
25
  yield EventService.importFromCOA(data)({
25
26
  action: new action_1.MongoRepository(settings.connection),
26
27
  categoryCode: new categoryCode_1.MongoRepository(settings.connection),
28
+ creativeWork: new creativeWork_1.MongoRepository(settings.connection),
27
29
  event: new event_1.MongoRepository(settings.connection),
28
30
  place: new place_1.MongoRepository(settings.connection),
29
31
  seller: new seller_1.MongoRepository(settings.connection)
@@ -45,7 +45,6 @@ export declare const USE_OPTIMIZE_TICKET_OFFER: boolean;
45
45
  export declare const MONGO_MAX_TIME_MS: number;
46
46
  export declare const MONGO_READ_PREFERENCE: string;
47
47
  export declare const MONGO_AUTO_INDEX: boolean;
48
- export declare const COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH: number;
49
48
  /**
50
49
  * グローバル設定
51
50
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.settings = exports.COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_OPTIMIZE_TICKET_OFFER = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
3
+ exports.settings = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = exports.USE_OPTIMIZE_TICKET_OFFER = exports.USE_AUTHORIZE_PAYMENT_RESULT_AS_ARRAY = exports.USE_ORDER_PAYMENT_DUE_ON_PLACED = exports.USE_DELETE_EVENT_BY_ORDER = exports.USE_OBJECT_AS_PAY_TRANSACTION_AMOUNT = exports.USE_NEW_EVENT_AVAILABILITY_KEY_FROM = exports.USE_ASSET_TRANSACTION_SYNC_PROCESSING = exports.DEFAULT_TASKS_EXPORT_AGENT_NAME = exports.DEFAULT_SENDER_EMAIL = exports.TRANSACTION_CANCELED_STORAGE_PERIOD_IN_DAYS = exports.TRANSACTION_CONFIRMED_STORAGE_PERIOD_IN_DAYS = exports.ASSET_TRANSACTION_STORAGE_PERIOD_IN_DAYS = exports.ABORTED_TASKS_WITHOUT_REPORT = exports.TRIGGER_WEBHOOK_RETRY_INTERVAL_IN_MS = exports.TRIGGER_WEBHOOK_MAX_RETRY_COUNT = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("./factory");
6
6
  const transactionWebhookUrls = (typeof process.env.INFORM_TRANSACTION_URL === 'string')
@@ -76,10 +76,6 @@ exports.MONGO_READ_PREFERENCE = (typeof process.env.MONGO_READ_PREFERENCE === 's
76
76
  ? process.env.MONGO_READ_PREFERENCE
77
77
  : 'primaryPreferred';
78
78
  exports.MONGO_AUTO_INDEX = process.env.MONGO_AUTO_INDEX === '1';
79
- exports.COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH = (typeof process.env.COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH === 'string')
80
- ? Number(process.env.COA_IMPORT_SCREENING_EVENT_SERIES_PERIOD_IN_MONTH)
81
- // tslint:disable-next-line:no-magic-numbers
82
- : 3;
83
79
  /**
84
80
  * グローバル設定
85
81
  */
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  }
10
10
  ],
11
11
  "dependencies": {
12
- "@chevre/factory": "4.334.0",
12
+ "@chevre/factory": "4.335.0",
13
13
  "@cinerino/sdk": "4.0.0-alpha.1",
14
14
  "@motionpicture/coa-service": "9.2.0",
15
15
  "@motionpicture/gmo-service": "5.2.0",
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "21.13.0-alpha.7"
118
+ "version": "21.13.0-alpha.9"
119
119
  }
@@ -1,27 +0,0 @@
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
- async function main() {
8
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
-
10
- const productRepo = new chevre.repository.Product(mongoose.connection);
11
- const sellerRepo = new chevre.repository.Seller(mongoose.connection);
12
- const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
13
-
14
- const result = await chevre.service.assetTransaction.pay.searchGMOTrade({
15
- transactionNumber: '020518441863622'
16
- })({
17
- product: productRepo,
18
- seller: sellerRepo,
19
- assetTransaction: assetTransactionRepo
20
- });
21
- console.log(result);
22
- // return;
23
- }
24
-
25
- main()
26
- .then(console.log)
27
- .catch(console.error);
@@ -1,22 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- export async function main() {
7
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
8
-
9
- const taskRepo = new chevre.repository.Task(mongoose.connection);
10
-
11
- const count = await taskRepo.countDelayedTasks({
12
- delayInSeconds: 60,
13
- name: {
14
- $nin: [<any>'orderProgramMembership']
15
- }
16
- });
17
- console.log('count:', count);
18
- }
19
-
20
- main()
21
- .then()
22
- .catch(console.error);
@@ -1,60 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- export async function main() {
7
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: true });
8
-
9
- const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection);
10
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
11
-
12
- for (const typeOf of [
13
- chevre.factory.transactionType.PlaceOrder,
14
- chevre.factory.transactionType.ReturnOrder,
15
- chevre.factory.transactionType.MoneyTransfer
16
- ]) {
17
- const count = await transactionRepo.count({
18
- typeOf,
19
- statuses: [
20
- chevre.factory.transactionStatusType.Canceled,
21
- chevre.factory.transactionStatusType.Confirmed,
22
- chevre.factory.transactionStatusType.Expired
23
- ],
24
- tasksExportationStatuses: [
25
- chevre.factory.transactionTasksExportationStatus.Exporting,
26
- chevre.factory.transactionTasksExportationStatus.Unexported
27
- ],
28
- endThrough: new Date()
29
- });
30
- console.log('count:', count, typeOf);
31
- }
32
-
33
- for (const typeOf of [
34
- chevre.factory.assetTransactionType.CancelReservation,
35
- chevre.factory.assetTransactionType.MoneyTransfer,
36
- chevre.factory.assetTransactionType.Pay,
37
- chevre.factory.assetTransactionType.Refund,
38
- chevre.factory.assetTransactionType.RegisterService,
39
- chevre.factory.assetTransactionType.Reserve
40
- ]) {
41
- const count = await assetTransactionRepo.count({
42
- typeOf,
43
- statuses: [
44
- chevre.factory.transactionStatusType.Canceled,
45
- chevre.factory.transactionStatusType.Confirmed,
46
- chevre.factory.transactionStatusType.Expired
47
- ],
48
- tasksExportationStatuses: [
49
- chevre.factory.transactionTasksExportationStatus.Exporting,
50
- chevre.factory.transactionTasksExportationStatus.Unexported
51
- ],
52
- endThrough: new Date()
53
- });
54
- console.log('count:', count, typeOf);
55
- }
56
- }
57
-
58
- main()
59
- .then()
60
- .catch(console.error);
@@ -1,36 +0,0 @@
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
- export async function main() {
11
- const now = new Date();
12
- await mongoose.connect(<string>process.env.MONGOLAB_URI);
13
-
14
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
15
-
16
- const transactions = await transactionRepo.search<chevre.factory.transactionType.MoneyTransfer>(
17
- {
18
- project: { id: { $eq: project.id } },
19
- typeOf: chevre.factory.transactionType.MoneyTransfer,
20
- statuses: [chevre.factory.transactionStatusType.Confirmed],
21
- startFrom: moment(now)
22
- .add(-1, 'year')
23
- .toDate(),
24
- startThrough: now,
25
- inclusion: ['_id', 'startDate', 'typeOf', 'object'],
26
- exclusion: []
27
- }
28
- );
29
- const count = transactions.filter((t) => t.object.description === '受け取り')
30
- .length;
31
- console.log('transactions found', count);
32
- }
33
-
34
- main()
35
- .then()
36
- .catch(console.error);
@@ -1,32 +0,0 @@
1
- // tslint:disable:no-console
2
- import * as mongoose from 'mongoose';
3
-
4
- import { chevre } from '../../../lib/index';
5
-
6
- // tslint:disable-next-line:max-func-body-length
7
- async function main() {
8
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
-
10
- const offerRepo = new chevre.repository.Offer(mongoose.connection);
11
-
12
- const result = await offerRepo.count(
13
- {
14
- project: { id: { $eq: String(process.env.PROJECT_ID) } },
15
- availability: { $eq: chevre.factory.itemAvailability.InStock },
16
- id: {
17
- // $eq: '1001'
18
- // $in: string[];
19
- },
20
- identifier: {
21
- // $eq: '1001'
22
- // $in: string[];
23
- // $regex: '003'
24
- }
25
- }
26
- );
27
- console.log(result);
28
- }
29
-
30
- main()
31
- .then(console.log)
32
- .catch(console.error);
@@ -1,108 +0,0 @@
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 ONE_YEAR_IN_DAYS = 365;
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 now = new Date();
14
- const endDateLt: Date = moment(now)
15
- // tslint:disable-next-line:no-magic-numbers
16
- .add(-ONE_YEAR_IN_DAYS, 'days')
17
- .toDate();
18
- const startDateLt: Date = moment('2022-01-01T00:00:00Z')
19
- .toDate();
20
-
21
- const taskRepo = new chevre.repository.Task(mongoose.connection);
22
- const transactionRepo = new chevre.repository.Transaction(mongoose.connection);
23
-
24
- const cursor = transactionRepo.getCursor(
25
- {
26
- typeOf: { $eq: chevre.factory.transactionType.PlaceOrder },
27
- startDate: {
28
- $lt: startDateLt
29
- }
30
- // endDate: {
31
- // $exists: true,
32
- // $lt: moment(now)
33
- // // tslint:disable-next-line:no-magic-numbers
34
- // .add(-365, 'days')
35
- // .toDate()
36
- // }
37
- },
38
- {
39
- _id: 1,
40
- typeOf: 1,
41
- project: 1,
42
- startDate: 1,
43
- endDate: 1,
44
- object: 1
45
- }
46
- );
47
- console.log('transactions found');
48
-
49
- let i = 0;
50
- let updateCount = 0;
51
- await cursor.eachAsync(async (doc) => {
52
- i += 1;
53
- const transaction: Pick<
54
- chevre.factory.transaction.placeOrder.ITransaction,
55
- 'id' | 'project' | 'typeOf' | 'startDate' | 'endDate' | 'object'
56
- > = doc.toObject();
57
- console.log('checking...', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
58
-
59
- const isEndDateBefore = transaction.endDate !== undefined && moment(transaction.endDate)
60
- .isBefore(endDateLt);
61
- if (isEndDateBefore) {
62
- const runsAt: Date = moment(transaction.endDate)
63
- .add(ONE_YEAR_IN_DAYS, 'days')
64
- .toDate();
65
-
66
- updateCount += 1;
67
- const deleteTransactionTask: chevre.factory.task.deleteTransaction.IAttributes = {
68
- project: transaction.project,
69
- name: chevre.factory.taskName.DeleteTransaction,
70
- status: chevre.factory.taskStatus.Ready,
71
- runsAt,
72
- remainingNumberOfTries: 3,
73
- numberOfTried: 0,
74
- executionResults: [],
75
- data: {
76
- object: {
77
- specifyingMethod: chevre.factory.task.deleteTransaction.SpecifyingMethod.Id,
78
- endDate: transaction.endDate,
79
- id: transaction.id,
80
- object: {
81
- ...(typeof transaction.object.confirmationNumber === 'string')
82
- ? { confirmationNumber: transaction.object.confirmationNumber }
83
- : undefined,
84
- ...(typeof transaction.object.orderNumber === 'string')
85
- ? { orderNumber: transaction.object.orderNumber }
86
- : undefined
87
- },
88
- project: transaction.project,
89
- startDate: transaction.startDate,
90
- typeOf: transaction.typeOf
91
- }
92
- }
93
- };
94
- console.log(
95
- 'saving task...',
96
- deleteTransactionTask, transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
97
- await taskRepo.saveMany([deleteTransactionTask], { emitImmediately: false });
98
- console.log('task saved', transaction.project.id, transaction.id, transaction.startDate, transaction.endDate, i);
99
- }
100
- });
101
-
102
- console.log(i, 'transactions checked');
103
- console.log(updateCount, 'transactions updated');
104
- }
105
-
106
- main()
107
- .then()
108
- .catch(console.error);