@chevre/domain 22.10.0-alpha.2 → 22.10.0-alpha.3

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,61 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ const NEW_IDENTIFIER = 'DefaultTokenIssuer';
7
+
8
+ // tslint:disable-next-line:max-func-body-length
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const issuerRepo = await chevre.repository.Issuer.createInstance(mongoose.connection);
13
+
14
+ const cursor = issuerRepo.getCursor(
15
+ {
16
+ // 'project.id': { $ne: EXCLUDED_PROJECT_ID }
17
+ },
18
+ {
19
+ _id: 1,
20
+ project: 1,
21
+ identifier: 1,
22
+ url: 1,
23
+ name: 1
24
+ }
25
+ );
26
+ console.log('docs found');
27
+
28
+ let i = 0;
29
+ let updateCount = 0;
30
+ await cursor.eachAsync(async (doc) => {
31
+ i += 1;
32
+ const issuer: chevre.factory.issuer.IIssuer = doc.toObject();
33
+
34
+ const alreadyMigrated = issuer.identifier === NEW_IDENTIFIER;
35
+
36
+ if (alreadyMigrated) {
37
+ console.log(
38
+ 'already migrated.',
39
+ issuer.id, issuer.project.id, issuer.identifier, i);
40
+ } else {
41
+ console.log(
42
+ 'updating...',
43
+ issuer.id, issuer.project.id, issuer.identifier, i);
44
+ await issuerRepo.renameIssuerIdentifier({
45
+ id: issuer.id,
46
+ identifier: NEW_IDENTIFIER
47
+ });
48
+ updateCount += 1;
49
+ console.log(
50
+ 'updated.',
51
+ issuer.id, issuer.project.id, issuer.identifier, i);
52
+ }
53
+ });
54
+
55
+ console.log(i, 'docs checked');
56
+ console.log(updateCount, 'docs updated');
57
+ }
58
+
59
+ main()
60
+ .then()
61
+ .catch(console.error);
@@ -13,6 +13,9 @@ export declare class IssuerRepo {
13
13
  saveIssuer(params: IIssuer): Promise<{
14
14
  id: string;
15
15
  }>;
16
+ renameIssuerIdentifier(params: Pick<IIssuer, 'id' | 'identifier'>): Promise<{
17
+ id: string;
18
+ }>;
16
19
  projectPublicFields(params: ISearchConditions): Promise<Pick<IIssuer, 'id' | 'identifier' | 'project' | 'name' | 'url'>[]>;
17
20
  findById(params: {
18
21
  id: string;
@@ -69,6 +69,20 @@ class IssuerRepo {
69
69
  return { id: savedId };
70
70
  });
71
71
  }
72
+ renameIssuerIdentifier(params) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ let savedId;
75
+ let doc;
76
+ const { id } = params, updateFields = __rest(params, ["id"]);
77
+ doc = yield this.issuerModel.findOneAndUpdate({ _id: { $eq: params.id } }, { $set: updateFields }, { upsert: false, new: true, projection: { _id: 1 } })
78
+ .exec();
79
+ savedId = params.id;
80
+ if (doc === null) {
81
+ throw new factory.errors.NotFound(this.issuerModel.modelName);
82
+ }
83
+ return { id: savedId };
84
+ });
85
+ }
72
86
  projectPublicFields(params) {
73
87
  return __awaiter(this, void 0, void 0, function* () {
74
88
  var _a;
@@ -7,6 +7,9 @@ declare function createReserveTransactionStartParams(params: {
7
7
  acceptedOffers: factory.assetTransaction.reserve.IAcceptedTicketOfferWithoutDetail[];
8
8
  event: {
9
9
  id: string;
10
+ offers?: {
11
+ offeredBy?: string;
12
+ };
10
13
  };
11
14
  broker?: factory.reservation.IBroker<factory.reservationType>;
12
15
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'expires' | 'seller'>;
@@ -8,7 +8,7 @@ exports.responseBody2acceptedOffers4result = responseBody2acceptedOffers4result;
8
8
  const moment = require("moment");
9
9
  const factory = require("../../../../factory");
10
10
  function createReserveTransactionStartParams(params) {
11
- var _a;
11
+ var _a, _b;
12
12
  const { transaction, transactionNumber } = params;
13
13
  const { seller } = transaction;
14
14
  const acceptedTicketOffersWithoutDetail = (Array.isArray(params.acceptedOffers))
@@ -48,7 +48,8 @@ function createReserveTransactionStartParams(params) {
48
48
  // }
49
49
  // ]
50
50
  };
51
- const object = Object.assign({ acceptedOffer: acceptedTicketOffersWithoutDetail, reservationFor: { id: params.event.id } }, (params.broker !== undefined) ? { broker: params.broker } : undefined);
51
+ const offeredByToken = (_b = params.event.offers) === null || _b === void 0 ? void 0 : _b.offeredBy;
52
+ const object = Object.assign({ acceptedOffer: acceptedTicketOffersWithoutDetail, reservationFor: Object.assign({ id: params.event.id }, (typeof offeredByToken === 'string') ? { offers: { offeredBy: offeredByToken } } : undefined) }, (params.broker !== undefined) ? { broker: params.broker } : undefined);
52
53
  return {
53
54
  project: { typeOf: factory.organizationType.Project, id: params.project.id },
54
55
  typeOf: factory.assetTransactionType.Reserve,
@@ -24,7 +24,11 @@ import type { TicketRepo } from '../../../../repo/ticket';
24
24
  import { IResultAcceptedOffer } from './factory';
25
25
  declare function processStartReserve4chevre(params: {
26
26
  acceptedOffers: factory.assetTransaction.reserve.IAcceptedTicketOfferWithoutDetail[];
27
- event: Pick<IMinimizedIndividualEvent<factory.eventType.ScreeningEvent>, 'id'>;
27
+ event: Pick<IMinimizedIndividualEvent<factory.eventType.ScreeningEvent>, 'id'> & {
28
+ offers?: {
29
+ offeredBy?: string;
30
+ };
31
+ };
28
32
  broker?: factory.reservation.IBroker<factory.reservationType>;
29
33
  transactionNumber: string;
30
34
  transaction: Pick<factory.transaction.ITransaction<factory.transactionType.PlaceOrder>, 'agent' | 'expires' | 'id' | 'project' | 'seller' | 'typeOf'>;
@@ -82,7 +82,7 @@ function authorize(params, options) {
82
82
  }
83
83
  function validateCreateRequest(params) {
84
84
  return (repos) => __awaiter(this, void 0, void 0, function* () {
85
- var _a, _b;
85
+ var _a, _b, _c;
86
86
  const transaction = yield repos.transaction.projectFieldsInProgressById({
87
87
  typeOf: factory.transactionType.PlaceOrder,
88
88
  id: params.transaction.id
@@ -98,14 +98,8 @@ function validateCreateRequest(params) {
98
98
  if (typeof ((_b = params.object.reservationFor) === null || _b === void 0 ? void 0 : _b.id) !== 'string' || params.object.reservationFor.id.length === 0) {
99
99
  throw new factory.errors.ArgumentNull('object.reservationFor.id');
100
100
  }
101
- // discontinue preSearchedEvent(2024-07-17~)
102
- // const event = await repos.event.findMinimizedIndividualEventById<factory.eventType.ScreeningEvent>({
103
- // id: params.object.reservationFor.id
104
- // });
105
- const event = {
106
- id: params.object.reservationFor.id,
107
- typeOf: factory.eventType.ScreeningEvent // ひとまずfix(2024-07-17~)
108
- };
101
+ const offeredByToken = (_c = params.object.reservationFor.offers) === null || _c === void 0 ? void 0 : _c.offeredBy;
102
+ const event = Object.assign({ id: params.object.reservationFor.id, typeOf: factory.eventType.ScreeningEvent }, (typeof offeredByToken === 'string') ? { offers: { offeredBy: offeredByToken } } : undefined);
109
103
  return { transaction, event };
110
104
  });
111
105
  }
package/package.json CHANGED
@@ -113,5 +113,5 @@
113
113
  "postversion": "git push origin --tags",
114
114
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
115
115
  },
116
- "version": "22.10.0-alpha.2"
116
+ "version": "22.10.0-alpha.3"
117
117
  }