@chevre/domain 20.1.0-alpha.18 → 20.1.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 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);
13
+
14
+ const eventRepo = new chevre.repository.Event(mongoose.connection);
15
+
16
+ const cursor = eventRepo.getCursor(
17
+ {
18
+ // 'project.id': { $eq: project.id },
19
+ 'project.id': { $ne: EXCLUDED_PROJECT_ID },
20
+ typeOf: { $eq: chevre.factory.eventType.ScreeningEventSeries }
21
+ // typeOf: { $eq: chevre.factory.eventType.ScreeningEvent },
22
+ // startDate: {
23
+ // $gte: moment()
24
+ // .add(-1, 'month')
25
+ // .toDate()
26
+ // }
27
+ // _id: { $eq: 'al6aff83w' }
28
+ },
29
+ {
30
+ // _id: 1,
31
+ }
32
+ );
33
+ console.log('events found');
34
+
35
+ const additionalPropertyNames: string[] = [];
36
+ const projectIds: string[] = [];
37
+
38
+ let i = 0;
39
+ const updateCount = 0;
40
+ await cursor.eachAsync(async (doc) => {
41
+ i += 1;
42
+ const event: chevre.factory.event.screeningEventSeries.IEvent = doc.toObject();
43
+
44
+ const additionalPropertyNamesOnEvent = event.additionalProperty?.map((p) => p.name);
45
+ if (Array.isArray(additionalPropertyNamesOnEvent) && additionalPropertyNamesOnEvent.length > 0) {
46
+ console.log(additionalPropertyNamesOnEvent.length, 'additionalPropertyNamesOnEvent found', event.project.id);
47
+ additionalPropertyNames.push(...additionalPropertyNamesOnEvent);
48
+ projectIds.push(event.project.id);
49
+ additionalPropertyNamesOnEvent.forEach((name) => {
50
+ if (!name.match(/^[a-zA-Z]*$/)) {
51
+ throw new Error(`not matched ${event.project.id} ${event.id}`);
52
+ }
53
+ // tslint:disable-next-line:no-magic-numbers
54
+ if (name.length < 8) {
55
+ throw new Error(`length matched ${event.project.id} ${event.id} ${name}`);
56
+ }
57
+ });
58
+ }
59
+ });
60
+ console.log(i, 'events checked');
61
+ console.log(updateCount, 'events updated');
62
+ console.log([...new Set(additionalPropertyNames)]);
63
+ console.log([...new Set(projectIds)]);
64
+ }
65
+
66
+ main()
67
+ .then()
68
+ .catch(console.error);
@@ -0,0 +1,35 @@
1
+ import { Connection } from 'mongoose';
2
+ import * as factory from '../factory';
3
+ /**
4
+ * 追加特性名称リポジトリ
5
+ */
6
+ export declare class MongoRepository {
7
+ private readonly additionalPropertyNameModel;
8
+ constructor(connection: Connection);
9
+ static CREATE_MONGO_CONDITIONS(params: factory.categoryCode.ISearchConditions): any[];
10
+ /**
11
+ * 検索
12
+ */
13
+ search(params: factory.categoryCode.ISearchConditions): Promise<factory.categoryCode.ICategoryCode[]>;
14
+ findById(params: {
15
+ id: string;
16
+ }): Promise<factory.categoryCode.ICategoryCode>;
17
+ save(params: {
18
+ id?: string;
19
+ attributes: factory.categoryCode.ICategoryCode;
20
+ }): Promise<factory.categoryCode.ICategoryCode>;
21
+ /**
22
+ * 削除する
23
+ */
24
+ deleteById(params: {
25
+ id: string;
26
+ }): Promise<void>;
27
+ /**
28
+ * プロジェクト指定で削除する
29
+ */
30
+ deleteByProject(params: {
31
+ project: {
32
+ id: string;
33
+ };
34
+ }): Promise<void>;
35
+ }
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.MongoRepository = void 0;
24
+ const additionalPropertyName_1 = require("./mongoose/model/additionalPropertyName");
25
+ const factory = require("../factory");
26
+ /**
27
+ * 追加特性名称リポジトリ
28
+ */
29
+ class MongoRepository {
30
+ constructor(connection) {
31
+ this.additionalPropertyNameModel = connection.model(additionalPropertyName_1.modelName);
32
+ }
33
+ // tslint:disable-next-line:cyclomatic-complexity max-func-body-length
34
+ static CREATE_MONGO_CONDITIONS(params) {
35
+ var _a, _b, _c, _d;
36
+ // MongoDB検索条件
37
+ const andConditions = [];
38
+ // tslint:disable-next-line:no-single-line-block-comment
39
+ /* istanbul ignore else */
40
+ if (params.project !== undefined && params.project !== null) {
41
+ if (params.project.id !== undefined && params.project.id !== null) {
42
+ if (typeof params.project.id.$eq === 'string') {
43
+ andConditions.push({
44
+ 'project.id': {
45
+ $eq: params.project.id.$eq
46
+ }
47
+ });
48
+ }
49
+ }
50
+ }
51
+ // tslint:disable-next-line:no-single-line-block-comment
52
+ /* istanbul ignore else */
53
+ if (params.id !== undefined && params.id !== null) {
54
+ if (typeof params.id.$eq === 'string') {
55
+ andConditions.push({
56
+ _id: {
57
+ $eq: params.id.$eq
58
+ }
59
+ });
60
+ }
61
+ }
62
+ // tslint:disable-next-line:no-single-line-block-comment
63
+ /* istanbul ignore else */
64
+ if (params.name !== undefined && params.name !== null) {
65
+ if (typeof params.name.$regex === 'string' && params.name.$regex.length > 0) {
66
+ andConditions.push({
67
+ $or: [
68
+ {
69
+ 'name.ja': {
70
+ $exists: true,
71
+ $regex: new RegExp(params.name.$regex)
72
+ }
73
+ },
74
+ {
75
+ 'name.en': {
76
+ $exists: true,
77
+ $regex: new RegExp(params.name.$regex)
78
+ }
79
+ }
80
+ ]
81
+ });
82
+ }
83
+ }
84
+ const codeValueEq = (_a = params.codeValue) === null || _a === void 0 ? void 0 : _a.$eq;
85
+ if (typeof codeValueEq === 'string') {
86
+ andConditions.push({
87
+ codeValue: {
88
+ $exists: true,
89
+ $eq: codeValueEq
90
+ }
91
+ });
92
+ }
93
+ const codeValueIn = (_b = params.codeValue) === null || _b === void 0 ? void 0 : _b.$in;
94
+ if (Array.isArray(codeValueIn)) {
95
+ andConditions.push({
96
+ codeValue: {
97
+ $exists: true,
98
+ $in: codeValueIn
99
+ }
100
+ });
101
+ }
102
+ // tslint:disable-next-line:no-single-line-block-comment
103
+ /* istanbul ignore else */
104
+ if (params.inCodeSet !== undefined && params.inCodeSet !== null) {
105
+ if (params.inCodeSet.identifier !== undefined && params.inCodeSet.identifier !== null) {
106
+ if (typeof params.inCodeSet.identifier.$eq === 'string') {
107
+ andConditions.push({
108
+ 'inCodeSet.identifier': {
109
+ $exists: true,
110
+ $eq: params.inCodeSet.identifier.$eq
111
+ }
112
+ });
113
+ }
114
+ }
115
+ }
116
+ const inCodeSetIdentifierIn = (_d = (_c = params.inCodeSet) === null || _c === void 0 ? void 0 : _c.identifier) === null || _d === void 0 ? void 0 : _d.$in;
117
+ if (Array.isArray(inCodeSetIdentifierIn)) {
118
+ andConditions.push({
119
+ 'inCodeSet.identifier': {
120
+ $exists: true,
121
+ $in: inCodeSetIdentifierIn
122
+ }
123
+ });
124
+ }
125
+ return andConditions;
126
+ }
127
+ // public async count(params: factory.categoryCode.ISearchConditions): Promise<number> {
128
+ // const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
129
+ // return this.additionalPropertyNameModel.countDocuments((conditions.length > 0) ? { $and: conditions } : {})
130
+ // .setOptions({ maxTimeMS: 10000 })
131
+ // .exec();
132
+ // }
133
+ /**
134
+ * 検索
135
+ */
136
+ search(params) {
137
+ return __awaiter(this, void 0, void 0, function* () {
138
+ const conditions = MongoRepository.CREATE_MONGO_CONDITIONS(params);
139
+ const query = this.additionalPropertyNameModel.find((conditions.length > 0) ? { $and: conditions } : {}, {
140
+ __v: 0,
141
+ createdAt: 0,
142
+ updatedAt: 0
143
+ });
144
+ if (typeof params.limit === 'number') {
145
+ const page = (typeof params.page === 'number') ? params.page : 1;
146
+ query.limit(params.limit)
147
+ .skip(params.limit * (page - 1));
148
+ }
149
+ // tslint:disable-next-line:no-single-line-block-comment
150
+ /* istanbul ignore else */
151
+ if (params.sort !== undefined) {
152
+ query.sort(params.sort);
153
+ }
154
+ return query.setOptions({ maxTimeMS: 10000 })
155
+ .exec()
156
+ .then((docs) => docs.map((doc) => doc.toObject()));
157
+ });
158
+ }
159
+ findById(params) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ const doc = yield this.additionalPropertyNameModel.findOne({ _id: params.id }, {
162
+ __v: 0,
163
+ createdAt: 0,
164
+ updatedAt: 0
165
+ })
166
+ .exec();
167
+ if (doc === null) {
168
+ throw new factory.errors.NotFound(this.additionalPropertyNameModel.modelName);
169
+ }
170
+ return doc.toObject();
171
+ });
172
+ }
173
+ save(params) {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ let doc;
176
+ if (typeof params.id !== 'string') {
177
+ doc = yield this.additionalPropertyNameModel.create(params.attributes);
178
+ }
179
+ else {
180
+ const _a = params.attributes, { id, codeValue, inCodeSet, project, typeOf } = _a, updateFields = __rest(_a, ["id", "codeValue", "inCodeSet", "project", "typeOf"]);
181
+ doc = yield this.additionalPropertyNameModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
182
+ .exec();
183
+ }
184
+ if (doc === null) {
185
+ throw new factory.errors.NotFound(this.additionalPropertyNameModel.modelName);
186
+ }
187
+ return doc.toObject();
188
+ });
189
+ }
190
+ /**
191
+ * 削除する
192
+ */
193
+ deleteById(params) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ yield this.additionalPropertyNameModel.findOneAndRemove({ _id: params.id })
196
+ .exec();
197
+ });
198
+ }
199
+ /**
200
+ * プロジェクト指定で削除する
201
+ */
202
+ deleteByProject(params) {
203
+ return __awaiter(this, void 0, void 0, function* () {
204
+ yield this.additionalPropertyNameModel.deleteMany({
205
+ 'project.id': { $eq: params.project.id }
206
+ })
207
+ .exec();
208
+ });
209
+ }
210
+ }
211
+ exports.MongoRepository = MongoRepository;
@@ -0,0 +1,7 @@
1
+ import * as mongoose from 'mongoose';
2
+ declare const modelName = "AdditionalPropertyNam";
3
+ /**
4
+ * 追加特性名称スキーマ
5
+ */
6
+ declare const schema: mongoose.Schema<mongoose.Document<any, any, any>, mongoose.Model<mongoose.Document<any, any, any>, any, any>, undefined, {}>;
7
+ export { modelName, schema };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schema = exports.modelName = void 0;
4
+ const mongoose = require("mongoose");
5
+ const modelName = 'AdditionalPropertyNam';
6
+ exports.modelName = modelName;
7
+ const writeConcern = { j: true, w: 'majority', wtimeout: 10000 };
8
+ /**
9
+ * 追加特性名称スキーマ
10
+ */
11
+ const schema = new mongoose.Schema({
12
+ project: mongoose.SchemaTypes.Mixed,
13
+ typeOf: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ codeValue: {
18
+ type: String,
19
+ required: true
20
+ },
21
+ inCodeSet: mongoose.SchemaTypes.Mixed
22
+ }, {
23
+ collection: 'additionalPropertyNames',
24
+ id: true,
25
+ read: 'primaryPreferred',
26
+ writeConcern: writeConcern,
27
+ strict: true,
28
+ useNestedStrict: true,
29
+ timestamps: {
30
+ createdAt: 'createdAt',
31
+ updatedAt: 'updatedAt'
32
+ },
33
+ toJSON: {
34
+ getters: false,
35
+ virtuals: false,
36
+ minimize: false,
37
+ versionKey: false
38
+ },
39
+ toObject: {
40
+ getters: false,
41
+ virtuals: true,
42
+ minimize: false,
43
+ versionKey: false
44
+ }
45
+ });
46
+ exports.schema = schema;
47
+ schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' });
48
+ schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' });
49
+ schema.index({ codeValue: 1 }, { name: 'searchByCodeValue' });
50
+ schema.index({ 'project.id': 1, codeValue: 1 }, {
51
+ name: 'searchByProjectId'
52
+ });
53
+ schema.index({ 'inCodeSet.identifier': 1, codeValue: 1 }, {
54
+ name: 'searchByInCodeSetIdentifier',
55
+ partialFilterExpression: {
56
+ 'inCodeSet.identifier': { $exists: true }
57
+ }
58
+ });
59
+ schema.index({ 'name.ja': 1, codeValue: 1 }, {
60
+ name: 'searchByNameJa',
61
+ partialFilterExpression: {
62
+ 'name.ja': { $exists: true }
63
+ }
64
+ });
65
+ schema.index({ 'name.en': 1, codeValue: 1 }, {
66
+ name: 'searchByNameEn',
67
+ partialFilterExpression: {
68
+ 'name.en': { $exists: true }
69
+ }
70
+ });
71
+ mongoose.model(modelName, schema)
72
+ .on('index',
73
+ // tslint:disable-next-line:no-single-line-block-comment
74
+ /* istanbul ignore next */
75
+ (error) => {
76
+ if (error !== undefined) {
77
+ // tslint:disable-next-line:no-console
78
+ console.error(error);
79
+ }
80
+ });
@@ -7,6 +7,7 @@ import { MongoRepository as AccountingReportRepo } from './repo/accountingReport
7
7
  import { MongoRepository as AccountTitleRepo } from './repo/accountTitle';
8
8
  import { MongoRepository as AccountTransactionRepo } from './repo/accountTransaction';
9
9
  import { MongoRepository as ActionRepo } from './repo/action';
10
+ import { MongoRepository as AdditionalPropertyNameRepo } from './repo/additionalPropertyName';
10
11
  import { MongoRepository as AssetTransactionRepo } from './repo/assetTransaction';
11
12
  import { MongoRepository as CategoryCodeRepo } from './repo/categoryCode';
12
13
  import { MongoRepository as CodeRepo } from './repo/code';
@@ -65,6 +66,11 @@ export declare class AccountTransaction extends AccountTransactionRepo {
65
66
  }
66
67
  export declare class Action extends ActionRepo {
67
68
  }
69
+ /**
70
+ * 追加特性名称リポジトリ
71
+ */
72
+ export declare class AdditionalPropertyName extends AdditionalPropertyNameRepo {
73
+ }
68
74
  export declare namespace action {
69
75
  class RegisterServiceInProgress extends RegisterServiceActionInProgress {
70
76
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.rateLimit = exports.itemAvailability = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.AccountAction = exports.Account = void 0;
3
+ exports.rateLimit = exports.itemAvailability = exports.TransactionNumber = exports.Transaction = exports.Telemetry = exports.Task = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.Seller = exports.Role = exports.Reservation = exports.Project = exports.Product = exports.PriceSpecification = exports.Place = exports.Permit = exports.Person = exports.paymentMethod = exports.OwnershipInfo = exports.OrderNumber = exports.Order = exports.OfferCatalog = exports.Offer = exports.MerchantReturnPolicy = exports.Member = exports.Event = exports.EmailMessage = exports.Customer = exports.CreativeWork = exports.ConfirmationNumber = exports.Code = exports.CategoryCode = exports.AssetTransaction = exports.action = exports.AdditionalPropertyName = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.AccountAction = exports.Account = void 0;
4
4
  // tslint:disable:max-classes-per-file completed-docs
5
5
  /**
6
6
  * リポジトリ
@@ -11,6 +11,7 @@ const accountingReport_1 = require("./repo/accountingReport");
11
11
  const accountTitle_1 = require("./repo/accountTitle");
12
12
  const accountTransaction_1 = require("./repo/accountTransaction");
13
13
  const action_1 = require("./repo/action");
14
+ const additionalPropertyName_1 = require("./repo/additionalPropertyName");
14
15
  const assetTransaction_1 = require("./repo/assetTransaction");
15
16
  const categoryCode_1 = require("./repo/categoryCode");
16
17
  const code_1 = require("./repo/code");
@@ -75,6 +76,12 @@ exports.AccountTransaction = AccountTransaction;
75
76
  class Action extends action_1.MongoRepository {
76
77
  }
77
78
  exports.Action = Action;
79
+ /**
80
+ * 追加特性名称リポジトリ
81
+ */
82
+ class AdditionalPropertyName extends additionalPropertyName_1.MongoRepository {
83
+ }
84
+ exports.AdditionalPropertyName = AdditionalPropertyName;
78
85
  var action;
79
86
  (function (action) {
80
87
  class RegisterServiceInProgress extends registerServiceInProgress_1.RedisRepository {
package/package.json CHANGED
@@ -120,5 +120,5 @@
120
120
  "postversion": "git push origin --tags",
121
121
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
122
122
  },
123
- "version": "20.1.0-alpha.18"
123
+ "version": "20.1.0-alpha.19"
124
124
  }