@chevre/domain 24.1.0-alpha.0 → 24.1.0-alpha.10
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/README.md +0 -2
- package/lib/chevre/repo/acceptedOffer.d.ts +1 -1
- package/lib/chevre/repo/acceptedOffer.js +10 -10
- package/lib/chevre/repo/accountingReport.d.ts +9 -2
- package/lib/chevre/repo/accountingReport.js +30 -28
- package/lib/chevre/repo/aggregateReservation.d.ts +6 -0
- package/lib/chevre/repo/aggregateReservation.js +9 -0
- package/lib/chevre/repo/factory/reservation/createMongoConditions.js +155 -180
- package/lib/chevre/repo/mongoose/schemas/accountingReport.js +10 -9
- package/lib/chevre/repo/mongoose/schemas/order.js +108 -108
- package/lib/chevre/repo/mongoose/schemas/reservation.d.ts +1 -0
- package/lib/chevre/repo/mongoose/schemas/reservation.js +117 -117
- package/lib/chevre/repo/order.d.ts +2 -1
- package/lib/chevre/repo/order.js +171 -170
- package/lib/chevre/repo/project.d.ts +0 -3
- package/lib/chevre/repo/project.js +0 -10
- package/lib/chevre/repo/reservation.d.ts +2 -0
- package/lib/chevre/service/aggregation/event/aggregateOffers.js +17 -26
- package/lib/chevre/service/order/createAccountingReportIfNotExist.d.ts +1 -3
- package/lib/chevre/service/order/createAccountingReportIfNotExist.js +67 -72
- package/lib/chevre/service/reserve/useReservation.d.ts +1 -1
- package/lib/chevre/service/reserve/useReservation.js +20 -24
- package/lib/chevre/service/task/createAccountingReport.js +11 -9
- package/lib/chevre/service/task/onResourceDeleted.js +7 -8
- package/lib/chevre/service/task/onResourceUpdated.js +7 -8
- package/lib/chevre/service/task/useReservation.d.ts +2 -2
- package/lib/chevre/service/task/useReservation.js +6 -18
- package/lib/chevre/service/taskHandler.js +1 -0
- package/package.json +2 -2
- package/lib/chevre/repo/mongoose/schemas/productModel.d.ts +0 -33
- package/lib/chevre/repo/mongoose/schemas/productModel.js +0 -57
- package/lib/chevre/repo/productModel.d.ts +0 -27
- package/lib/chevre/repo/productModel.js +0 -170
- package/lib/chevre/service/task/onResourceUpdated/onCategoryCodeUpdated.d.ts +0 -15
- package/lib/chevre/service/task/onResourceUpdated/onCategoryCodeUpdated.js +0 -16
- package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.d.ts +0 -15
- package/lib/chevre/service/task/onResourceUpdated/syncCategoryCode.js +0 -47
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProductModelRepo = void 0;
|
|
4
|
-
const factory_1 = require("../factory");
|
|
5
|
-
// import { MONGO_MAX_TIME_MS } from '../settings';
|
|
6
|
-
const productModel_1 = require("./mongoose/schemas/productModel");
|
|
7
|
-
// type IKeyOfProjection = keyof IProductModel | '_id';
|
|
8
|
-
// type ISearchConditions = Pick<factory.product.ISearchConditions, 'id' | 'limit' | 'page' | 'project'> & {
|
|
9
|
-
// category?: {
|
|
10
|
-
// codeValue?: { $in?: string[] };
|
|
11
|
-
// inCodeSet?: { identifier?: { $eq?: string } };
|
|
12
|
-
// };
|
|
13
|
-
// };
|
|
14
|
-
/**
|
|
15
|
-
* プロダクトモデルリポジトリ
|
|
16
|
-
*/
|
|
17
|
-
class ProductModelRepo {
|
|
18
|
-
productModelModel;
|
|
19
|
-
constructor(connection) {
|
|
20
|
-
this.productModelModel = connection.model(productModel_1.modelName, (0, productModel_1.createSchema)());
|
|
21
|
-
}
|
|
22
|
-
// public static CREATE_MONGO_CONDITIONS(params: ISearchConditions) {
|
|
23
|
-
// // MongoDB検索条件
|
|
24
|
-
// const andConditions: FilterQuery<factory.product.IProduct>[] = [];
|
|
25
|
-
// const projectIdEq = params.project?.id?.$eq;
|
|
26
|
-
// if (typeof projectIdEq === 'string') {
|
|
27
|
-
// andConditions.push({
|
|
28
|
-
// 'project.id': { $eq: projectIdEq }
|
|
29
|
-
// });
|
|
30
|
-
// }
|
|
31
|
-
// const idEq = params.id?.$eq;
|
|
32
|
-
// if (typeof idEq === 'string') {
|
|
33
|
-
// andConditions.push({ _id: { $eq: idEq } });
|
|
34
|
-
// }
|
|
35
|
-
// const idIn = params.id?.$in;
|
|
36
|
-
// if (Array.isArray(idIn)) {
|
|
37
|
-
// andConditions.push({ _id: { $in: idIn } });
|
|
38
|
-
// }
|
|
39
|
-
// const categoryCodeValueIn = params.category?.codeValue?.$in;
|
|
40
|
-
// if (Array.isArray(categoryCodeValueIn)) {
|
|
41
|
-
// andConditions.push({ 'category.codeValue': { $exists: true, $in: categoryCodeValueIn } });
|
|
42
|
-
// }
|
|
43
|
-
// const categoryInCodeSetIdentifierEq = params.category?.inCodeSet?.identifier?.$eq;
|
|
44
|
-
// if (typeof categoryInCodeSetIdentifierEq === 'string') {
|
|
45
|
-
// andConditions.push({ 'category.inCodeSet.identifier': { $exists: true, $eq: categoryInCodeSetIdentifierEq } });
|
|
46
|
-
// }
|
|
47
|
-
// return andConditions;
|
|
48
|
-
// }
|
|
49
|
-
// public async search(
|
|
50
|
-
// conditions: ISearchConditions,
|
|
51
|
-
// inclusion: IKeyOfProjection[],
|
|
52
|
-
// exclusion: IKeyOfProjection[]
|
|
53
|
-
// ): Promise<IProductModel[]> {
|
|
54
|
-
// const andConditions = ProductModelRepo.CREATE_MONGO_CONDITIONS(conditions);
|
|
55
|
-
// let projection: Record<string, number> = {};
|
|
56
|
-
// if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
57
|
-
// inclusion.forEach((field) => {
|
|
58
|
-
// projection[field] = 1;
|
|
59
|
-
// });
|
|
60
|
-
// } else {
|
|
61
|
-
// projection = {
|
|
62
|
-
// __v: 0,
|
|
63
|
-
// createdAt: 0,
|
|
64
|
-
// updatedAt: 0
|
|
65
|
-
// };
|
|
66
|
-
// if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
67
|
-
// exclusion.forEach((field) => {
|
|
68
|
-
// projection[field] = 0;
|
|
69
|
-
// });
|
|
70
|
-
// }
|
|
71
|
-
// }
|
|
72
|
-
// const query = this.productModelModel.find(
|
|
73
|
-
// (andConditions.length > 0) ? { $and: andConditions } : {},
|
|
74
|
-
// projection
|
|
75
|
-
// );
|
|
76
|
-
// if (typeof conditions.limit === 'number' && conditions.limit > 0) {
|
|
77
|
-
// const page: number = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
|
|
78
|
-
// query.limit(conditions.limit)
|
|
79
|
-
// .skip(conditions.limit * (page - 1));
|
|
80
|
-
// }
|
|
81
|
-
// // if (conditions.sort?.productID !== undefined) {
|
|
82
|
-
// // query.sort({ productID: conditions.sort.productID });
|
|
83
|
-
// // }
|
|
84
|
-
// return query.setOptions({ maxTimeMS: MONGO_MAX_TIME_MS })
|
|
85
|
-
// .exec()
|
|
86
|
-
// .then((docs) => docs.map((doc) => doc.toObject({ virtuals: true })));
|
|
87
|
-
// }
|
|
88
|
-
// public async deleteById(params: { id: string }) {
|
|
89
|
-
// await this.productModelModel.findOneAndDelete({ _id: params.id })
|
|
90
|
-
// .exec();
|
|
91
|
-
// }
|
|
92
|
-
// /**
|
|
93
|
-
// * プロダクトを保管する
|
|
94
|
-
// */
|
|
95
|
-
// public async save(params: {
|
|
96
|
-
// /**
|
|
97
|
-
// * idを指定すれば更新
|
|
98
|
-
// */
|
|
99
|
-
// id?: string;
|
|
100
|
-
// $set: Omit<IProductModel, 'id'> & { id?: never };
|
|
101
|
-
// }): Promise<{ id: string }> {
|
|
102
|
-
// let savedId: string;
|
|
103
|
-
// if (typeof params.id === 'string') {
|
|
104
|
-
// // 上書き禁止属性を除外
|
|
105
|
-
// const { category, id, project, typeOf, ...setFields } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
106
|
-
// const updatedDoc = await this.productModelModel.findOneAndUpdate(
|
|
107
|
-
// { _id: { $eq: params.id } },
|
|
108
|
-
// {
|
|
109
|
-
// $set: setFields
|
|
110
|
-
// },
|
|
111
|
-
// { upsert: false, new: true, projection: { _id: 1 } }
|
|
112
|
-
// )
|
|
113
|
-
// .exec();
|
|
114
|
-
// if (updatedDoc === null) {
|
|
115
|
-
// throw new factory.errors.NotFound(this.productModelModel.modelName);
|
|
116
|
-
// }
|
|
117
|
-
// savedId = updatedDoc.id;
|
|
118
|
-
// } else {
|
|
119
|
-
// const { id, ...createParams } = params.$set; // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
120
|
-
// const createdDoc = await this.productModelModel.create(createParams);
|
|
121
|
-
// savedId = createdDoc.id;
|
|
122
|
-
// }
|
|
123
|
-
// // if (doc === null) {
|
|
124
|
-
// // throw new factory.errors.NotFound(this.productModelModel.modelName);
|
|
125
|
-
// // }
|
|
126
|
-
// return { id: savedId };
|
|
127
|
-
// }
|
|
128
|
-
/**
|
|
129
|
-
* 区分から同期する
|
|
130
|
-
*/
|
|
131
|
-
async upsertByCategory(params) {
|
|
132
|
-
const upsertingProductModel = {
|
|
133
|
-
project: { id: params.category.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
134
|
-
typeOf: 'ProductModel',
|
|
135
|
-
category: {
|
|
136
|
-
codeValue: params.category.codeValue,
|
|
137
|
-
inCodeSet: params.category.inCodeSet,
|
|
138
|
-
id: params.category.id
|
|
139
|
-
},
|
|
140
|
-
name: params.category.name,
|
|
141
|
-
offers: [{
|
|
142
|
-
typeOf: factory_1.factory.offerType.Offer
|
|
143
|
-
}]
|
|
144
|
-
};
|
|
145
|
-
const { project, typeOf, offers, category, ...setFields } = upsertingProductModel;
|
|
146
|
-
const doc = await this.productModelModel.findOneAndUpdate({
|
|
147
|
-
'project.id': { $eq: upsertingProductModel.project.id },
|
|
148
|
-
'category.id': { $exists: true, $eq: upsertingProductModel.category.id }
|
|
149
|
-
}, {
|
|
150
|
-
$setOnInsert: { project, typeOf, offers, category },
|
|
151
|
-
$set: setFields
|
|
152
|
-
}, { new: true, upsert: true, projection: { _id: 1 } })
|
|
153
|
-
.exec();
|
|
154
|
-
if (doc === null) {
|
|
155
|
-
throw new factory_1.factory.errors.NotFound(this.productModelModel.modelName);
|
|
156
|
-
}
|
|
157
|
-
return doc.toObject({ virtuals: true });
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* 区分から削除する
|
|
161
|
-
*/
|
|
162
|
-
async deleteByCategory(params) {
|
|
163
|
-
await this.productModelModel.deleteMany({
|
|
164
|
-
'project.id': { $eq: params.category.project.id },
|
|
165
|
-
'category.id': { $exists: true, $eq: params.category.id }
|
|
166
|
-
})
|
|
167
|
-
.exec();
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.ProductModelRepo = ProductModelRepo;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CategoryCodeRepo } from '../../../repo/categoryCode';
|
|
2
|
-
import type { ProductModelRepo } from '../../../repo/productModel';
|
|
3
|
-
/**
|
|
4
|
-
* 区分変更時処理
|
|
5
|
-
*/
|
|
6
|
-
export declare function onCategoryCodeUpdated(params: {
|
|
7
|
-
project: {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
ids: string[];
|
|
11
|
-
isDeleted: boolean;
|
|
12
|
-
}): (repos: {
|
|
13
|
-
categoryCode: CategoryCodeRepo;
|
|
14
|
-
productModel: ProductModelRepo;
|
|
15
|
-
}) => Promise<void>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onCategoryCodeUpdated = onCategoryCodeUpdated;
|
|
4
|
-
const syncCategoryCode_1 = require("./syncCategoryCode");
|
|
5
|
-
/**
|
|
6
|
-
* 区分変更時処理
|
|
7
|
-
*/
|
|
8
|
-
function onCategoryCodeUpdated(params) {
|
|
9
|
-
return async (repos) => {
|
|
10
|
-
await (0, syncCategoryCode_1.syncCategoryCode)({
|
|
11
|
-
project: { id: params.project.id },
|
|
12
|
-
ids: params.ids,
|
|
13
|
-
isDeleted: false
|
|
14
|
-
})(repos);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { CategoryCodeRepo } from '../../../repo/categoryCode';
|
|
2
|
-
import type { ProductModelRepo } from '../../../repo/productModel';
|
|
3
|
-
/**
|
|
4
|
-
* 区分を他リソースへ同期する
|
|
5
|
-
*/
|
|
6
|
-
export declare function syncCategoryCode(params: {
|
|
7
|
-
project: {
|
|
8
|
-
id: string;
|
|
9
|
-
};
|
|
10
|
-
ids: string[];
|
|
11
|
-
isDeleted: boolean;
|
|
12
|
-
}): (repos: {
|
|
13
|
-
categoryCode: CategoryCodeRepo;
|
|
14
|
-
productModel: ProductModelRepo;
|
|
15
|
-
}) => Promise<void>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncCategoryCode = syncCategoryCode;
|
|
4
|
-
const factory_1 = require("../../../factory");
|
|
5
|
-
/**
|
|
6
|
-
* 区分を他リソースへ同期する
|
|
7
|
-
*/
|
|
8
|
-
function syncCategoryCode(params) {
|
|
9
|
-
return async (repos) => {
|
|
10
|
-
if (params.isDeleted) {
|
|
11
|
-
for (const categoryCodeId of params.ids) {
|
|
12
|
-
// プロダクトモデルを削除
|
|
13
|
-
await repos.productModel.deleteByCategory({
|
|
14
|
-
category: {
|
|
15
|
-
project: { id: params.project.id, typeOf: factory_1.factory.organizationType.Project },
|
|
16
|
-
id: categoryCodeId
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
for (const categoryCodeId of params.ids) {
|
|
23
|
-
const syncingCategoryCode = (await repos.categoryCode.projectCategoryCodeFields({
|
|
24
|
-
limit: 1,
|
|
25
|
-
page: 1,
|
|
26
|
-
project: { id: { $eq: params.project.id } },
|
|
27
|
-
id: { $eq: categoryCodeId }
|
|
28
|
-
}, ['codeValue', 'inCodeSet', 'name', 'project', 'id'])).shift();
|
|
29
|
-
if (syncingCategoryCode !== undefined) {
|
|
30
|
-
switch (syncingCategoryCode.inCodeSet.identifier) {
|
|
31
|
-
case factory_1.factory.categoryCode.CategorySetIdentifier.SeatingType:
|
|
32
|
-
// プロダクトモデルへ同期
|
|
33
|
-
await repos.productModel.upsertByCategory({
|
|
34
|
-
category: {
|
|
35
|
-
...syncingCategoryCode,
|
|
36
|
-
id: categoryCodeId
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
default:
|
|
41
|
-
// no op
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|