@chevre/domain 23.2.0-alpha.18 → 23.2.0-alpha.19

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,68 @@
1
+ // tslint:disable:no-console
2
+ // import * as redis from 'redis';
3
+ import * as mongoose from 'mongoose';
4
+
5
+ import { chevre } from '../../../../lib/index';
6
+
7
+ const project = { typeOf: chevre.factory.organizationType.Project, id: String(process.env.PROJECT_ID) };
8
+
9
+ async function main() {
10
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
+
12
+ const entranceGateRepo =
13
+ await chevre.repository.place.EntranceGate.createInstance(mongoose.connection, { id: '5bfb841d5a78d7948369979a' });
14
+
15
+ const gates = await entranceGateRepo.findEntranceGates({
16
+ limit: 10,
17
+ page: 1,
18
+ project: { id: { $eq: project.id } }
19
+ });
20
+ console.log(gates);
21
+ console.log(gates.length);
22
+
23
+ let result = await entranceGateRepo.addEntranceGatesByIdentifierIfNotExist(
24
+ [
25
+ {
26
+ $set: {
27
+ identifier: 'sample001',
28
+ name: { ja: 'gateNameJa' }
29
+ }
30
+ }
31
+ ],
32
+ {
33
+ project: { id: project.id }
34
+ }
35
+ );
36
+ console.log(result);
37
+
38
+ result = await entranceGateRepo.updateEntranceGatesByIdentifier(
39
+ [
40
+ {
41
+ $set: {
42
+ identifier: 'sample001',
43
+ name: { ja: 'gateNameJaUpdated' }
44
+ }
45
+ }
46
+ ],
47
+ {
48
+ project: { id: project.id }
49
+ }
50
+ );
51
+ console.log(result);
52
+
53
+ result = await entranceGateRepo.deleteEntranceGatesByIdentifier(
54
+ [
55
+ {
56
+ identifier: 'sample001'
57
+ }
58
+ ],
59
+ {
60
+ project: { id: project.id }
61
+ }
62
+ );
63
+ console.log(result);
64
+ }
65
+
66
+ main()
67
+ .then(console.log)
68
+ .catch(console.error);
@@ -0,0 +1,82 @@
1
+ // tslint:disable:no-console
2
+ import * as mongoose from 'mongoose';
3
+
4
+ import { chevre } from '../../../../lib/index';
5
+
6
+ // const project = { id: String(process.env.PROJECT_ID) };
7
+ // const excludedProject = { id: String(process.env.EXCLUDED_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 movieTheaterRepo = await chevre.repository.place.MovieTheater.createInstance(mongoose.connection);
14
+
15
+ const cursor = movieTheaterRepo.getCursor(
16
+ {
17
+ // 'project.id': {
18
+ // $ne: 'sskts-development',
19
+ // $eq: 'ttts-development'
20
+ // }
21
+ // _id: { $eq: '67de46777ec0510590b68922' }
22
+ },
23
+ {
24
+ // _id: 1,
25
+ // about: 1,
26
+ // project: 1,
27
+ // typeOf: 1,
28
+ // issuedBy: 1
29
+ }
30
+ );
31
+ console.log('docs found');
32
+
33
+ let i = 0;
34
+ let updateCount = 0;
35
+ await cursor.eachAsync(async (doc) => {
36
+ const movieTheater: chevre.factory.place.movieTheater.IPlace = doc.toObject();
37
+
38
+ i += 1;
39
+ const { hasEntranceGate } = movieTheater;
40
+ if (!Array.isArray(hasEntranceGate)) {
41
+ throw new Error('hasEntranceGateLength must be an array');
42
+ }
43
+ const hasEntranceGateLength = hasEntranceGate?.length;
44
+ if (typeof hasEntranceGateLength !== 'number') {
45
+ throw new Error('hasEntranceGateLength undefined');
46
+ }
47
+ const uniqueIdentifiersByMovieTheater = hasEntranceGate.map(({ identifier }) => identifier);
48
+
49
+ const entranceGateRepo = await chevre.repository.place.EntranceGate.createInstance(mongoose.connection, { id: movieTheater.id });
50
+ const entranceGates = await entranceGateRepo.findEntranceGates({
51
+ limit: 100,
52
+ page: 1,
53
+ project: { id: { $eq: movieTheater.project.id } }
54
+ });
55
+ const entranceGateCount = entranceGates.length;
56
+ const uniqueIdentifiers = entranceGates.map(({ identifier }) => identifier);
57
+
58
+ const countMatched = hasEntranceGateLength === entranceGateCount;
59
+ const identifiersMatched = uniqueIdentifiersByMovieTheater.length === uniqueIdentifiers.length
60
+ && uniqueIdentifiersByMovieTheater.every((identifier) => uniqueIdentifiers.includes(identifier));
61
+ console.log(uniqueIdentifiersByMovieTheater, uniqueIdentifiers);
62
+
63
+ console.log(
64
+ 'checking...', movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
65
+ if (countMatched && identifiersMatched) {
66
+ console.log(
67
+ 'matched.', movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
68
+ } else {
69
+ updateCount += 1;
70
+ console.log(
71
+ 'unmatched.',
72
+ movieTheater.project.id, movieTheater.id, hasEntranceGateLength, entranceGateCount, i);
73
+ }
74
+ });
75
+
76
+ console.log(i, 'docs checked');
77
+ console.log(updateCount, 'docs updated');
78
+ }
79
+
80
+ main()
81
+ .then()
82
+ .catch(console.error);
@@ -15,7 +15,8 @@ async function main() {
15
15
  chevre.factory.role.organizationRole.RoleName.TicketClerk
16
16
  ];
17
17
  const permissions = [
18
- 'admin.sellers.rooms.read'
18
+ 'admin.sellers.rooms.read',
19
+ 'admin.sellers.seatSections.read'
19
20
  ];
20
21
  for (const roleName of roleNames) {
21
22
  for (const permission of permissions) {
@@ -15,7 +15,8 @@ async function main() {
15
15
  // chevre.factory.role.organizationRole.RoleName.TicketClerk
16
16
  ];
17
17
  const permissions = [
18
- 'admin.sellers.rooms.*'
18
+ 'admin.sellers.rooms.*',
19
+ 'admin.sellers.seatSections.*'
19
20
  ];
20
21
  for (const roleName of roleNames) {
21
22
  for (const permission of permissions) {
@@ -1,3 +1,4 @@
1
+ import type { BulkWriteResult } from 'mongodb';
1
2
  import { Connection } from 'mongoose';
2
3
  import * as factory from '../../factory';
3
4
  /**
@@ -10,6 +11,12 @@ interface IOperator {
10
11
  id: string;
11
12
  }
12
13
  type IEntranceGate = Pick<factory.place.movieTheater.IEntranceGate, 'identifier' | 'name'>;
14
+ type ICreatingEntranceGate = Pick<factory.place.movieTheater.IEntranceGate, 'identifier' | 'name'>;
15
+ interface IUpdateOptions {
16
+ project: {
17
+ id: string;
18
+ };
19
+ }
13
20
  /**
14
21
  * 施設の入場ゲートリポジトリ
15
22
  */
@@ -26,5 +33,23 @@ export declare class EntranceGateRepo {
26
33
  };
27
34
  };
28
35
  }): Promise<IEntranceGate[]>;
36
+ addEntranceGatesByIdentifierIfNotExist(params: {
37
+ $set: ICreatingEntranceGate;
38
+ }[], options: IUpdateOptions): Promise<{
39
+ bulkWriteResult?: BulkWriteResult;
40
+ }>;
41
+ updateEntranceGatesByIdentifier(params: {
42
+ $set: ICreatingEntranceGate;
43
+ }[], options: IUpdateOptions): Promise<{
44
+ bulkWriteResult?: BulkWriteResult;
45
+ }>;
46
+ deleteEntranceGatesByIdentifier(params: {
47
+ /**
48
+ * ゲートコード
49
+ */
50
+ identifier: string;
51
+ }[], options: IUpdateOptions): Promise<{
52
+ bulkWriteResult?: BulkWriteResult;
53
+ }>;
29
54
  }
30
55
  export {};
@@ -58,5 +58,98 @@ class EntranceGateRepo {
58
58
  .exec();
59
59
  });
60
60
  }
61
+ addEntranceGatesByIdentifierIfNotExist(params, options) {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ const { project } = options;
64
+ const movieTheaterId = new mongoose_1.Types.ObjectId(this.operator.id);
65
+ const bulkWriteOps = [];
66
+ if (Array.isArray(params)) {
67
+ params.forEach(({ $set }) => {
68
+ const { identifier, name } = $set;
69
+ // ゲートを含まない施設があれば
70
+ const filter = {
71
+ 'project.id': { $eq: project.id },
72
+ _id: { $eq: movieTheaterId },
73
+ 'hasEntranceGate.identifier': { $ne: identifier }
74
+ };
75
+ const creatingEntranceGate = Object.assign({ identifier, typeOf: factory.placeType.Place }, (typeof (name === null || name === void 0 ? void 0 : name.ja) === 'string' || typeof (name === null || name === void 0 ? void 0 : name.en) === 'string') ? { name } : undefined);
76
+ // ゲートをpush
77
+ const update = {
78
+ $push: { hasEntranceGate: creatingEntranceGate }
79
+ };
80
+ const updateOne = { filter, update };
81
+ bulkWriteOps.push({ updateOne });
82
+ });
83
+ }
84
+ if (bulkWriteOps.length > 0) {
85
+ const bulkWriteResult = yield this.civicStructureModel.bulkWrite(bulkWriteOps, { ordered: false });
86
+ return { bulkWriteResult };
87
+ }
88
+ return {};
89
+ });
90
+ }
91
+ updateEntranceGatesByIdentifier(params, options) {
92
+ return __awaiter(this, void 0, void 0, function* () {
93
+ const { project } = options;
94
+ const movieTheaterId = new mongoose_1.Types.ObjectId(this.operator.id);
95
+ const bulkWriteOps = [];
96
+ if (Array.isArray(params)) {
97
+ params.forEach(({ $set }) => {
98
+ const { identifier, name } = $set;
99
+ // ゲートを含む施設があれば
100
+ const filter = {
101
+ 'project.id': { $eq: project.id },
102
+ _id: { $eq: movieTheaterId },
103
+ 'hasEntranceGate.identifier': { $eq: identifier }
104
+ };
105
+ const updatingEntranceGate = Object.assign({ identifier, typeOf: factory.placeType.Place }, (typeof (name === null || name === void 0 ? void 0 : name.ja) === 'string' || typeof (name === null || name === void 0 ? void 0 : name.en) === 'string') ? { name } : undefined);
106
+ const update = {
107
+ $set: {
108
+ 'hasEntranceGate.$[entranceGate]': updatingEntranceGate
109
+ }
110
+ };
111
+ // ゲートコードで$set
112
+ const arrayFilters = [
113
+ { 'entranceGate.identifier': { $eq: identifier } }
114
+ ];
115
+ const updateOne = { filter, update, arrayFilters };
116
+ bulkWriteOps.push({ updateOne });
117
+ });
118
+ }
119
+ if (bulkWriteOps.length > 0) {
120
+ const bulkWriteResult = yield this.civicStructureModel.bulkWrite(bulkWriteOps, { ordered: false });
121
+ return { bulkWriteResult };
122
+ }
123
+ return {};
124
+ });
125
+ }
126
+ deleteEntranceGatesByIdentifier(params, options) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ const { project } = options;
129
+ const movieTheaterId = new mongoose_1.Types.ObjectId(this.operator.id);
130
+ const bulkWriteOps = [];
131
+ if (Array.isArray(params)) {
132
+ params.forEach(({ identifier }) => {
133
+ // ゲートを含む施設があれば
134
+ const filter = {
135
+ 'project.id': { $eq: project.id },
136
+ _id: { $eq: movieTheaterId },
137
+ 'hasEntranceGate.identifier': { $eq: identifier }
138
+ };
139
+ // ゲートをpull
140
+ const update = {
141
+ $pull: { hasEntranceGate: { identifier: { $eq: identifier } } }
142
+ };
143
+ const updateOne = { filter, update };
144
+ bulkWriteOps.push({ updateOne });
145
+ });
146
+ }
147
+ if (bulkWriteOps.length > 0) {
148
+ const bulkWriteResult = yield this.civicStructureModel.bulkWrite(bulkWriteOps, { ordered: false });
149
+ return { bulkWriteResult };
150
+ }
151
+ return {};
152
+ });
153
+ }
61
154
  }
62
155
  exports.EntranceGateRepo = EntranceGateRepo;
package/package.json CHANGED
@@ -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.18"
119
+ "version": "23.2.0-alpha.19"
120
120
  }