@chevre/domain 21.30.0-alpha.3 → 21.30.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
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 actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
+
15
+ // tslint:disable-next-line:no-increment-decrement no-magic-numbers
16
+ for (let index = 0; index < 24 * 548; index++) {
17
+ const updateResult = await actionRepo.unsetUnnecessaryFields({
18
+ filter: {
19
+ // typeOf: { $eq: chevre.factory.actionType.ConfirmAction },
20
+ // typeOf: { $eq: chevre.factory.actionType.SendAction },
21
+ // typeOf: { $eq: chevre.factory.actionType.ReturnAction },
22
+ typeOf: { $eq: chevre.factory.actionType.PayAction },
23
+ 'purpose.typeOf': { $exists: true, $eq: chevre.factory.order.OrderType.Order },
24
+ startDate: {
25
+ $gte: moment()
26
+ .add(-(index + 1), 'hours')
27
+ .toDate(),
28
+ $lte: moment()
29
+ .add(-index, 'hours')
30
+ .toDate()
31
+ }
32
+ // _id: { $eq: '61da235d94a80f000af85f6b' }
33
+ },
34
+ $unset: {
35
+ 'purpose.project': 1,
36
+ 'purpose.seller': 1,
37
+ 'purpose.customer': 1
38
+ }
39
+ });
40
+ console.log(
41
+ 'unset processed.', updateResult,
42
+ -index, 'hours',
43
+ moment.duration(index, 'hours')
44
+ .asDays(),
45
+ 'days'
46
+ );
47
+ }
48
+ }
49
+
50
+ main()
51
+ .then(() => {
52
+ console.log('success!');
53
+ })
54
+ .catch(console.error);
@@ -169,7 +169,12 @@ export declare class MongoRepository {
169
169
  $eq: string;
170
170
  };
171
171
  };
172
- }): Promise<Pick<IAction<factory.actionType>, 'id' | 'actionStatus'>[]>;
172
+ purpose?: {
173
+ id: {
174
+ $eq: string;
175
+ };
176
+ };
177
+ }): Promise<Pick<IAction<factory.actionType>, 'id' | 'actionStatus' | 'error'>[]>;
173
178
  deleteByProject(params: {
174
179
  project: {
175
180
  id: string;
@@ -536,11 +536,17 @@ class MongoRepository {
536
536
  const doc = yield this.actionModel.findOneAndUpdate({
537
537
  _id: { $eq: params.id },
538
538
  typeOf: { $eq: params.typeOf }
539
- }, { actionStatus: factory.actionStatusType.CanceledActionStatus }, { new: false, projection: { _id: 1 } })
539
+ }, { $set: { actionStatus: factory.actionStatusType.CanceledActionStatus } }, { new: false, projection: { _id: 1 } })
540
540
  .exec();
541
541
  if (doc === null) {
542
542
  throw new factory.errors.NotFound(this.actionModel.modelName);
543
543
  }
544
+ // endDateが存在しなければセット(2024-04-22~)
545
+ yield this.actionModel.updateOne({
546
+ _id: { $eq: params.id },
547
+ endDate: { $exists: false }
548
+ }, { $set: { endDate: new Date() } })
549
+ .exec();
544
550
  });
545
551
  }
546
552
  /**
@@ -702,9 +708,12 @@ class MongoRepository {
702
708
  });
703
709
  }
704
710
  searchBySameAs(params) {
711
+ var _a;
705
712
  return __awaiter(this, void 0, void 0, function* () {
706
- const query = this.actionModel.find({ 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq } })
707
- .select({ _id: 1, actionStatus: 1 })
713
+ const query = this.actionModel.find(Object.assign({ 'sameAs.id': { $exists: true, $eq: params.sameAs.id.$eq } }, (typeof ((_a = params.purpose) === null || _a === void 0 ? void 0 : _a.id.$eq) === 'string')
714
+ ? { 'purpose.id': { $exists: true, $eq: params.purpose.id.$eq } }
715
+ : undefined))
716
+ .select({ _id: 1, actionStatus: 1, error: 1 })
708
717
  .limit(1);
709
718
  return query.exec()
710
719
  .then((docs) => docs.map((doc) => doc.toObject()));
@@ -58,7 +58,10 @@ function call(params) {
58
58
  catch (error) {
59
59
  let throwsError = true;
60
60
  // アクションが存在すればタスクを実行済扱いにする
61
- const action = (yield actionRepo.searchBySameAs({ sameAs: { id: { $eq: params.id } } })).shift();
61
+ const action = (yield actionRepo.searchBySameAs({
62
+ sameAs: { id: { $eq: params.id } },
63
+ purpose: { id: { $eq: params.data.purpose.id } }
64
+ })).shift();
62
65
  if (typeof (action === null || action === void 0 ? void 0 : action.id) === 'string') {
63
66
  throwsError = false;
64
67
  }
package/package.json CHANGED
@@ -110,5 +110,5 @@
110
110
  "postversion": "git push origin --tags",
111
111
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
112
112
  },
113
- "version": "21.30.0-alpha.3"
113
+ "version": "21.30.0-alpha.4"
114
114
  }
@@ -1,57 +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
- async function main() {
11
- await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
12
-
13
- const actionRepo = await chevre.repository.Action.createInstance(mongoose.connection);
14
-
15
- // tslint:disable-next-line:no-increment-decrement
16
- // tslint:disable-next-line:no-magic-numbers
17
- for (let index = 0; index < 24 * 548; index++) {
18
- const updateResult = await actionRepo.unsetUnnecessaryFields({
19
- filter: {
20
- typeOf: { $eq: chevre.factory.actionType.DeleteAction },
21
- 'object.typeOf': { $exists: true, $eq: chevre.factory.transactionType.PlaceOrder },
22
- startDate: {
23
- $gte: moment()
24
- .add(-(index + 1), 'hours')
25
- .toDate(),
26
- $lte: moment()
27
- .add(-index, 'hours')
28
- .toDate()
29
- }
30
- // _id: { $eq: '65fbb1746e12c17600902282' }
31
- },
32
- $unset: {
33
- 'object._id': 1,
34
- 'object.agent': 1,
35
- 'object.seller': 1,
36
- 'object.object.passportToken': 1,
37
- 'object.object.authorizeActions': 1,
38
- 'object.object.clientUser': 1,
39
- 'object.object.customer': 1,
40
- 'object.object.passport': 1,
41
- 'object.status': 1,
42
- 'object.expires': 1,
43
- 'object.tasksExportationStatus': 1,
44
- 'object.createdAt': 1,
45
- 'object.updatedAt': 1,
46
- 'object.potentialActions': 1,
47
- 'object.result': 1
48
- }
49
- });
50
- console.log('unset processed.', updateResult, -index, 'hours', moment.duration(index, 'hours')
51
- .asDays());
52
- }
53
- }
54
-
55
- main()
56
- .then()
57
- .catch(console.error);