@chevre/domain 23.0.0-alpha.10 → 23.0.0-alpha.12
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/offerCatalog/updateManyOfferCatalogsByIds.ts +49 -0
- package/example/src/chevre/product/findHasOfferCatalog.ts +14 -10
- package/example/src/chevre/reIndex.ts +1 -3
- package/example/src/chevre/roles/addAdminProductHasOfferCatalogReadPermissionIfNotExists.ts +33 -0
- package/lib/chevre/errorHandler.d.ts +6 -2
- package/lib/chevre/errorHandler.js +8 -2
- package/lib/chevre/repo/offerCatalog.d.ts +17 -2
- package/lib/chevre/repo/offerCatalog.js +5 -2
- package/package.json +2 -2
- package/example/src/chevre/searchOfferCatalogItems.ts +0 -59
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
// const PROJECT_ID = process.env.PROJECT_ID;
|
|
7
|
+
mongoose.Model.on('index', (...args) => {
|
|
8
|
+
console.error('******** index event emitted. ********\n', args);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
await offerCatalogRepo.updateManyOfferCatalogsByIds({
|
|
18
|
+
id: {
|
|
19
|
+
$in: ['xxx']
|
|
20
|
+
},
|
|
21
|
+
itemOffered: {
|
|
22
|
+
typeOf: {
|
|
23
|
+
$eq: chevre.factory.product.ProductType.EventService
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
$push: {
|
|
27
|
+
itemListElement: {
|
|
28
|
+
$each: [{ id: 'xxx', typeOf: chevre.factory.offerType.Offer }],
|
|
29
|
+
$slice: 300
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
$pull: {
|
|
33
|
+
itemListElement: {
|
|
34
|
+
$elemMatch: {
|
|
35
|
+
id: {
|
|
36
|
+
$in: ['xxx']
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
} catch (error) {
|
|
43
|
+
throw await chevre.errorHandler.handleMongoError(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main()
|
|
48
|
+
.then(console.log)
|
|
49
|
+
.catch(console.error);
|
|
@@ -10,16 +10,20 @@ async function main() {
|
|
|
10
10
|
|
|
11
11
|
const productHasOfferCatalogRepo = await chevre.repository.ProductHasOfferCatalog.createInstance(mongoose.connection);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
try {
|
|
14
|
+
const offerCatalogs = (await productHasOfferCatalogRepo.findOfferCatalogs(
|
|
15
|
+
{
|
|
16
|
+
limit: 10,
|
|
17
|
+
page: 1,
|
|
18
|
+
project: { id: { $eq: project.id } },
|
|
19
|
+
product: { id: { $in: ['656038908b1cd5ce629f5992', '60c1c0031fb182000bed5eff'] } }
|
|
20
|
+
}
|
|
21
|
+
));
|
|
22
|
+
// tslint:disable-next-line:no-null-keyword
|
|
23
|
+
console.dir(offerCatalogs, { depth: null });
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw await chevre.errorHandler.handleMongoError(error);
|
|
26
|
+
}
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
main()
|
|
@@ -11,9 +11,7 @@ mongoose.Model.on('index', (...args) => {
|
|
|
11
11
|
async function main() {
|
|
12
12
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
13
|
|
|
14
|
-
await chevre.repository.
|
|
15
|
-
await chevre.repository.Seller.createInstance(mongoose.connection);
|
|
16
|
-
await chevre.repository.ProductOffer.createInstance(mongoose.connection);
|
|
14
|
+
await chevre.repository.Note.createInstance(mongoose.connection);
|
|
17
15
|
console.log('success!');
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as mongoose from 'mongoose';
|
|
3
|
+
|
|
4
|
+
import { chevre } from '../../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const roleRepo = await chevre.repository.Role.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const roleNames = [
|
|
12
|
+
chevre.factory.role.organizationRole.RoleName.InventoryManager
|
|
13
|
+
// chevre.factory.role.organizationRole.RoleName.SellersOwner,
|
|
14
|
+
// chevre.factory.role.organizationRole.RoleName.SellersInventoryManager,
|
|
15
|
+
// chevre.factory.role.organizationRole.RoleName.TicketClerk
|
|
16
|
+
];
|
|
17
|
+
const permissions = [
|
|
18
|
+
'admin.productHasOfferCatalog.read'
|
|
19
|
+
];
|
|
20
|
+
for (const roleName of roleNames) {
|
|
21
|
+
for (const permission of permissions) {
|
|
22
|
+
const result = await roleRepo.addPermissionIfNotExists({
|
|
23
|
+
roleName: { $eq: roleName },
|
|
24
|
+
permission
|
|
25
|
+
});
|
|
26
|
+
console.log('permission added.', result, roleName);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
main()
|
|
32
|
+
.then()
|
|
33
|
+
.catch(console.error);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* https://www.mongodb.com/ja-jp/docs/manual/reference/error-codes/
|
|
3
|
+
*/
|
|
1
4
|
export declare enum MongoErrorCode {
|
|
2
|
-
|
|
5
|
+
ConflictUpdateOperator = 40,
|
|
3
6
|
MaxTimeMSExpired = 50,
|
|
4
|
-
ExceededTimeLimit = 262
|
|
7
|
+
ExceededTimeLimit = 262,
|
|
8
|
+
DuplicateKey = 11000
|
|
5
9
|
}
|
|
6
10
|
export declare function isMongoError(error: unknown): Promise<boolean>;
|
|
7
11
|
export declare function handleMongoError(error: unknown): Promise<unknown>;
|
|
@@ -24,11 +24,15 @@ exports.handleAWSError = handleAWSError;
|
|
|
24
24
|
const http_status_1 = require("http-status");
|
|
25
25
|
const factory_1 = require("./factory");
|
|
26
26
|
let mongo;
|
|
27
|
+
/**
|
|
28
|
+
* https://www.mongodb.com/ja-jp/docs/manual/reference/error-codes/
|
|
29
|
+
*/
|
|
27
30
|
var MongoErrorCode;
|
|
28
31
|
(function (MongoErrorCode) {
|
|
29
|
-
MongoErrorCode[MongoErrorCode["
|
|
32
|
+
MongoErrorCode[MongoErrorCode["ConflictUpdateOperator"] = 40] = "ConflictUpdateOperator";
|
|
30
33
|
MongoErrorCode[MongoErrorCode["MaxTimeMSExpired"] = 50] = "MaxTimeMSExpired";
|
|
31
34
|
MongoErrorCode[MongoErrorCode["ExceededTimeLimit"] = 262] = "ExceededTimeLimit";
|
|
35
|
+
MongoErrorCode[MongoErrorCode["DuplicateKey"] = 11000] = "DuplicateKey";
|
|
32
36
|
})(MongoErrorCode || (exports.MongoErrorCode = MongoErrorCode = {}));
|
|
33
37
|
function isMongoError(error) {
|
|
34
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -46,9 +50,11 @@ function handleMongoError(error) {
|
|
|
46
50
|
let handledError = error;
|
|
47
51
|
if (handledError instanceof mongo.MongoError || handledError instanceof mongo.MongoServerError) {
|
|
48
52
|
switch (handledError.code) {
|
|
53
|
+
case MongoErrorCode.ConflictUpdateOperator:
|
|
54
|
+
handledError = new factory_1.errors.Argument('', `Some updating fields conflict. code:${handledError.code} message:${handledError.message}`);
|
|
55
|
+
break;
|
|
49
56
|
case MongoErrorCode.DuplicateKey:
|
|
50
57
|
handledError = new factory_1.errors.AlreadyInUse('', [], `Some fields already in use. code:${handledError.code} message:${handledError.message}`);
|
|
51
|
-
// no op
|
|
52
58
|
break;
|
|
53
59
|
case MongoErrorCode.MaxTimeMSExpired:
|
|
54
60
|
case MongoErrorCode.ExceededTimeLimit:
|
|
@@ -48,13 +48,28 @@ export declare class OfferCatalogRepo {
|
|
|
48
48
|
id: string;
|
|
49
49
|
dateSynced: Date;
|
|
50
50
|
}): Promise<void>;
|
|
51
|
-
|
|
51
|
+
/**
|
|
52
|
+
* オファーカタログIDリストからitemListElementをまとめて編集する
|
|
53
|
+
*/
|
|
54
|
+
updateManyOfferCatalogsByIds(params: {
|
|
52
55
|
id: {
|
|
53
56
|
$in: string[];
|
|
54
57
|
};
|
|
58
|
+
itemOffered: {
|
|
59
|
+
typeOf: {
|
|
60
|
+
$eq: factory.product.ProductType;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
55
63
|
$push: {
|
|
56
64
|
itemListElement: {
|
|
57
|
-
|
|
65
|
+
/**
|
|
66
|
+
* ひとまず要素がOfferのみに対応
|
|
67
|
+
*/
|
|
68
|
+
$each: factory.offerCatalog.IItemListElementAsAggregateOffer[];
|
|
69
|
+
/**
|
|
70
|
+
* カタログ内最大要素数
|
|
71
|
+
* 指定した数でsliceされる
|
|
72
|
+
*/
|
|
58
73
|
$slice: number;
|
|
59
74
|
};
|
|
60
75
|
};
|
|
@@ -252,13 +252,16 @@ class OfferCatalogRepo {
|
|
|
252
252
|
.exec();
|
|
253
253
|
});
|
|
254
254
|
}
|
|
255
|
-
|
|
255
|
+
/**
|
|
256
|
+
* オファーカタログIDリストからitemListElementをまとめて編集する
|
|
257
|
+
*/
|
|
258
|
+
updateManyOfferCatalogsByIds(params) {
|
|
256
259
|
return __awaiter(this, void 0, void 0, function* () {
|
|
257
260
|
if (!Array.isArray(params.id.$in) || params.id.$in.length === 0) {
|
|
258
261
|
return;
|
|
259
262
|
}
|
|
260
263
|
const pushItemListElementIds = params.$push.itemListElement.$each.map((element) => element.id);
|
|
261
|
-
yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in } }, (pushItemListElementIds.length > 0)
|
|
264
|
+
yield this.offerCatalogModel.updateMany(Object.assign({ _id: { $in: params.id.$in }, 'itemOffered.typeOf': { $exists: true, $eq: params.itemOffered.typeOf.$eq } }, (pushItemListElementIds.length > 0)
|
|
262
265
|
// itemListElementのユニークネスを保証する
|
|
263
266
|
? {
|
|
264
267
|
'itemListElement.id': {
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"moment-timezone": "^0.5.33",
|
|
28
28
|
"node-fpe": "1.0.0",
|
|
29
29
|
"pug": "^2.0.4",
|
|
30
|
-
"uniqid": "
|
|
30
|
+
"uniqid": "5.4.0",
|
|
31
31
|
"uuid": "^3.4.0"
|
|
32
32
|
},
|
|
33
33
|
"description": "Chevre Domain Library for Node.js",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "23.0.0-alpha.
|
|
118
|
+
"version": "23.0.0-alpha.12"
|
|
119
119
|
}
|
|
@@ -1,59 +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 = process.env.PROJECT_ID;
|
|
7
|
-
mongoose.Model.on('index', (...args) => {
|
|
8
|
-
console.error('******** index event emitted. ********\n', args);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
async function main() {
|
|
12
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
-
|
|
14
|
-
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
15
|
-
const offerCatalogRepo = await chevre.repository.OfferCatalog.createInstance(mongoose.connection);
|
|
16
|
-
const offerCatalogItemRepo = await chevre.repository.OfferCatalogItem.createInstance(mongoose.connection);
|
|
17
|
-
const productRepo = await chevre.repository.Product.createInstance(mongoose.connection);
|
|
18
|
-
|
|
19
|
-
const result = await (await chevre.service.offer.createService()).event.searchOfferCatalogItems({
|
|
20
|
-
event: {
|
|
21
|
-
id: 'bm0f0cadm'
|
|
22
|
-
},
|
|
23
|
-
limit: 10,
|
|
24
|
-
page: 1,
|
|
25
|
-
options: { includedInDataCatalog: { id: 'blpj322ni' } }
|
|
26
|
-
})({
|
|
27
|
-
event: eventRepo,
|
|
28
|
-
offerCatalog: offerCatalogRepo,
|
|
29
|
-
offerCatalogItem: offerCatalogItemRepo,
|
|
30
|
-
product: productRepo
|
|
31
|
-
});
|
|
32
|
-
console.log(result);
|
|
33
|
-
console.log(result.length);
|
|
34
|
-
|
|
35
|
-
// console.log('searching...');
|
|
36
|
-
// const catalogs = await catalogItemRepo.search(
|
|
37
|
-
// {
|
|
38
|
-
// project: { id: { $eq: PROJECT_ID } },
|
|
39
|
-
// sort: { identifier: chevre.factory.sortType.Descending },
|
|
40
|
-
// limit: 2,
|
|
41
|
-
// page: 1,
|
|
42
|
-
// itemListElement: { typeOf: { $eq: 'Offer' } }
|
|
43
|
-
// }
|
|
44
|
-
// );
|
|
45
|
-
// console.log(catalogs[0]?.id, typeof catalogs[0]?.id);
|
|
46
|
-
// console.log(catalogs.length);
|
|
47
|
-
|
|
48
|
-
// const numCatalogs = await catalogItemRepo.count(
|
|
49
|
-
// {
|
|
50
|
-
// project: { id: { $eq: PROJECT_ID } },
|
|
51
|
-
// itemListElement: { typeOf: { $eq: 'Offer' } }
|
|
52
|
-
// }
|
|
53
|
-
// );
|
|
54
|
-
// console.log('numCatalogs:', numCatalogs);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
main()
|
|
58
|
-
.then(console.log)
|
|
59
|
-
.catch(console.error);
|