@chevre/domain 22.3.0 → 22.4.0-alpha.1
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.
- package/example/src/chevre/findItemListElementById.ts +23 -0
- package/example/src/chevre/projectFields.ts +3 -3
- package/lib/chevre/repo/customerType.d.ts +2 -2
- package/lib/chevre/repo/customerType.js +14 -21
- package/lib/chevre/repo/member.d.ts +4 -2
- package/lib/chevre/repo/member.js +22 -15
- package/lib/chevre/repo/mongoose/schemas/customerType.js +1 -10
- package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +0 -3
- package/lib/chevre/repo/offerCatalog.d.ts +5 -1
- package/lib/chevre/repo/offerCatalog.js +15 -6
- package/lib/chevre/repo/offerCatalogItem.d.ts +5 -1
- package/lib/chevre/repo/offerCatalogItem.js +3 -2
- package/lib/chevre/repo/offerItemCondition.d.ts +4 -7
- package/lib/chevre/repo/offerItemCondition.js +49 -28
- package/lib/chevre/service/aggregation/project.js +0 -20
- package/lib/chevre/service/task/onResourceUpdated.js +4 -17
- package/lib/chevre/service/transaction/placeOrder/start/validateStartRequest.js +2 -2
- package/lib/chevre/service/transaction/returnOrder/preStart.js +2 -2
- package/package.json +1 -1
- package/example/src/chevre/migrateMembers.ts +0 -94
- package/example/src/chevre/searchCustomerTypes.ts +0 -57
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
|
+
|
|
11
|
+
const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
|
|
12
|
+
|
|
13
|
+
const result = await offerCatalogRepo.findItemListElementById({
|
|
14
|
+
id: 'blpc770py',
|
|
15
|
+
project: { id: project.id }
|
|
16
|
+
});
|
|
17
|
+
console.log(result);
|
|
18
|
+
console.log(result.itemListElement.length);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
main()
|
|
22
|
+
.then(console.log)
|
|
23
|
+
.catch(console.error);
|
|
@@ -8,15 +8,15 @@ const project = { id: String(process.env.PROJECT_ID) };
|
|
|
8
8
|
async function main() {
|
|
9
9
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const repo = await chevre.repository.OfferItemCondition.createInstance(mongoose.connection);
|
|
12
12
|
|
|
13
|
-
const docs = await
|
|
13
|
+
const docs = await repo.projectFields(
|
|
14
14
|
{
|
|
15
15
|
limit: 1,
|
|
16
16
|
page: 1,
|
|
17
17
|
project: { id: { $eq: project.id } }
|
|
18
18
|
},
|
|
19
|
-
['id', '
|
|
19
|
+
['id', 'identifier', 'itemOffered', 'typeOf']
|
|
20
20
|
);
|
|
21
21
|
// tslint:disable-next-line:no-null-keyword
|
|
22
22
|
console.dir(docs, { depth: null });
|
|
@@ -2,7 +2,7 @@ import type { BulkWriteResult } from 'mongodb';
|
|
|
2
2
|
import { Connection, FilterQuery } from 'mongoose';
|
|
3
3
|
import { ICustomerType } from './mongoose/schemas/customerType';
|
|
4
4
|
import * as factory from '../factory';
|
|
5
|
-
type IKeyOfProjection = keyof ICustomerType
|
|
5
|
+
type IKeyOfProjection = keyof ICustomerType;
|
|
6
6
|
/**
|
|
7
7
|
* カスタマータイプリポジトリ
|
|
8
8
|
*/
|
|
@@ -13,7 +13,7 @@ export declare class CustomerTypeRepo {
|
|
|
13
13
|
/**
|
|
14
14
|
* 検索
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
projectFields(params: factory.categoryCode.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<ICustomerType[]>;
|
|
17
17
|
saveManyByCodeValue(params: {
|
|
18
18
|
attributes: ICustomerType;
|
|
19
19
|
upsert?: boolean;
|
|
@@ -12,6 +12,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CustomerTypeRepo = void 0;
|
|
13
13
|
const customerType_1 = require("./mongoose/schemas/customerType");
|
|
14
14
|
const settings_1 = require("../settings");
|
|
15
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
16
|
+
'typeOf',
|
|
17
|
+
'codeValue',
|
|
18
|
+
'name'
|
|
19
|
+
];
|
|
15
20
|
/**
|
|
16
21
|
* カスタマータイプリポジトリ
|
|
17
22
|
*/
|
|
@@ -25,52 +30,40 @@ class CustomerTypeRepo {
|
|
|
25
30
|
const andConditions = [];
|
|
26
31
|
const codeValueEq = (_a = params.codeValue) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
27
32
|
if (typeof codeValueEq === 'string') {
|
|
28
|
-
andConditions.push({ codeValue: { $
|
|
33
|
+
andConditions.push({ codeValue: { $eq: codeValueEq } });
|
|
29
34
|
}
|
|
30
35
|
const codeValueIn = (_b = params.codeValue) === null || _b === void 0 ? void 0 : _b.$in;
|
|
31
36
|
if (Array.isArray(codeValueIn)) {
|
|
32
|
-
andConditions.push({ codeValue: { $
|
|
37
|
+
andConditions.push({ codeValue: { $in: codeValueIn } });
|
|
33
38
|
}
|
|
34
39
|
return andConditions;
|
|
35
40
|
}
|
|
36
41
|
/**
|
|
37
42
|
* 検索
|
|
38
43
|
*/
|
|
39
|
-
|
|
44
|
+
projectFields(params, inclusion) {
|
|
40
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
46
|
const conditions = CustomerTypeRepo.CREATE_MONGO_CONDITIONS(params);
|
|
42
|
-
let
|
|
47
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
43
48
|
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
44
|
-
inclusion.
|
|
45
|
-
projection[field] = 1;
|
|
46
|
-
});
|
|
49
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
47
50
|
}
|
|
48
51
|
else {
|
|
49
|
-
|
|
50
|
-
__v: 0,
|
|
51
|
-
createdAt: 0,
|
|
52
|
-
updatedAt: 0
|
|
53
|
-
};
|
|
54
|
-
if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
55
|
-
exclusion.forEach((field) => {
|
|
56
|
-
projection[field] = 0;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
52
|
+
// no op
|
|
59
53
|
}
|
|
54
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
60
55
|
const query = this.customerTypeModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
61
56
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
62
57
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
63
58
|
query.limit(params.limit)
|
|
64
59
|
.skip(params.limit * (page - 1));
|
|
65
60
|
}
|
|
66
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
67
|
-
/* istanbul ignore else */
|
|
68
61
|
if (params.sort !== undefined) {
|
|
69
62
|
query.sort(params.sort);
|
|
70
63
|
}
|
|
71
64
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
72
|
-
.
|
|
73
|
-
.
|
|
65
|
+
.lean()
|
|
66
|
+
.exec();
|
|
74
67
|
});
|
|
75
68
|
}
|
|
76
69
|
saveManyByCodeValue(params) {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import type { Connection } from 'mongoose';
|
|
26
26
|
import * as factory from '../factory';
|
|
27
|
+
type IKeyOfProjection = keyof factory.iam.IMember;
|
|
27
28
|
/**
|
|
28
29
|
* IAMメンバーリポジトリ
|
|
29
30
|
*/
|
|
@@ -31,7 +32,7 @@ export declare class MemberRepo {
|
|
|
31
32
|
private readonly memberModel;
|
|
32
33
|
constructor(connection: Connection);
|
|
33
34
|
static CREATE_MONGO_CONDITIONS(params: factory.iam.ISearchConditions): any[];
|
|
34
|
-
|
|
35
|
+
projectFields(params: factory.iam.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.iam.IMember[]>;
|
|
35
36
|
aggregateRoleNames(params: {
|
|
36
37
|
project: {
|
|
37
38
|
id: {
|
|
@@ -62,7 +63,7 @@ export declare class MemberRepo {
|
|
|
62
63
|
/**
|
|
63
64
|
* メンバー作成
|
|
64
65
|
*/
|
|
65
|
-
create(params: factory.iam.IMember[]): Promise<
|
|
66
|
+
create(params: factory.iam.IMember[]): Promise<void>;
|
|
66
67
|
/**
|
|
67
68
|
* メンバー更新
|
|
68
69
|
*/
|
|
@@ -163,3 +164,4 @@ export declare class MemberRepo {
|
|
|
163
164
|
$unset: any;
|
|
164
165
|
}): Promise<import("mongoose").UpdateWriteOpResult>;
|
|
165
166
|
}
|
|
167
|
+
export {};
|
|
@@ -11,8 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.MemberRepo = void 0;
|
|
13
13
|
const factory = require("../factory");
|
|
14
|
-
const member_1 = require("./mongoose/schemas/member");
|
|
15
14
|
const settings_1 = require("../settings");
|
|
15
|
+
const member_1 = require("./mongoose/schemas/member");
|
|
16
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
17
|
+
'project',
|
|
18
|
+
'typeOf',
|
|
19
|
+
'member'
|
|
20
|
+
];
|
|
16
21
|
/**
|
|
17
22
|
* IAMメンバーリポジトリ
|
|
18
23
|
*/
|
|
@@ -72,29 +77,31 @@ class MemberRepo {
|
|
|
72
77
|
}
|
|
73
78
|
return andConditions;
|
|
74
79
|
}
|
|
75
|
-
|
|
80
|
+
projectFields(params, inclusion) {
|
|
76
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
82
|
const conditions = MemberRepo.CREATE_MONGO_CONDITIONS(params);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
84
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
85
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// no op
|
|
89
|
+
}
|
|
90
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
91
|
+
const query = this.memberModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
83
92
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
84
93
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
85
94
|
query.limit(params.limit)
|
|
86
95
|
.skip(params.limit * (page - 1));
|
|
87
96
|
}
|
|
88
|
-
// tslint:disable-next-line:no-single-line-block-comment
|
|
89
|
-
/* istanbul ignore else */
|
|
90
97
|
if (params.sort !== undefined) {
|
|
91
98
|
query.sort(params.sort);
|
|
92
99
|
}
|
|
93
100
|
// const explainResult = await (<any>query).explain();
|
|
94
101
|
// console.log(explainResult[0].executionStats.allPlansExecution.map((e: any) => e.executionStages.inputStage));
|
|
95
102
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
96
|
-
.
|
|
97
|
-
.
|
|
103
|
+
.lean()
|
|
104
|
+
.exec();
|
|
98
105
|
});
|
|
99
106
|
}
|
|
100
107
|
aggregateRoleNames(params) {
|
|
@@ -139,21 +146,21 @@ class MemberRepo {
|
|
|
139
146
|
*/
|
|
140
147
|
create(params) {
|
|
141
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
let members = [];
|
|
149
|
+
// let members: factory.iam.IMember[] = [];
|
|
143
150
|
if (params.length > 0) {
|
|
144
|
-
const docs =
|
|
151
|
+
// const docs = await this.memberModel.insertMany(params.map((p) => {
|
|
152
|
+
yield this.memberModel.insertMany(params.map((p) => {
|
|
145
153
|
return {
|
|
146
154
|
project: p.project,
|
|
147
155
|
typeOf: p.typeOf,
|
|
148
156
|
member: p.member
|
|
149
157
|
};
|
|
150
158
|
}));
|
|
151
|
-
members = docs.map((doc) => doc.toObject());
|
|
152
159
|
}
|
|
153
160
|
else {
|
|
154
161
|
// no op
|
|
155
162
|
}
|
|
156
|
-
return members;
|
|
163
|
+
// return members;
|
|
157
164
|
});
|
|
158
165
|
}
|
|
159
166
|
/**
|
|
@@ -35,16 +35,7 @@ const schemaOptions = {
|
|
|
35
35
|
versionKey: false
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
const indexes = [
|
|
39
|
-
// [ // discontinue(2024-08-07~)
|
|
40
|
-
// { createdAt: 1 },
|
|
41
|
-
// { name: 'searchByCreatedAt' }
|
|
42
|
-
// ],
|
|
43
|
-
// [
|
|
44
|
-
// { updatedAt: 1 },
|
|
45
|
-
// { name: 'searchByUpdatedAt' }
|
|
46
|
-
// ]
|
|
47
|
-
];
|
|
38
|
+
const indexes = [];
|
|
48
39
|
exports.indexes = indexes;
|
|
49
40
|
/**
|
|
50
41
|
* カスタマータイプスキーマ
|
|
@@ -12,9 +12,6 @@ const schemaDefinition = {
|
|
|
12
12
|
typeOf: String,
|
|
13
13
|
name: mongoose_1.SchemaTypes.Mixed,
|
|
14
14
|
itemOffered: mongoose_1.SchemaTypes.Mixed
|
|
15
|
-
// createdAt: SchemaTypes.Mixed,
|
|
16
|
-
// updatedAt: SchemaTypes.Mixed,
|
|
17
|
-
// __v: SchemaTypes.Mixed
|
|
18
15
|
};
|
|
19
16
|
const schemaOptions = {
|
|
20
17
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
@@ -111,7 +111,11 @@ export declare class OfferCatalogRepo {
|
|
|
111
111
|
project: {
|
|
112
112
|
id: string;
|
|
113
113
|
};
|
|
114
|
-
}): Promise<
|
|
114
|
+
}): Promise<{
|
|
115
|
+
itemListElement: {
|
|
116
|
+
id: string;
|
|
117
|
+
}[];
|
|
118
|
+
}>;
|
|
115
119
|
/**
|
|
116
120
|
* 一つ目のitemListElementを取得する
|
|
117
121
|
*/
|
|
@@ -134,22 +134,25 @@ class OfferCatalogRepo {
|
|
|
134
134
|
}
|
|
135
135
|
save(params) {
|
|
136
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
let savedId;
|
|
137
138
|
let doc;
|
|
138
|
-
if (params.id === '') {
|
|
139
|
+
if (typeof params.id !== 'string' || params.id === '') {
|
|
139
140
|
const uniqid = yield Promise.resolve().then(() => require('uniqid'));
|
|
140
141
|
const newId = uniqid();
|
|
141
142
|
const { id, $unset } = params, creatingDoc = __rest(params, ["id", "$unset"]);
|
|
142
143
|
doc = yield this.offerCatalogModel.create(Object.assign(Object.assign({}, creatingDoc), { _id: newId }));
|
|
144
|
+
savedId = newId;
|
|
143
145
|
}
|
|
144
146
|
else {
|
|
145
147
|
const { id, identifier, itemOffered, project, typeOf, $unset } = params, updateFields = __rest(params, ["id", "identifier", "itemOffered", "project", "typeOf", "$unset"]); // 上書き禁止属性を除外
|
|
146
148
|
doc = yield this.offerCatalogModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: updateFields }, (params.$unset !== undefined) ? { $unset: params.$unset } : undefined), { upsert: false, new: true, projection: { _id: 1 } })
|
|
147
149
|
.exec();
|
|
150
|
+
savedId = id;
|
|
148
151
|
}
|
|
149
152
|
if (doc === null) {
|
|
150
153
|
throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
|
|
151
154
|
}
|
|
152
|
-
return
|
|
155
|
+
return { id: savedId };
|
|
153
156
|
});
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
@@ -166,9 +169,14 @@ class OfferCatalogRepo {
|
|
|
166
169
|
}, {
|
|
167
170
|
$set: updateFields,
|
|
168
171
|
$setOnInsert: { _id: newId, identifier, itemOffered, project, typeOf }
|
|
169
|
-
}, {
|
|
172
|
+
}, {
|
|
173
|
+
upsert: true,
|
|
174
|
+
new: true,
|
|
175
|
+
projection: { _id: 0, id: '$_id' }
|
|
176
|
+
})
|
|
177
|
+
.lean()
|
|
170
178
|
.exec();
|
|
171
|
-
return doc.
|
|
179
|
+
return { id: doc.id };
|
|
172
180
|
});
|
|
173
181
|
}
|
|
174
182
|
/**
|
|
@@ -333,12 +341,13 @@ class OfferCatalogRepo {
|
|
|
333
341
|
const doc = yield this.offerCatalogModel.findOne({
|
|
334
342
|
'project.id': { $eq: params.project.id },
|
|
335
343
|
_id: { $eq: params.id }
|
|
336
|
-
}, { 'itemListElement.id': 1 })
|
|
344
|
+
}, { 'itemListElement.id': 1, _id: 0 })
|
|
345
|
+
.lean() // lean(2024-09-24~)
|
|
337
346
|
.exec();
|
|
338
347
|
if (doc === null) {
|
|
339
348
|
throw new factory.errors.NotFound(this.offerCatalogModel.modelName);
|
|
340
349
|
}
|
|
341
|
-
return doc
|
|
350
|
+
return doc;
|
|
342
351
|
});
|
|
343
352
|
}
|
|
344
353
|
/**
|
|
@@ -99,7 +99,11 @@ export declare class OfferCatalogItemRepo {
|
|
|
99
99
|
project: {
|
|
100
100
|
id: string;
|
|
101
101
|
};
|
|
102
|
-
}): Promise<
|
|
102
|
+
}): Promise<{
|
|
103
|
+
itemListElement: {
|
|
104
|
+
id: string;
|
|
105
|
+
}[];
|
|
106
|
+
}>;
|
|
103
107
|
deleteById(params: {
|
|
104
108
|
id: string;
|
|
105
109
|
}): Promise<void>;
|
|
@@ -317,12 +317,13 @@ class OfferCatalogItemRepo {
|
|
|
317
317
|
const doc = yield this.offerCatalogItemModel.findOne({
|
|
318
318
|
'project.id': { $eq: params.project.id },
|
|
319
319
|
_id: { $eq: params.id }
|
|
320
|
-
}, { 'itemListElement.id': 1 })
|
|
320
|
+
}, { 'itemListElement.id': 1, _id: 0 })
|
|
321
|
+
.lean() // lean(2024-09-24~)
|
|
321
322
|
.exec();
|
|
322
323
|
if (doc === null) {
|
|
323
324
|
throw new factory.errors.NotFound(this.offerCatalogItemModel.modelName);
|
|
324
325
|
}
|
|
325
|
-
return doc
|
|
326
|
+
return doc;
|
|
326
327
|
});
|
|
327
328
|
}
|
|
328
329
|
deleteById(params) {
|
|
@@ -24,9 +24,7 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import type { Connection } from 'mongoose';
|
|
26
26
|
import * as factory from '../factory';
|
|
27
|
-
|
|
28
|
-
[key: string]: 0 | 1;
|
|
29
|
-
}
|
|
27
|
+
type IKeyOfProjection = keyof factory.offerItemCondition.IOfferItemCondition;
|
|
30
28
|
/**
|
|
31
29
|
* アイテムコンディションリポジトリ
|
|
32
30
|
*/
|
|
@@ -34,11 +32,10 @@ export declare class OfferItemConditionRepo {
|
|
|
34
32
|
private readonly offerItemConditionModel;
|
|
35
33
|
constructor(connection: Connection);
|
|
36
34
|
static CREATE_MONGO_CONDITIONS(params: factory.offerItemCondition.ISearchConditions): any[];
|
|
37
|
-
|
|
35
|
+
projectFields(params: factory.offerItemCondition.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.offerItemCondition.IOfferItemCondition[]>;
|
|
36
|
+
save(params: factory.offerItemCondition.IOfferItemCondition): Promise<{
|
|
38
37
|
id: string;
|
|
39
|
-
}
|
|
40
|
-
search(params: factory.offerItemCondition.ISearchConditions, projection?: IProjection): Promise<factory.offerItemCondition.IOfferItemCondition[]>;
|
|
41
|
-
save(params: factory.offerItemCondition.IOfferItemCondition): Promise<factory.offerItemCondition.IOfferItemCondition>;
|
|
38
|
+
}>;
|
|
42
39
|
deleteById(params: {
|
|
43
40
|
id: string;
|
|
44
41
|
}): Promise<void>;
|
|
@@ -22,8 +22,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
23
|
exports.OfferItemConditionRepo = void 0;
|
|
24
24
|
const factory = require("../factory");
|
|
25
|
-
const offerItemCondition_1 = require("./mongoose/schemas/offerItemCondition");
|
|
26
25
|
const settings_1 = require("../settings");
|
|
26
|
+
const offerItemCondition_1 = require("./mongoose/schemas/offerItemCondition");
|
|
27
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
28
|
+
'project',
|
|
29
|
+
'identifier',
|
|
30
|
+
'typeOf',
|
|
31
|
+
'name',
|
|
32
|
+
'itemOffered'
|
|
33
|
+
];
|
|
27
34
|
/**
|
|
28
35
|
* アイテムコンディションリポジトリ
|
|
29
36
|
*/
|
|
@@ -56,31 +63,42 @@ class OfferItemConditionRepo {
|
|
|
56
63
|
}
|
|
57
64
|
return andConditions;
|
|
58
65
|
}
|
|
59
|
-
findById(params
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
// public async findById(params: {
|
|
67
|
+
// id: string;
|
|
68
|
+
// }): Promise<factory.offerItemCondition.IOfferItemCondition> {
|
|
69
|
+
// const doc = await this.offerItemConditionModel.findOne(
|
|
70
|
+
// { _id: params.id },
|
|
71
|
+
// {
|
|
72
|
+
// __v: 0,
|
|
73
|
+
// createdAt: 0,
|
|
74
|
+
// updatedAt: 0
|
|
75
|
+
// }
|
|
76
|
+
// )
|
|
77
|
+
// .exec();
|
|
78
|
+
// if (doc === null) {
|
|
79
|
+
// throw new factory.errors.NotFound(this.offerItemConditionModel.modelName);
|
|
80
|
+
// }
|
|
81
|
+
// return doc.toObject();
|
|
82
|
+
// }
|
|
83
|
+
projectFields(params,
|
|
84
|
+
// projection?: IProjection
|
|
85
|
+
inclusion) {
|
|
74
86
|
var _a;
|
|
75
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
88
|
const conditions = OfferItemConditionRepo.CREATE_MONGO_CONDITIONS(params);
|
|
77
|
-
const positiveProjectionExists = (projection !== undefined && projection !== null)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
// const positiveProjectionExists: boolean = (projection !== undefined && projection !== null)
|
|
90
|
+
// ? Object.values(projection)
|
|
91
|
+
// .some((value) => value !== 0)
|
|
92
|
+
// : false;
|
|
93
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
94
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
95
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
|
|
99
|
+
}
|
|
100
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
101
|
+
const query = this.offerItemConditionModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
84
102
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
85
103
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
86
104
|
query.limit(params.limit)
|
|
@@ -90,26 +108,29 @@ class OfferItemConditionRepo {
|
|
|
90
108
|
query.sort({ identifier: params.sort.identifier });
|
|
91
109
|
}
|
|
92
110
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
93
|
-
.
|
|
94
|
-
.
|
|
111
|
+
.lean() // lean(2024-09-24~)
|
|
112
|
+
.exec();
|
|
95
113
|
});
|
|
96
114
|
}
|
|
97
115
|
save(params) {
|
|
98
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
let savedId;
|
|
99
118
|
let doc;
|
|
100
|
-
if (params.id === '') {
|
|
119
|
+
if (typeof params.id !== 'string' || params.id === '') {
|
|
101
120
|
const { id } = params, creatingParams = __rest(params, ["id"]); // omit id(2024-09-12~)
|
|
102
121
|
doc = yield this.offerItemConditionModel.create(creatingParams);
|
|
122
|
+
savedId = doc.id;
|
|
103
123
|
}
|
|
104
124
|
else {
|
|
105
125
|
const { id, identifier, project, typeOf } = params, updateFields = __rest(params, ["id", "identifier", "project", "typeOf"]);
|
|
106
|
-
doc = yield this.offerItemConditionModel.findOneAndUpdate({ _id:
|
|
126
|
+
doc = yield this.offerItemConditionModel.findOneAndUpdate({ _id: { $eq: id } }, updateFields, { upsert: false, new: true, projection: { _id: 1 } })
|
|
107
127
|
.exec();
|
|
128
|
+
savedId = id;
|
|
108
129
|
}
|
|
109
130
|
if (doc === null) {
|
|
110
131
|
throw new factory.errors.NotFound(this.offerItemConditionModel.modelName);
|
|
111
132
|
}
|
|
112
|
-
return
|
|
133
|
+
return { id: savedId };
|
|
113
134
|
});
|
|
114
135
|
}
|
|
115
136
|
deleteById(params) {
|
|
@@ -38,31 +38,11 @@ function aggregate(params) {
|
|
|
38
38
|
}
|
|
39
39
|
})(repos);
|
|
40
40
|
debug('aggregated. aggregateReservation:', aggregateReservation);
|
|
41
|
-
// 値がundefinedの場合に更新しないように注意
|
|
42
|
-
// const update: any = {
|
|
43
|
-
// $set: {
|
|
44
|
-
// updatedAt: new Date(), // $setオブジェクトが空だとMongoエラーになるので
|
|
45
|
-
// aggregateReservation: aggregateReservation
|
|
46
|
-
// },
|
|
47
|
-
// $unset: {
|
|
48
|
-
// noExistingAttributeName: 1 // $unsetは空だとエラーになるので
|
|
49
|
-
// }
|
|
50
|
-
// };
|
|
51
|
-
// debug('update:', update);
|
|
52
41
|
// 保管
|
|
53
42
|
yield repos.project.updateAggregateReservation({
|
|
54
43
|
id: project.id,
|
|
55
44
|
aggregateReservation
|
|
56
45
|
});
|
|
57
|
-
// await repos.project.projectModel.findOneAndUpdate(
|
|
58
|
-
// { _id: project.id },
|
|
59
|
-
// update,
|
|
60
|
-
// { new: true }
|
|
61
|
-
// )
|
|
62
|
-
// .exec();
|
|
63
|
-
// if (projectDoc !== null) {
|
|
64
|
-
// project = projectDoc.toObject();
|
|
65
|
-
// }
|
|
66
46
|
});
|
|
67
47
|
}
|
|
68
48
|
exports.aggregate = aggregate;
|
|
@@ -8,17 +8,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
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
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
12
|
exports.call = void 0;
|
|
24
13
|
const factory = require("../../factory");
|
|
@@ -478,12 +467,13 @@ function createInformAccountTitleTasks(params) {
|
|
|
478
467
|
project: 1,
|
|
479
468
|
typeOf: 1
|
|
480
469
|
})
|
|
470
|
+
.lean()
|
|
481
471
|
.exec()
|
|
482
472
|
.then((doc) => {
|
|
483
473
|
if (doc === null) {
|
|
484
474
|
throw new factory.errors.NotFound(params.typeOf);
|
|
485
475
|
}
|
|
486
|
-
return doc
|
|
476
|
+
return doc;
|
|
487
477
|
});
|
|
488
478
|
const accountTitles4inform = [accountTitle];
|
|
489
479
|
if (accountTitles4inform.length > 0) {
|
|
@@ -495,19 +485,16 @@ function createInformAccountTitleTasks(params) {
|
|
|
495
485
|
accountTitles4inform.forEach((accountTitle4inform) => {
|
|
496
486
|
var _a;
|
|
497
487
|
// _idは不要であり、存在すると予期せぬ影響を及ぼす可能性がある
|
|
498
|
-
//
|
|
499
|
-
const
|
|
488
|
+
// const { _id, ...informObject } = accountTitle4inform;
|
|
489
|
+
const informObject = accountTitle4inform;
|
|
500
490
|
const informActionAttributes = {
|
|
501
|
-
// agent: accountTitle4inform.project,
|
|
502
491
|
object: informObject,
|
|
503
|
-
// project: accountTitle4inform.project,
|
|
504
492
|
recipient: {
|
|
505
493
|
id: '',
|
|
506
494
|
name: String((_a = informResource.recipient) === null || _a === void 0 ? void 0 : _a.name),
|
|
507
495
|
typeOf: factory.creativeWorkType.WebApplication,
|
|
508
496
|
url: informUrl
|
|
509
497
|
}
|
|
510
|
-
// typeOf: factory.actionType.InformAction
|
|
511
498
|
};
|
|
512
499
|
informTasks.push({
|
|
513
500
|
project: accountTitle4inform.project,
|
|
@@ -103,14 +103,14 @@ function validateStartRequest(params) {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
// IAM存在検証(2024-02-06~)
|
|
106
|
-
const iamMember = (yield repos.member.
|
|
106
|
+
const iamMember = (yield repos.member.projectFields({
|
|
107
107
|
project: { id: { $eq: seller.project.id } },
|
|
108
108
|
member: {
|
|
109
109
|
typeOf: { $eq: factory.creativeWorkType.WebApplication },
|
|
110
110
|
id: { $eq: clientId },
|
|
111
111
|
memberOf: { typeOf: { $eq: factory.organizationType.Project } } // プロジェクトメンバーのはず
|
|
112
112
|
}
|
|
113
|
-
})).shift();
|
|
113
|
+
}, ['member'])).shift();
|
|
114
114
|
if (iamMember === undefined) {
|
|
115
115
|
throw new factory.errors.NotFound(factory.iam.RoleType.OrganizationRole);
|
|
116
116
|
}
|
|
@@ -70,9 +70,9 @@ function preStart(params) {
|
|
|
70
70
|
.filter((returnPolicy) => { var _a; return typeof ((_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id) === 'string'; })
|
|
71
71
|
.map((returnPolicy) => { var _a; return String((_a = returnPolicy.itemCondition) === null || _a === void 0 ? void 0 : _a.id); });
|
|
72
72
|
if (itemConditionIds.length > 0) {
|
|
73
|
-
offerItemConditions = yield repos.offerItemCondition.
|
|
73
|
+
offerItemConditions = yield repos.offerItemCondition.projectFields({
|
|
74
74
|
id: { $in: itemConditionIds }
|
|
75
|
-
});
|
|
75
|
+
}, ['id', 'identifier', 'itemOffered', 'typeOf']);
|
|
76
76
|
}
|
|
77
77
|
const policiesByOffer = yield searchPoliciesByOffer({ offers })(repos);
|
|
78
78
|
const { usedReservationExists } = yield checkUsedReservationExists({ orders })(repos);
|
package/package.json
CHANGED
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
|
|
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 memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
13
|
-
|
|
14
|
-
const cursor = memberRepo.getCursor(
|
|
15
|
-
{
|
|
16
|
-
'member.memberOf.typeOf': { $eq: chevre.factory.organizationType.Corporation }
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
}
|
|
20
|
-
);
|
|
21
|
-
console.log('members found');
|
|
22
|
-
|
|
23
|
-
let projectIds: string[] = [];
|
|
24
|
-
let i = 0;
|
|
25
|
-
let updateCount = 0;
|
|
26
|
-
await cursor.eachAsync(async (doc) => {
|
|
27
|
-
i += 1;
|
|
28
|
-
const iamMember: chevre.factory.iam.IMember = doc.toObject();
|
|
29
|
-
|
|
30
|
-
const alreadyMigrated = false;
|
|
31
|
-
projectIds.push(iamMember.project.id);
|
|
32
|
-
|
|
33
|
-
if (alreadyMigrated) {
|
|
34
|
-
console.log(
|
|
35
|
-
'already exist.',
|
|
36
|
-
iamMember.project.id,
|
|
37
|
-
iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
|
|
38
|
-
);
|
|
39
|
-
} else {
|
|
40
|
-
console.log(
|
|
41
|
-
'updating...',
|
|
42
|
-
iamMember.project.id,
|
|
43
|
-
iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
|
|
44
|
-
);
|
|
45
|
-
updateCount += 1;
|
|
46
|
-
console.log(
|
|
47
|
-
'updated.',
|
|
48
|
-
iamMember.project.id,
|
|
49
|
-
iamMember.member.memberOf.typeOf, iamMember.member.memberOf.id, i, updateCount
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
projectIds = [...new Set(projectIds)];
|
|
55
|
-
console.log(projectIds);
|
|
56
|
-
console.log(i, 'members checked');
|
|
57
|
-
console.log(updateCount, 'members updated');
|
|
58
|
-
|
|
59
|
-
// 販売者メンバーの存在するプロジェクトについて、inventoryManagerにiam.roleAdminを追加
|
|
60
|
-
const NEW_ROLE_NAME = 'iam.roleAdmin';
|
|
61
|
-
for (const projectId of projectIds) {
|
|
62
|
-
const inventoryManagers = await memberRepo.search({
|
|
63
|
-
project: { id: { $eq: projectId } },
|
|
64
|
-
member: {
|
|
65
|
-
hasRole: { roleName: { $eq: 'inventoryManager' } },
|
|
66
|
-
memberOf: { typeOf: { $eq: chevre.factory.organizationType.Project } }
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
console.log(inventoryManagers.length, 'inventoryManagers found', projectId);
|
|
70
|
-
for (const inventoryManager of inventoryManagers) {
|
|
71
|
-
const alreadyRoleAdmin = inventoryManager.member.hasRole.some(({ roleName }) => roleName === NEW_ROLE_NAME);
|
|
72
|
-
if (!alreadyRoleAdmin) {
|
|
73
|
-
const newHasRole: chevre.factory.iam.IMemberRole[] = [
|
|
74
|
-
{ typeOf: chevre.factory.iam.RoleType.OrganizationRole, roleName: NEW_ROLE_NAME },
|
|
75
|
-
...inventoryManager.member.hasRole
|
|
76
|
-
];
|
|
77
|
-
console.log('adding newRole', projectId, inventoryManager.member.id, newHasRole);
|
|
78
|
-
await memberRepo.updateByMemberId({
|
|
79
|
-
project: { id: inventoryManager.project.id },
|
|
80
|
-
member: {
|
|
81
|
-
id: inventoryManager.member.id,
|
|
82
|
-
memberOf: inventoryManager.member.memberOf,
|
|
83
|
-
hasRole: newHasRole
|
|
84
|
-
},
|
|
85
|
-
$unset: {}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
main()
|
|
93
|
-
.then()
|
|
94
|
-
.catch(console.error);
|
|
@@ -1,57 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
async function main() {
|
|
9
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
10
|
-
|
|
11
|
-
const customerTypeRepo = await chevre.repository.CustomerType.createInstance(mongoose.connection);
|
|
12
|
-
|
|
13
|
-
const saveResult = await customerTypeRepo.saveManyByCodeValue([
|
|
14
|
-
{
|
|
15
|
-
attributes: {
|
|
16
|
-
typeOf: 'CategoryCode',
|
|
17
|
-
codeValue: 'Enduser',
|
|
18
|
-
name: { ja: 'エンドユーザー' }
|
|
19
|
-
},
|
|
20
|
-
upsert: true
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
attributes: {
|
|
24
|
-
typeOf: 'CategoryCode',
|
|
25
|
-
codeValue: 'POS',
|
|
26
|
-
name: { ja: 'POS' }
|
|
27
|
-
},
|
|
28
|
-
upsert: true
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
attributes: {
|
|
32
|
-
typeOf: 'CategoryCode',
|
|
33
|
-
codeValue: 'TVM',
|
|
34
|
-
name: { ja: '券売機' }
|
|
35
|
-
},
|
|
36
|
-
upsert: true
|
|
37
|
-
}
|
|
38
|
-
]);
|
|
39
|
-
console.log('saved,', saveResult);
|
|
40
|
-
|
|
41
|
-
const categoryCodes = await customerTypeRepo.search(
|
|
42
|
-
{
|
|
43
|
-
limit: 100,
|
|
44
|
-
page: 1,
|
|
45
|
-
sort: { codeValue: chevre.factory.sortType.Ascending },
|
|
46
|
-
codeValue: { $eq: 'Enduser' }
|
|
47
|
-
},
|
|
48
|
-
[],
|
|
49
|
-
[]
|
|
50
|
-
);
|
|
51
|
-
console.log('categoryCodes found', categoryCodes);
|
|
52
|
-
console.log(categoryCodes.length, 'categoryCodes found');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
main()
|
|
56
|
-
.then()
|
|
57
|
-
.catch(console.error);
|