@chevre/domain 22.6.0 → 22.7.0-alpha.0

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 (25) hide show
  1. package/example/src/chevre/aggregateAllEvents2.ts +0 -1
  2. package/example/src/chevre/cleanReservations.ts +69 -0
  3. package/example/src/chevre/createEventBySchedule.ts +0 -1
  4. package/example/src/chevre/findSetting.ts +5 -12
  5. package/lib/chevre/repo/mongoose/schemas/setting.d.ts +20 -0
  6. package/lib/chevre/repo/mongoose/schemas/setting.js +2 -0
  7. package/lib/chevre/repo/setting.d.ts +1 -1
  8. package/lib/chevre/repo/setting.js +2 -2
  9. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.d.ts +2 -2
  10. package/lib/chevre/service/transaction/moneyTransfer/exportTasks/factory.js +21 -3
  11. package/lib/chevre/service/transaction/moneyTransfer.d.ts +3 -2
  12. package/lib/chevre/service/transaction/moneyTransfer.js +9 -2
  13. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.d.ts +2 -2
  14. package/lib/chevre/service/transaction/placeOrder/exportTasks/factory.js +27 -8
  15. package/lib/chevre/service/transaction/placeOrder/exportTasksById.d.ts +3 -2
  16. package/lib/chevre/service/transaction/placeOrder/exportTasksById.js +9 -2
  17. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.d.ts +2 -2
  18. package/lib/chevre/service/transaction/returnOrder/exportTasks/factory.js +23 -5
  19. package/lib/chevre/service/transaction/returnOrder.d.ts +2 -2
  20. package/lib/chevre/service/transaction/returnOrder.js +9 -2
  21. package/lib/chevre/service/transaction.d.ts +3 -2
  22. package/lib/chevre/service/transaction.js +6 -4
  23. package/lib/chevre/settings.d.ts +0 -29
  24. package/lib/chevre/settings.js +3 -18
  25. package/package.json +1 -1
@@ -51,7 +51,6 @@ export async function aggregateScreeningEvent() {
51
51
  headerIdentifier: 'xx'
52
52
  },
53
53
  deliverOrderLimit: 1,
54
- transaction: { informUrls: [], confirmedStoragePeriodInDays: 365, canceledStoragePeriodInDays: 365 },
55
54
  abortedTasksWithoutReport: [],
56
55
  coa: { timeout: 1000 },
57
56
  gmo: { timeout: 1000, timeoutBackground: 1000, useFetch: true },
@@ -0,0 +1,69 @@
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
+ // const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
9
+
10
+ // tslint:disable-next-line:max-func-body-length
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
13
+
14
+ const reservationsRepo = await chevre.repository.Reservation.createInstance(mongoose.connection);
15
+
16
+ const cursor = reservationsRepo.getCursor(
17
+ {
18
+ bookingTime: {
19
+ $lte: moment()
20
+ // tslint:disable-next-line:no-magic-numbers
21
+ .add(-365, 'days')
22
+ .toDate()
23
+ },
24
+ reservationStatus: {
25
+ $in: [
26
+ chevre.factory.reservationStatusType.ReservationCancelled
27
+ // chevre.factory.reservationStatusType.ReservationConfirmed
28
+ ]
29
+ }
30
+ // 'project.id': { $eq: project.id },
31
+ // 'project.id': { $ne: EXCLUDED_PROJECT_ID },
32
+ },
33
+ {
34
+ // paymentMethods: 1,
35
+ // project: 1,
36
+ // orderDate: 1
37
+ }
38
+ );
39
+ console.log('docs found');
40
+
41
+ let i = 0;
42
+ let updatedCount = 0;
43
+ await cursor.eachAsync(async (doc) => {
44
+ i += 1;
45
+ const reservation: chevre.factory.reservation.eventReservation.IReservation & {
46
+ previousReservationStatus: string;
47
+ } = doc.toObject();
48
+ console.log(
49
+ 'checking...',
50
+ reservation.project.id, reservation.id,
51
+ reservation.previousReservationStatus, reservation.reservationStatus, reservation.bookingTime, i
52
+ );
53
+ if (reservation.previousReservationStatus !== chevre.factory.reservationStatusType.ReservationPending) {
54
+ // throw new Error('invalid previousReservationStatus');
55
+ } else {
56
+ await reservationsRepo.deleteByIds({
57
+ project: { id: reservation.project.id },
58
+ ids: [reservation.id]
59
+ });
60
+ updatedCount += 1;
61
+ }
62
+ });
63
+ console.log(i, 'docs checked');
64
+ console.log(updatedCount, 'docs updated');
65
+ }
66
+
67
+ main()
68
+ .then()
69
+ .catch(console.error);
@@ -31,7 +31,6 @@ async function main() {
31
31
  headerIdentifier: 'xx'
32
32
  },
33
33
  deliverOrderLimit: 1,
34
- transaction: { informUrls: [], confirmedStoragePeriodInDays: 365, canceledStoragePeriodInDays: 365 },
35
34
  abortedTasksWithoutReport: [],
36
35
  coa: { timeout: 1000 },
37
36
  gmo: { timeout: 1000, timeoutBackground: 1000, useFetch: true },
@@ -25,7 +25,7 @@ async function main() {
25
25
 
26
26
  const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
27
27
 
28
- const result = await settingRepo.findOne({}, ['useInformResourceTypes']);
28
+ const result = await settingRepo.findOne({}, ['storage']);
29
29
  // tslint:disable-next-line:no-null-keyword
30
30
  console.dir(result, { depth: null });
31
31
 
@@ -53,17 +53,10 @@ async function main() {
53
53
  const updateResult = await settingRepo.updateByProject(
54
54
  { project: { id: { $eq: '*' } } },
55
55
  {
56
- useInformResourceTypes: [
57
- 'AccountTitle',
58
- 'CategoryCode',
59
- 'Movie',
60
- 'MovieTheater',
61
- 'EventService',
62
- 'NoteDigitalDocument',
63
- 'POS',
64
- 'ScreeningEvent',
65
- 'ScreeningEventSeries'
66
- ]
56
+ storage: {
57
+ transactionCanceledInDays: 180,
58
+ transactionConfirmedInDays: 365
59
+ }
67
60
  }
68
61
  );
69
62
  console.log('updated', updateResult);
@@ -15,6 +15,24 @@ interface IOnReservationStatusChanged {
15
15
  interface IOnEventChanged {
16
16
  informEvent2agg?: factory.project.IInformParams[];
17
17
  }
18
+ interface IOnTransactionStatusChanged {
19
+ /**
20
+ * AggService通知先
21
+ */
22
+ informTransaction?: factory.project.IInformParams[];
23
+ }
24
+ interface IStorageSettings {
25
+ /**
26
+ * 取引保管期間(Confirmed)
27
+ * default:365
28
+ */
29
+ transactionConfirmedInDays?: number;
30
+ /**
31
+ * 取引保管期間(Canceled)
32
+ * default:7
33
+ */
34
+ transactionCanceledInDays?: number;
35
+ }
18
36
  export interface ISetting {
19
37
  defaultSenderEmail?: string;
20
38
  onEventChanged?: IOnEventChanged;
@@ -23,10 +41,12 @@ export interface ISetting {
23
41
  onResourceUpdated?: {
24
42
  informResource?: factory.project.IInformParams[];
25
43
  };
44
+ onTransactionStatusChanged?: IOnTransactionStatusChanged;
26
45
  project: {
27
46
  id: string;
28
47
  typeOf: factory.organizationType.Project;
29
48
  };
49
+ storage?: IStorageSettings;
30
50
  useInformResourceTypes?: string[];
31
51
  userPoolIdOld?: string;
32
52
  userPoolIdNew?: string;
@@ -13,6 +13,8 @@ const schemaDefinition = {
13
13
  onOrderStatusChanged: mongoose_1.SchemaTypes.Mixed,
14
14
  onReservationStatusChanged: mongoose_1.SchemaTypes.Mixed,
15
15
  onResourceUpdated: mongoose_1.SchemaTypes.Mixed,
16
+ onTransactionStatusChanged: mongoose_1.SchemaTypes.Mixed,
17
+ storage: mongoose_1.SchemaTypes.Mixed,
16
18
  useInformResourceTypes: [String],
17
19
  userPoolIdOld: String,
18
20
  userPoolIdNew: String
@@ -46,5 +46,5 @@ export declare class SettingRepo {
46
46
  $eq: string;
47
47
  };
48
48
  };
49
- }, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld'>): Promise<import("mongoose").UpdateWriteOpResult>;
49
+ }, update: Pick<ISetting, 'onEventChanged' | 'onReservationStatusChanged' | 'onResourceUpdated' | 'defaultSenderEmail' | 'useInformResourceTypes' | 'userPoolIdNew' | 'userPoolIdOld' | 'storage'>): Promise<import("mongoose").UpdateWriteOpResult>;
50
50
  }
@@ -49,9 +49,9 @@ class SettingRepo {
49
49
  }
50
50
  updateByProject(filter, update) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- const { onEventChanged, onReservationStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld } = update;
52
+ const { onEventChanged, onReservationStatusChanged, onResourceUpdated, defaultSenderEmail, useInformResourceTypes, userPoolIdNew, userPoolIdOld, storage } = update;
53
53
  return this.settingModel.updateOne({ 'project.id': { $eq: filter.project.id.$eq } }, {
54
- $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined)
54
+ $set: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (onEventChanged !== undefined) ? { onEventChanged } : undefined), (onReservationStatusChanged !== undefined) ? { onReservationStatusChanged } : undefined), (onResourceUpdated !== undefined) ? { onResourceUpdated } : undefined), (defaultSenderEmail !== undefined) ? { defaultSenderEmail } : undefined), (useInformResourceTypes !== undefined) ? { useInformResourceTypes } : undefined), (userPoolIdNew !== undefined) ? { userPoolIdNew } : undefined), (userPoolIdOld !== undefined) ? { userPoolIdOld } : undefined), (storage !== undefined) ? { storage } : undefined)
55
55
  })
56
56
  .exec();
57
57
  });
@@ -1,9 +1,9 @@
1
+ import type { ISetting } from '../../../../repo/setting';
1
2
  import * as factory from '../../../../factory';
2
- import { Settings } from '../../../../settings';
3
3
  /**
4
4
  * 取引のタスクを作成する
5
5
  */
6
6
  export declare function createTasks(params: {
7
7
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.MoneyTransfer>, 'id' | 'endDate' | 'status' | 'project' | 'startDate' | 'typeOf' | 'object' | 'potentialActions'>;
8
8
  runsAt: Date;
9
- }, settings: Settings): factory.task.IAttributes<factory.taskName>[];
9
+ }, setting: Pick<ISetting, 'storage'> | null): factory.task.IAttributes<factory.taskName>[];
@@ -3,25 +3,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTasks = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("../../../../factory");
6
+ // import { Settings } from '../../../../settings';
6
7
  /**
7
8
  * 取引のタスクを作成する
8
9
  */
9
10
  // tslint:disable-next-line:max-func-body-length
10
- function createTasks(params, settings) {
11
+ function createTasks(params, setting
12
+ // settings: Settings
13
+ ) {
14
+ var _a, _b;
11
15
  const taskAttributes = [];
12
16
  const transaction = params.transaction;
13
17
  const taskRunsAt = params.runsAt;
18
+ const confirmedStoragePeriodInDays = (_a = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _a === void 0 ? void 0 : _a.transactionConfirmedInDays;
19
+ const canceledStoragePeriodInDays = (_b = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _b === void 0 ? void 0 : _b.transactionCanceledInDays;
20
+ if (typeof confirmedStoragePeriodInDays !== 'number') {
21
+ throw new factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
22
+ }
23
+ if (typeof canceledStoragePeriodInDays !== 'number') {
24
+ throw new factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
25
+ }
14
26
  // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
27
+ // let deleteAt = moment(transaction.endDate)
28
+ // .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
29
+ // .toDate();
15
30
  let deleteAt = moment(transaction.endDate)
16
- .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
31
+ .add(confirmedStoragePeriodInDays, 'days')
17
32
  .toDate();
18
33
  switch (transaction.status) {
19
34
  case factory.transactionStatusType.Confirmed:
20
35
  break;
21
36
  case factory.transactionStatusType.Canceled:
22
37
  case factory.transactionStatusType.Expired:
38
+ // deleteAt = moment(transaction.endDate)
39
+ // .add(settings.transaction.canceledStoragePeriodInDays, 'days')
40
+ // .toDate();
23
41
  deleteAt = moment(transaction.endDate)
24
- .add(settings.transaction.canceledStoragePeriodInDays, 'days')
42
+ .add(canceledStoragePeriodInDays, 'days')
25
43
  .toDate();
26
44
  break;
27
45
  default:
@@ -7,11 +7,11 @@ import type { PassportRepo } from '../../repo/passport';
7
7
  import type { ProductRepo } from '../../repo/product';
8
8
  import type { ProjectRepo } from '../../repo/project';
9
9
  import type { SellerRepo } from '../../repo/seller';
10
+ import type { SettingRepo } from '../../repo/setting';
10
11
  import type { TaskRepo } from '../../repo/task';
11
12
  import type { TicketRepo } from '../../repo/ticket';
12
13
  import type { IStartedTransaction, TransactionRepo } from '../../repo/transaction';
13
14
  import type { TransactionNumberRepo } from '../../repo/transactionNumber';
14
- import { Settings } from '../../settings';
15
15
  import { moneyTransfer as MoneyTransferFactory } from '../../factory/transaction';
16
16
  export interface IStartOperationRepos {
17
17
  action: ActionRepo;
@@ -30,9 +30,10 @@ export type IStartOperation<T> = (repos: IStartOperationRepos, credentials: {
30
30
  jwt: JWTCredentials;
31
31
  }) => Promise<T>;
32
32
  export type ITaskAndTransactionOperation<T> = (repos: {
33
+ setting: SettingRepo;
33
34
  task: TaskRepo;
34
35
  transaction: TransactionRepo;
35
- }, settings: Settings) => Promise<T>;
36
+ }) => Promise<T>;
36
37
  export type IConfirmOperation<T> = (repos: {
37
38
  action: ActionRepo;
38
39
  transaction: TransactionRepo;
@@ -16,6 +16,7 @@ exports.exportTasksById = exports.confirm = exports.start = void 0;
16
16
  const moment = require("moment");
17
17
  const factory = require("../../factory");
18
18
  const order_1 = require("../../factory/order");
19
+ // import { Settings } from '../../settings';
19
20
  const factory_1 = require("./moneyTransfer/exportTasks/factory");
20
21
  const factory_2 = require("./moneyTransfer/factory");
21
22
  const potentialActions_1 = require("./moneyTransfer/potentialActions");
@@ -561,7 +562,9 @@ function searchAuthorizeActions(params) {
561
562
  * 取引のタスク出力
562
563
  */
563
564
  function exportTasksById(params) {
564
- return (repos, settings) => __awaiter(this, void 0, void 0, function* () {
565
+ return (repos
566
+ // settings: Settings
567
+ ) => __awaiter(this, void 0, void 0, function* () {
565
568
  const transaction = yield repos.transaction.projectFieldsById({
566
569
  typeOf: factory.transactionType.MoneyTransfer,
567
570
  id: params.id
@@ -573,10 +576,14 @@ function exportTasksById(params) {
573
576
  .add(params.runsTasksAfterInSeconds, 'seconds')
574
577
  .toDate();
575
578
  }
579
+ // search settings
580
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
576
581
  const taskAttributes = (0, factory_1.createTasks)({
577
582
  transaction,
578
583
  runsAt: taskRunsAt
579
- }, settings);
584
+ }, setting
585
+ // settings
586
+ );
580
587
  yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
581
588
  });
582
589
  }
@@ -1,5 +1,5 @@
1
+ import type { ISetting } from '../../../../repo/setting';
1
2
  import * as factory from '../../../../factory';
2
- import { Settings } from '../../../../settings';
3
3
  export type IPlaceOrderTransactionAsInformObject = Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'id' | 'typeOf' | 'endDate' | 'project' | 'seller' | 'startDate' | 'status'>;
4
4
  /**
5
5
  * 取引のタスクを作成する
@@ -7,4 +7,4 @@ export type IPlaceOrderTransactionAsInformObject = Pick<factory.transaction.ITra
7
7
  export declare function createTasks(params: {
8
8
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'endDate' | 'id' | 'object' | 'project' | 'seller' | 'startDate' | 'status' | 'typeOf'>;
9
9
  runsAt: Date;
10
- }, settings: Settings): factory.task.IAttributes<factory.taskName>[];
10
+ }, setting: Pick<ISetting, 'onTransactionStatusChanged' | 'storage'> | null): factory.task.IAttributes<factory.taskName>[];
@@ -7,12 +7,17 @@ const factory = require("../../../../factory");
7
7
  * 取引のタスクを作成する
8
8
  */
9
9
  // tslint:disable-next-line:max-func-body-length
10
- function createTasks(params, settings) {
10
+ function createTasks(params, setting
11
+ // settings: Settings
12
+ ) {
13
+ var _a, _b, _c;
11
14
  const taskAttributes = [];
12
15
  const transaction = params.transaction;
13
16
  const taskRunsAt = params.runsAt;
14
- const transactionWebhookUrls = (Array.isArray(settings.transaction.informUrls)) ? settings.transaction.informUrls : [];
15
- const triggerWebhookTaskAttributes = transactionWebhookUrls.map((webhookUrl) => {
17
+ // const transactionWebhookUrls = (Array.isArray(settings.transaction.informUrls)) ? settings.transaction.informUrls : [];
18
+ const informTransaction = (_a = setting === null || setting === void 0 ? void 0 : setting.onTransactionStatusChanged) === null || _a === void 0 ? void 0 : _a.informTransaction;
19
+ const transactionWebhookUrls = (Array.isArray(informTransaction)) ? informTransaction : [];
20
+ const triggerWebhookTaskAttributes = transactionWebhookUrls.map(({ recipient }) => {
16
21
  const informObject = Object.assign({ id: transaction.id, typeOf: transaction.typeOf, project: transaction.project, seller: transaction.seller, startDate: transaction.startDate, status: transaction.status }, (transaction.endDate !== undefined) ? { endDate: transaction.endDate } : undefined);
17
22
  return {
18
23
  project: transaction.project,
@@ -27,26 +32,40 @@ function createTasks(params, settings) {
27
32
  object: informObject,
28
33
  project: transaction.project,
29
34
  recipient: {
30
- id: '',
31
- name: webhookUrl,
35
+ id: (typeof (recipient === null || recipient === void 0 ? void 0 : recipient.id) === 'string') ? recipient.id : '',
36
+ name: recipient === null || recipient === void 0 ? void 0 : recipient.name,
32
37
  typeOf: factory.creativeWorkType.WebApplication,
33
- url: webhookUrl
38
+ url: recipient === null || recipient === void 0 ? void 0 : recipient.url
34
39
  },
35
40
  typeOf: factory.actionType.InformAction
36
41
  }
37
42
  };
38
43
  });
44
+ const confirmedStoragePeriodInDays = (_b = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _b === void 0 ? void 0 : _b.transactionConfirmedInDays;
45
+ const canceledStoragePeriodInDays = (_c = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _c === void 0 ? void 0 : _c.transactionCanceledInDays;
46
+ if (typeof confirmedStoragePeriodInDays !== 'number') {
47
+ throw new factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
48
+ }
49
+ if (typeof canceledStoragePeriodInDays !== 'number') {
50
+ throw new factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
51
+ }
39
52
  // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
53
+ // let deleteAt = moment(transaction.endDate)
54
+ // .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
55
+ // .toDate();
40
56
  let deleteAt = moment(transaction.endDate)
41
- .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
57
+ .add(confirmedStoragePeriodInDays, 'days')
42
58
  .toDate();
43
59
  switch (transaction.status) {
44
60
  case factory.transactionStatusType.Confirmed:
45
61
  break;
46
62
  case factory.transactionStatusType.Canceled:
47
63
  case factory.transactionStatusType.Expired:
64
+ // deleteAt = moment(transaction.endDate)
65
+ // .add(settings.transaction.canceledStoragePeriodInDays, 'days')
66
+ // .toDate();
48
67
  deleteAt = moment(transaction.endDate)
49
- .add(settings.transaction.canceledStoragePeriodInDays, 'days')
68
+ .add(canceledStoragePeriodInDays, 'days')
50
69
  .toDate();
51
70
  break;
52
71
  default:
@@ -1,10 +1,11 @@
1
+ import type { SettingRepo } from '../../../repo/setting';
1
2
  import type { TaskRepo } from '../../../repo/task';
2
3
  import type { TransactionRepo } from '../../../repo/transaction';
3
- import { Settings } from '../../../settings';
4
4
  type ITaskAndTransactionOperation<T> = (repos: {
5
+ setting: SettingRepo;
5
6
  task: TaskRepo;
6
7
  transaction: TransactionRepo;
7
- }, settings: Settings) => Promise<T>;
8
+ }) => Promise<T>;
8
9
  /**
9
10
  * 取引のタスクを出力します
10
11
  */
@@ -12,12 +12,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.exportTasksById = void 0;
13
13
  const moment = require("moment");
14
14
  const factory = require("../../../factory");
15
+ // import { Settings } from '../../../settings';
15
16
  const factory_1 = require("./exportTasks/factory");
16
17
  /**
17
18
  * 取引のタスクを出力します
18
19
  */
19
20
  function exportTasksById(params) {
20
- return (repos, settings) => __awaiter(this, void 0, void 0, function* () {
21
+ return (repos
22
+ // settings: Settings
23
+ ) => __awaiter(this, void 0, void 0, function* () {
21
24
  const transaction = yield repos.transaction.projectFieldsById({
22
25
  typeOf: factory.transactionType.PlaceOrder,
23
26
  id: params.id
@@ -29,10 +32,14 @@ function exportTasksById(params) {
29
32
  .add(params.runsTasksAfterInSeconds, 'seconds')
30
33
  .toDate();
31
34
  }
35
+ // search settings
36
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onTransactionStatusChanged', 'storage']);
32
37
  const taskAttributes = (0, factory_1.createTasks)({
33
38
  transaction,
34
39
  runsAt: taskRunsAt
35
- }, settings);
40
+ }, setting
41
+ // settings
42
+ );
36
43
  yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
37
44
  });
38
45
  }
@@ -1,9 +1,9 @@
1
+ import type { ISetting } from '../../../../repo/setting';
1
2
  import * as factory from '../../../../factory';
2
- import { Settings } from '../../../../settings';
3
3
  /**
4
4
  * 取引のタスクを作成する
5
5
  */
6
6
  export declare function createTasks(params: {
7
7
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.ReturnOrder>, 'endDate' | 'status' | 'id' | 'project' | 'typeOf' | 'startDate' | 'object' | 'potentialActions'>;
8
8
  runsAt: Date;
9
- }, settings: Settings): factory.task.IAttributes<factory.taskName>[];
9
+ }, setting: Pick<ISetting, 'storage'> | null): factory.task.IAttributes<factory.taskName>[];
@@ -3,25 +3,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createTasks = void 0;
4
4
  const moment = require("moment");
5
5
  const factory = require("../../../../factory");
6
+ // import { Settings } from '../../../../settings';
6
7
  /**
7
8
  * 取引のタスクを作成する
8
9
  */
9
- function createTasks(params, settings) {
10
- var _a;
10
+ // tslint:disable-next-line:max-func-body-length
11
+ function createTasks(params, setting
12
+ // settings: Settings
13
+ ) {
14
+ var _a, _b, _c;
11
15
  const taskAttributes = [];
12
16
  const transaction = params.transaction;
13
17
  const taskRunsAt = params.runsAt;
18
+ const confirmedStoragePeriodInDays = (_a = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _a === void 0 ? void 0 : _a.transactionConfirmedInDays;
19
+ const canceledStoragePeriodInDays = (_b = setting === null || setting === void 0 ? void 0 : setting.storage) === null || _b === void 0 ? void 0 : _b.transactionCanceledInDays;
20
+ if (typeof confirmedStoragePeriodInDays !== 'number') {
21
+ throw new factory.errors.NotFound('setting.storage.confirmedStoragePeriodInDays');
22
+ }
23
+ if (typeof canceledStoragePeriodInDays !== 'number') {
24
+ throw new factory.errors.NotFound('setting.storage.canceledStoragePeriodInDays');
25
+ }
14
26
  // 取引削除タスクを作成(取引ステータスによってrunsAtを調整)
27
+ // let deleteAt = moment(transaction.endDate)
28
+ // .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
29
+ // .toDate();
15
30
  let deleteAt = moment(transaction.endDate)
16
- .add(settings.transaction.confirmedStoragePeriodInDays, 'days')
31
+ .add(confirmedStoragePeriodInDays, 'days')
17
32
  .toDate();
18
33
  switch (transaction.status) {
19
34
  case factory.transactionStatusType.Confirmed:
20
35
  break;
21
36
  case factory.transactionStatusType.Canceled:
22
37
  case factory.transactionStatusType.Expired:
38
+ // deleteAt = moment(transaction.endDate)
39
+ // .add(settings.transaction.canceledStoragePeriodInDays, 'days')
40
+ // .toDate();
23
41
  deleteAt = moment(transaction.endDate)
24
- .add(settings.transaction.canceledStoragePeriodInDays, 'days')
42
+ .add(canceledStoragePeriodInDays, 'days')
25
43
  .toDate();
26
44
  break;
27
45
  default:
@@ -43,7 +61,7 @@ function createTasks(params, settings) {
43
61
  taskAttributes.push(deleteTransactionTask);
44
62
  switch (transaction.status) {
45
63
  case factory.transactionStatusType.Confirmed:
46
- const returnOrderPotentialActions = (_a = transaction.potentialActions) === null || _a === void 0 ? void 0 : _a.returnOrder;
64
+ const returnOrderPotentialActions = (_c = transaction.potentialActions) === null || _c === void 0 ? void 0 : _c.returnOrder;
47
65
  if (Array.isArray(returnOrderPotentialActions)) {
48
66
  // 返品タスク
49
67
  const returnOrderTask = returnOrderPotentialActions.map((r) => {
@@ -13,7 +13,6 @@ import type { SellerRepo } from '../../repo/seller';
13
13
  import type { SettingRepo } from '../../repo/setting';
14
14
  import type { TaskRepo } from '../../repo/task';
15
15
  import type { IStartedTransaction, TransactionRepo } from '../../repo/transaction';
16
- import { Settings } from '../../settings';
17
16
  import { preStart } from './returnOrder/preStart';
18
17
  interface IStartOperationRepos {
19
18
  acceptedOffer: AcceptedOfferRepo;
@@ -29,9 +28,10 @@ interface IStartOperationRepos {
29
28
  }
30
29
  type IStartOperation<T> = (repos: IStartOperationRepos) => Promise<T>;
31
30
  type ITaskAndTransactionOperation<T> = (repos: {
31
+ setting: SettingRepo;
32
32
  task: TaskRepo;
33
33
  transaction: TransactionRepo;
34
- }, settings: Settings) => Promise<T>;
34
+ }) => Promise<T>;
35
35
  /**
36
36
  * 返品取引開始
37
37
  */
@@ -16,6 +16,7 @@ exports.exportTasksById = exports.confirm = exports.start = exports.preStart = v
16
16
  const createDebug = require("debug");
17
17
  const moment = require("moment-timezone");
18
18
  const factory = require("../../factory");
19
+ // import { Settings } from '../../settings';
19
20
  const factory_1 = require("./returnOrder/exportTasks/factory");
20
21
  const potentialActions_1 = require("./returnOrder/potentialActions");
21
22
  const preStart_1 = require("./returnOrder/preStart");
@@ -155,7 +156,9 @@ exports.confirm = confirm;
155
156
  * この関数では、取引のタスクエクスポートステータスは見ません
156
157
  */
157
158
  function exportTasksById(params) {
158
- return (repos, settings) => __awaiter(this, void 0, void 0, function* () {
159
+ return (repos
160
+ // settings: Settings
161
+ ) => __awaiter(this, void 0, void 0, function* () {
159
162
  const transaction = yield repos.transaction.projectFieldsById({ typeOf: factory.transactionType.ReturnOrder, id: params.id }, ['typeOf', 'status', 'project', 'endDate', 'startDate', 'object', 'potentialActions']);
160
163
  // タスク実行日時バッファの指定があれば調整
161
164
  let taskRunsAt = new Date();
@@ -164,10 +167,14 @@ function exportTasksById(params) {
164
167
  .add(params.runsTasksAfterInSeconds, 'seconds')
165
168
  .toDate();
166
169
  }
170
+ // search settings
171
+ const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['storage']);
167
172
  const taskAttributes = (0, factory_1.createTasks)({
168
173
  transaction,
169
174
  runsAt: taskRunsAt
170
- }, settings);
175
+ }, setting
176
+ // settings
177
+ );
171
178
  yield repos.task.saveMany(taskAttributes, { emitImmediately: true });
172
179
  });
173
180
  }
@@ -2,13 +2,13 @@ import * as factory from '../factory';
2
2
  import type { OrderInTransactionRepo } from '../repo/orderInTransaction';
3
3
  import type { OrderNumberRepo } from '../repo/orderNumber';
4
4
  import type { ProjectRepo } from '../repo/project';
5
+ import type { SettingRepo } from '../repo/setting';
5
6
  import type { TaskRepo } from '../repo/task';
6
7
  import type { TransactionRepo } from '../repo/transaction';
7
8
  import { deleteTransaction } from './transaction/deleteTransaction';
8
9
  import * as MoneyTransferTransactionService from './transaction/moneyTransfer';
9
10
  import * as PlaceOrderTransactionService from './transaction/placeOrder';
10
11
  import * as ReturnOrderTransactionService from './transaction/returnOrder';
11
- import { Settings } from '../settings';
12
12
  export type ITransactionOperation<T> = (repos: {
13
13
  transaction: TransactionRepo;
14
14
  }) => Promise<T>;
@@ -35,9 +35,10 @@ export declare function updateAgent(params: {
35
35
  transaction: TransactionRepo;
36
36
  }) => Promise<void>;
37
37
  export type IExportTasksOperation<T> = (repos: {
38
+ setting: SettingRepo;
38
39
  task: TaskRepo;
39
40
  transaction: TransactionRepo;
40
- }, settings: Settings) => Promise<T>;
41
+ }) => Promise<T>;
41
42
  /**
42
43
  * ひとつの取引のタスクをエクスポートする
43
44
  */
@@ -112,7 +112,9 @@ exports.updateAgent = updateAgent;
112
112
  * ひとつの取引のタスクをエクスポートする
113
113
  */
114
114
  function exportTasks(params) {
115
- return (repos, settings) => __awaiter(this, void 0, void 0, function* () {
115
+ return (repos
116
+ // settings: Settings
117
+ ) => __awaiter(this, void 0, void 0, function* () {
116
118
  const transaction = yield repos.transaction.startExportTasks(Object.assign(Object.assign({ status: params.status, tasksExportAction: {
117
119
  agent: { name: params.tasksExportAction.agent.name }
118
120
  } }, (params.typeOf !== undefined) ? { typeOf: params.typeOf } : undefined), (typeof params.id === 'string') ? { id: params.id } : undefined));
@@ -124,17 +126,17 @@ function exportTasks(params) {
124
126
  case factory.transactionType.MoneyTransfer:
125
127
  yield MoneyTransferTransactionService.exportTasksById(Object.assign({ id: transaction.id }, (typeof params.runsTasksAfterInSeconds === 'number')
126
128
  ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
127
- : undefined))(repos, settings);
129
+ : undefined))(repos);
128
130
  break;
129
131
  case factory.transactionType.PlaceOrder:
130
132
  yield PlaceOrderTransactionService.exportTasksById(Object.assign({ id: transaction.id }, (typeof params.runsTasksAfterInSeconds === 'number')
131
133
  ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
132
- : undefined))(repos, settings);
134
+ : undefined))(repos);
133
135
  break;
134
136
  case factory.transactionType.ReturnOrder:
135
137
  yield ReturnOrderTransactionService.exportTasksById(Object.assign({ id: transaction.id }, (typeof params.runsTasksAfterInSeconds === 'number')
136
138
  ? { runsTasksAfterInSeconds: params.runsTasksAfterInSeconds }
137
- : undefined))(repos, settings);
139
+ : undefined))(repos);
138
140
  break;
139
141
  default:
140
142
  }
@@ -36,19 +36,6 @@ interface ISurfrockSettings {
36
36
  interface IOptions {
37
37
  abortedTasksWithoutReport: string[];
38
38
  numTryConfirmReserveTransaction: number;
39
- transaction: {
40
- informUrls: string[];
41
- /**
42
- * 取引保管期間(Confirmed)
43
- * default:365
44
- */
45
- confirmedStoragePeriodInDays: number;
46
- /**
47
- * 取引保管期間(Canceled)
48
- * default:7
49
- */
50
- canceledStoragePeriodInDays: number;
51
- };
52
39
  deliverOrderLimit: number;
53
40
  coa: {
54
41
  timeout: number;
@@ -68,22 +55,6 @@ interface IOptions {
68
55
  declare class Settings {
69
56
  readonly abortedTasksWithoutReport: string[];
70
57
  readonly numTryConfirmReserveTransaction: number;
71
- readonly transaction: {
72
- /**
73
- * 注文取引通知先
74
- */
75
- informUrls: string[];
76
- /**
77
- * 取引保管期間(Confirmed)
78
- * default:365
79
- */
80
- confirmedStoragePeriodInDays: number;
81
- /**
82
- * 取引保管期間(Canceled)
83
- * default:7
84
- */
85
- canceledStoragePeriodInDays: number;
86
- };
87
58
  readonly deliverOrderLimit: number;
88
59
  readonly coa: {
89
60
  timeout: number;
@@ -1,5 +1,4 @@
1
1
  "use strict";
2
- // import * as factory from './factory';
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.Settings = exports.AggregationSettings = exports.MONGO_AUTO_INDEX = exports.MONGO_READ_PREFERENCE = exports.MONGO_MAX_TIME_MS = void 0;
5
4
  const aggregation_1 = require("./settings/aggregation");
@@ -9,28 +8,14 @@ Object.defineProperty(exports, "AggregationSettings", { enumerable: true, get: f
9
8
  */
10
9
  class Settings {
11
10
  constructor(options) {
12
- const {
13
- // onEventChanged,
14
- // onOrderStatusChanged,
15
- // onResourceUpdated,
16
- // onReservationStatusChanged,
17
- // userPoolIdOld,
18
- // userPoolIdNew,
19
- abortedTasksWithoutReport, numTryConfirmReserveTransaction, transaction,
20
- // defaultSenderEmail,
11
+ const { abortedTasksWithoutReport, numTryConfirmReserveTransaction,
12
+ // transaction,
21
13
  deliverOrderLimit, coa, gmo, movieticketReserve,
22
14
  // useAssetTransactionSyncProcessing,
23
15
  useExperimentalFeature, notification } = options;
24
- // this.onEventChanged = onEventChanged;
25
- // this.onOrderStatusChanged = onOrderStatusChanged;
26
- // this.onResourceUpdated = onResourceUpdated;
27
- // this.onReservationStatusChanged = onReservationStatusChanged;
28
- // this.userPoolIdOld = userPoolIdOld;
29
- // this.userPoolIdNew = userPoolIdNew;
30
16
  this.abortedTasksWithoutReport = abortedTasksWithoutReport;
31
17
  this.numTryConfirmReserveTransaction = numTryConfirmReserveTransaction;
32
- this.transaction = transaction;
33
- // this.defaultSenderEmail = defaultSenderEmail;
18
+ // this.transaction = transaction;
34
19
  this.deliverOrderLimit = deliverOrderLimit;
35
20
  this.coa = coa;
36
21
  this.gmo = gmo;
package/package.json CHANGED
@@ -108,5 +108,5 @@
108
108
  "postversion": "git push origin --tags",
109
109
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
110
110
  },
111
- "version": "22.6.0"
111
+ "version": "22.7.0-alpha.0"
112
112
  }