@chevre/domain 23.2.0-alpha.23 → 23.2.0-alpha.25

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,43 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+ import { chevre } from '../../../../lib/index';
4
+
5
+ const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
6
+
7
+ async function main() {
8
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
9
+
10
+ const movieTheaterRepo = await chevre.repository.place.MovieTheater.createInstance(mongoose.connection);
11
+
12
+ const result = await movieTheaterRepo.upsertMovieTheatersByBranchCode(
13
+ [
14
+ {
15
+ $set: {
16
+ branchCode: 'SAMPLE',
17
+ name: { ja: 'sampleNameJa', en: 'from samples' },
18
+ additionalProperty: [],
19
+ kanaName: '',
20
+ telephone: '',
21
+ offers: {
22
+ typeOf: chevre.factory.offerType.Offer,
23
+ eligibleQuantity: { maxValue: 6, unitCode: chevre.factory.unitCode.C62, typeOf: 'QuantitativeValue' },
24
+ availabilityEndsGraceTime: { value: 6, unitCode: chevre.factory.unitCode.Sec, typeOf: 'QuantitativeValue' },
25
+ availabilityStartsGraceTime: { value: 6, unitCode: chevre.factory.unitCode.Day, typeOf: 'QuantitativeValue' },
26
+ availabilityEndsGraceTimeOnPOS: { value: 6, unitCode: chevre.factory.unitCode.Sec, typeOf: 'QuantitativeValue' },
27
+ availabilityStartsGraceTimeOnPOS: { value: 6, unitCode: chevre.factory.unitCode.Day, typeOf: 'QuantitativeValue' }
28
+ }
29
+
30
+ }
31
+ }
32
+ ],
33
+ {
34
+ project: { id: project.id },
35
+ sellerId: '59d20831e53ebc2b4e774466'
36
+ }
37
+ );
38
+ console.log(result);
39
+ }
40
+
41
+ main()
42
+ .then(console.log)
43
+ .catch(console.error);
@@ -1,3 +1,4 @@
1
+ import type { BulkWriteResult } from 'mongodb';
1
2
  import type { Connection, FilterQuery } from 'mongoose';
2
3
  import * as factory from '../../factory';
3
4
  import { IDocType } from '../mongoose/schemas/civicStructure';
@@ -5,10 +6,23 @@ export type IScreeningRoomFoundByBranchCode = Pick<factory.place.screeningRoom.I
5
6
  export type IMovieTheaterIncludingScreeningRooms = Pick<factory.place.movieTheater.IPlace, 'additionalProperty' | 'branchCode' | 'kanaName' | 'name' | 'offers' | 'parentOrganization' | 'project' | 'telephone' | 'typeOf'> & {
6
7
  containsPlace: factory.place.screeningRoom.IPlace[];
7
8
  };
8
- type IKeyOfProjection = keyof factory.place.movieTheater.IPlace | 'offers.availabilityStartsGraceTime' | 'offers.availabilityEndsGraceTime';
9
+ type IKeyOfProjection = keyof factory.place.movieTheater.IPlace | 'offers.typeOf' | 'offers.eligibleQuantity' | 'offers.availabilityStartsGraceTime' | 'offers.availabilityEndsGraceTime';
9
10
  type IMovieTheaterPublicAttributes = Pick<factory.place.movieTheater.IPlace, 'additionalProperty' | 'branchCode' | 'id' | 'kanaName' | 'name' | 'parentOrganization' | 'project' | 'telephone' | 'typeOf' | 'url'> & {
10
11
  offers?: Pick<factory.place.movieTheater.IOffer, 'availabilityEndsGraceTime' | 'availabilityStartsGraceTime'>;
11
12
  };
13
+ type IUpsertingMovieTheater = Pick<factory.place.movieTheater.IPlace, 'additionalProperty' | 'branchCode' | 'kanaName' | 'name' | 'offers' | 'telephone' | 'url'> & {
14
+ hasEntranceGate?: never;
15
+ hasPOS?: never;
16
+ };
17
+ interface IUpsertOptions {
18
+ project: {
19
+ id: string;
20
+ };
21
+ /**
22
+ * 施設の所属販売者ID
23
+ */
24
+ sellerId: string;
25
+ }
12
26
  /**
13
27
  * 施設リポジトリ
14
28
  */
@@ -25,6 +39,18 @@ export declare class MovieTheaterRepo {
25
39
  id: string;
26
40
  }>;
27
41
  saveMovieTheaterByBranchCode4coa(params: IMovieTheaterIncludingScreeningRooms): Promise<void>;
42
+ /**
43
+ * コードをキーにして冪等作成
44
+ * 2026-01-13~
45
+ */
46
+ upsertMovieTheatersByBranchCode(params: {
47
+ $set: IUpsertingMovieTheater;
48
+ $unset?: {
49
+ [key in keyof IUpsertingMovieTheater]?: 1;
50
+ };
51
+ }[], options: IUpsertOptions): Promise<{
52
+ bulkWriteResult?: BulkWriteResult;
53
+ }>;
28
54
  /**
29
55
  * 施設のpublic属性検索
30
56
  * 2024-09-18~
@@ -27,6 +27,8 @@ const civicStructure_1 = require("../mongoose/schemas/civicStructure");
27
27
  const AVAILABLE_PROJECT_FIELDS = [
28
28
  'additionalProperty', 'branchCode', 'hasEntranceGate', 'kanaName', 'name',
29
29
  'offers', 'parentOrganization', 'project', 'telephone', 'typeOf', 'url',
30
+ 'offers.typeOf',
31
+ 'offers.eligibleQuantity',
30
32
  'offers.availabilityStartsGraceTime',
31
33
  'offers.availabilityEndsGraceTime'
32
34
  ];
@@ -39,7 +41,7 @@ class MovieTheaterRepo {
39
41
  }
40
42
  // tslint:disable-next-line:max-func-body-length
41
43
  static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params) {
42
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
44
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
43
45
  const andConditions = [{ typeOf: { $eq: factory.placeType.MovieTheater } }];
44
46
  const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
45
47
  if (typeof projectIdEq === 'string') {
@@ -73,11 +75,15 @@ class MovieTheaterRepo {
73
75
  ]
74
76
  });
75
77
  }
76
- const parentOrganizationIdEq = (_h = (_g = params.parentOrganization) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$eq;
78
+ const sellerIdEq = (_h = (_g = params.seller) === null || _g === void 0 ? void 0 : _g.id) === null || _h === void 0 ? void 0 : _h.$eq;
79
+ if (typeof sellerIdEq === 'string') {
80
+ andConditions.push({ 'parentOrganization.id': { $exists: true, $eq: sellerIdEq } });
81
+ }
82
+ const parentOrganizationIdEq = (_k = (_j = params.parentOrganization) === null || _j === void 0 ? void 0 : _j.id) === null || _k === void 0 ? void 0 : _k.$eq;
77
83
  if (typeof parentOrganizationIdEq === 'string') {
78
84
  andConditions.push({ 'parentOrganization.id': { $exists: true, $eq: parentOrganizationIdEq } });
79
85
  }
80
- const additionalPropertyElemMatch = (_j = params.additionalProperty) === null || _j === void 0 ? void 0 : _j.$elemMatch;
86
+ const additionalPropertyElemMatch = (_l = params.additionalProperty) === null || _l === void 0 ? void 0 : _l.$elemMatch;
81
87
  if (additionalPropertyElemMatch !== undefined && additionalPropertyElemMatch !== null) {
82
88
  andConditions.push({
83
89
  additionalProperty: {
@@ -132,6 +138,50 @@ class MovieTheaterRepo {
132
138
  }
133
139
  });
134
140
  }
141
+ /**
142
+ * コードをキーにして冪等作成
143
+ * 2026-01-13~
144
+ */
145
+ upsertMovieTheatersByBranchCode(params, options) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ const { project, sellerId } = options;
148
+ const bulkWriteOps = [];
149
+ if (Array.isArray(params)) {
150
+ params.forEach(({ $set, $unset }) => {
151
+ const { branchCode, hasEntranceGate, hasPOS } = $set, // 入場ゲート,POSを決して編集しないように
152
+ setFields = __rest($set, ["branchCode", "hasEntranceGate", "hasPOS"]);
153
+ if (typeof branchCode !== 'string' || branchCode === '') {
154
+ throw new factory.errors.ArgumentNull('branchCode');
155
+ }
156
+ // リソースのユニークネスを保証するfilter
157
+ const filter = {
158
+ typeOf: { $eq: factory.placeType.MovieTheater },
159
+ 'project.id': { $eq: project.id },
160
+ branchCode: { $eq: branchCode }
161
+ };
162
+ const initialMovieTheater = {
163
+ typeOf: factory.placeType.MovieTheater,
164
+ project: { id: project.id, typeOf: factory.organizationType.Project },
165
+ branchCode,
166
+ parentOrganization: { id: sellerId, typeOf: factory.organizationType.Corporation }
167
+ };
168
+ const setOnInsert = initialMovieTheater;
169
+ const update = Object.assign({ $setOnInsert: setOnInsert, $set: setFields }, ($unset !== undefined) ? { $unset } : undefined);
170
+ const updateOne = {
171
+ filter,
172
+ update,
173
+ upsert: true
174
+ };
175
+ bulkWriteOps.push({ updateOne });
176
+ });
177
+ }
178
+ if (bulkWriteOps.length > 0) {
179
+ const bulkWriteResult = yield this.civicStructureModel.bulkWrite(bulkWriteOps, { ordered: false });
180
+ return { bulkWriteResult };
181
+ }
182
+ return {};
183
+ });
184
+ }
135
185
  /**
136
186
  * 施設のpublic属性検索
137
187
  * 2024-09-18~
@@ -58,6 +58,7 @@ function addOffers2Seat(params) {
58
58
  * イベントに対する座席オファーを検索する
59
59
  */
60
60
  function searchEventSeatOffersWithPaging(params) {
61
+ // tslint:disable-next-line:max-func-body-length
61
62
  return (repos) => __awaiter(this, void 0, void 0, function* () {
62
63
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
63
64
  const { useDefaultSection } = params.options;
@@ -115,14 +116,26 @@ function searchEventSeatOffersWithPaging(params) {
115
116
  };
116
117
  })
117
118
  });
118
- offers = seats.map((seat, index) => {
119
- return addOffers2Seat({
120
- seat,
121
- availability: (typeof availabilities[index] === 'string')
122
- ? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
123
- : factory.itemAvailability.InStock,
124
- priceSpecs: [] // priceSpecsをレスポンスから廃止(2024-12-22~)
125
- });
119
+ offers = seats.map(({ branchCode, name, containedInPlace, seatingType }, index) => {
120
+ // デフォルトセクション指定の場合、first elementのみセクションコードを含める
121
+ const includeSectionCode = !useDefaultSection
122
+ || (useDefaultSection && index === 0);
123
+ return Object.assign({ branchCode,
124
+ name,
125
+ seatingType,
126
+ // ...seat,
127
+ offers: [{
128
+ availability: (typeof availabilities[index] === 'string')
129
+ ? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
130
+ : factory.itemAvailability.InStock
131
+ }] }, (includeSectionCode) ? { containedInPlace } : undefined);
132
+ // return addOffers2Seat({
133
+ // seat,
134
+ // availability: (typeof availabilities[index] === 'string')
135
+ // ? factory.itemAvailability.OutOfStock // ホルダーが存在すればOutOfStock
136
+ // : factory.itemAvailability.InStock,
137
+ // priceSpecs: [] // priceSpecsをレスポンスから廃止(2024-12-22~)
138
+ // });
126
139
  });
127
140
  }
128
141
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "5.4.0-alpha.13",
14
+ "@chevre/factory": "5.4.0-alpha.14",
15
15
  "@cinerino/sdk": "12.12.1",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.4.0-alpha.1",
@@ -116,5 +116,5 @@
116
116
  "postversion": "git push origin --tags",
117
117
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
118
118
  },
119
- "version": "23.2.0-alpha.23"
119
+ "version": "23.2.0-alpha.25"
120
120
  }