@chevre/domain 22.3.0-alpha.3 → 22.3.0-alpha.5
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/projectFields.ts +5 -15
- package/lib/chevre/repo/customer.d.ts +12 -6
- package/lib/chevre/repo/customer.js +40 -13
- package/lib/chevre/repo/mongoose/schemas/account.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/account.js +29 -13
- package/lib/chevre/repo/mongoose/schemas/accountingReport.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/accountingReport.js +17 -12
- package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +9 -15
- package/package.json +1 -1
|
@@ -12,29 +12,19 @@ mongoose.Model.on('index', (...args) => {
|
|
|
12
12
|
async function main() {
|
|
13
13
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const customerRepo = await chevre.repository.Customer.createInstance(mongoose.connection);
|
|
16
16
|
|
|
17
|
-
const docs = await
|
|
17
|
+
const docs = await customerRepo.projectFields(
|
|
18
18
|
{
|
|
19
19
|
limit: 1,
|
|
20
|
-
page: 1
|
|
21
|
-
typeOf: { $eq: chevre.factory.actionType.AuthorizeAction }
|
|
20
|
+
page: 1
|
|
22
21
|
},
|
|
23
|
-
['
|
|
24
|
-
['
|
|
22
|
+
['contactPoint', 'additionalProperty'],
|
|
23
|
+
['contactPoint', 'additionalProperty']
|
|
25
24
|
);
|
|
26
25
|
// tslint:disable-next-line:no-null-keyword
|
|
27
26
|
console.dir(docs, { depth: null });
|
|
28
27
|
console.log(docs.length, 'docs found');
|
|
29
|
-
|
|
30
|
-
const actions = await actionRepo.searchByOrderNumber(
|
|
31
|
-
{
|
|
32
|
-
orderNumber: 'CIN9-4893721-9248784'
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
// tslint:disable-next-line:no-null-keyword
|
|
36
|
-
console.dir(actions, { depth: null });
|
|
37
|
-
console.log(actions.length, 'actions found');
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
main()
|
|
@@ -24,7 +24,10 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import type { Connection, FilterQuery } from 'mongoose';
|
|
26
26
|
import * as factory from '../factory';
|
|
27
|
-
type
|
|
27
|
+
type IUnset = {
|
|
28
|
+
[key in keyof Pick<factory.customer.ICustomer, 'telephone' | 'url'>]?: 1;
|
|
29
|
+
};
|
|
30
|
+
type IKeyOfProjection = keyof factory.customer.ICustomer;
|
|
28
31
|
/**
|
|
29
32
|
* 顧客リポジトリ
|
|
30
33
|
*/
|
|
@@ -34,14 +37,17 @@ export declare class CustomerRepo {
|
|
|
34
37
|
static CREATE_MONGO_CONDITIONS(params: factory.customer.ISearchConditions): FilterQuery<factory.customer.ICustomer>[];
|
|
35
38
|
save(params: {
|
|
36
39
|
id?: string;
|
|
37
|
-
attributes: factory.customer.ICustomer
|
|
38
|
-
|
|
40
|
+
attributes: Omit<factory.customer.ICustomer, 'id'> & {
|
|
41
|
+
id?: never;
|
|
42
|
+
$unset?: IUnset;
|
|
43
|
+
};
|
|
44
|
+
}): Promise<{
|
|
45
|
+
id: string;
|
|
46
|
+
}>;
|
|
39
47
|
/**
|
|
40
48
|
* 顧客検索
|
|
41
49
|
*/
|
|
42
|
-
|
|
43
|
-
[key in IKeyOfProjection]?: 0;
|
|
44
|
-
}): Promise<factory.customer.ICustomer[]>;
|
|
50
|
+
projectFields(conditions: factory.customer.ISearchConditions, inclusion: IKeyOfProjection[], exclusion: IKeyOfProjection[]): Promise<factory.customer.ICustomer[]>;
|
|
45
51
|
deleteById(params: {
|
|
46
52
|
id: string;
|
|
47
53
|
}): Promise<void>;
|
|
@@ -24,6 +24,17 @@ exports.CustomerRepo = void 0;
|
|
|
24
24
|
const customer_1 = require("./mongoose/schemas/customer");
|
|
25
25
|
const factory = require("../factory");
|
|
26
26
|
const settings_1 = require("../settings");
|
|
27
|
+
const AVAILABLE_PROJECT_FIELDS = [
|
|
28
|
+
'additionalProperty',
|
|
29
|
+
'contactPoint',
|
|
30
|
+
// 'email',
|
|
31
|
+
'branchCode',
|
|
32
|
+
'name',
|
|
33
|
+
'project',
|
|
34
|
+
'typeOf',
|
|
35
|
+
'url'
|
|
36
|
+
// 'telephone'f
|
|
37
|
+
];
|
|
27
38
|
/**
|
|
28
39
|
* 顧客リポジトリ
|
|
29
40
|
*/
|
|
@@ -67,33 +78,49 @@ class CustomerRepo {
|
|
|
67
78
|
return andConditions;
|
|
68
79
|
}
|
|
69
80
|
save(params) {
|
|
81
|
+
var _a, _b;
|
|
70
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
let
|
|
83
|
+
let savedId;
|
|
72
84
|
if (params.id === undefined) {
|
|
73
|
-
const
|
|
74
|
-
|
|
85
|
+
const _c = params.attributes, { id, $unset } = _c, creatingDoc = __rest(_c, ["id", "$unset"]);
|
|
86
|
+
const result = yield this.customerModel.insertMany(creatingDoc, { rawResult: true });
|
|
87
|
+
const insertedId = (_b = (_a = result.insertedIds) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.toHexString();
|
|
88
|
+
if (typeof insertedId !== 'string') {
|
|
89
|
+
throw new factory.errors.Internal(`customer not saved unexpectedly. result:${JSON.stringify(result)}`);
|
|
90
|
+
}
|
|
91
|
+
savedId = insertedId;
|
|
75
92
|
}
|
|
76
93
|
else {
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
|
|
94
|
+
const _d = params.attributes, { id, branchCode, project, typeOf, $unset } = _d, updateFields = __rest(_d, ["id", "branchCode", "project", "typeOf", "$unset"]);
|
|
95
|
+
const doc = yield this.customerModel.findOneAndUpdate({ _id: { $eq: params.id } }, Object.assign({ $set: updateFields }, ($unset !== undefined) ? { $unset } : undefined), { upsert: false, new: true, projection: { _id: 1, id: { $toString: '$_id' } } })
|
|
96
|
+
.lean()
|
|
80
97
|
.exec();
|
|
81
98
|
if (doc === null) {
|
|
82
99
|
throw new factory.errors.NotFound(this.customerModel.modelName);
|
|
83
100
|
}
|
|
84
|
-
|
|
101
|
+
savedId = params.id;
|
|
85
102
|
}
|
|
86
|
-
return
|
|
103
|
+
return { id: savedId };
|
|
87
104
|
});
|
|
88
105
|
}
|
|
89
106
|
/**
|
|
90
107
|
* 顧客検索
|
|
91
108
|
*/
|
|
92
|
-
|
|
109
|
+
projectFields(conditions, inclusion, exclusion) {
|
|
93
110
|
var _a;
|
|
94
111
|
return __awaiter(this, void 0, void 0, function* () {
|
|
95
112
|
const andConditions = CustomerRepo.CREATE_MONGO_CONDITIONS(conditions);
|
|
96
|
-
|
|
113
|
+
let positiveProjectionFields = AVAILABLE_PROJECT_FIELDS;
|
|
114
|
+
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
115
|
+
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
if (Array.isArray(exclusion) && exclusion.length > 0) {
|
|
119
|
+
positiveProjectionFields = positiveProjectionFields.filter((key) => !exclusion.includes(key));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const projection = Object.assign({ _id: 0, id: { $toString: '$_id' } }, Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1]))));
|
|
123
|
+
const query = this.customerModel.find((andConditions.length > 0) ? { $and: andConditions } : {}, projection);
|
|
97
124
|
if (typeof conditions.limit === 'number' && conditions.limit > 0) {
|
|
98
125
|
const page = (typeof conditions.page === 'number' && conditions.page > 0) ? conditions.page : 1;
|
|
99
126
|
query.limit(conditions.limit)
|
|
@@ -105,13 +132,13 @@ class CustomerRepo {
|
|
|
105
132
|
query.sort({ branchCode: conditions.sort.branchCode });
|
|
106
133
|
}
|
|
107
134
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
108
|
-
.
|
|
109
|
-
.
|
|
135
|
+
.lean() // 2024-09-03~
|
|
136
|
+
.exec();
|
|
110
137
|
});
|
|
111
138
|
}
|
|
112
139
|
deleteById(params) {
|
|
113
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
-
yield this.customerModel.findOneAndRemove({ _id: params.id })
|
|
141
|
+
yield this.customerModel.findOneAndRemove({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
|
|
115
142
|
.exec();
|
|
116
143
|
});
|
|
117
144
|
}
|
|
@@ -5,6 +5,6 @@ type IModel = Model<IDocType>;
|
|
|
5
5
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
6
6
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
7
7
|
declare const modelName = "Account";
|
|
8
|
-
declare function createSchema(): ISchema;
|
|
9
8
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
9
|
+
declare function createSchema(): ISchema;
|
|
10
10
|
export { createSchema, IModel, indexes, modelName };
|
|
@@ -6,7 +6,18 @@ const writeConcern_1 = require("../writeConcern");
|
|
|
6
6
|
const settings_1 = require("../../../settings");
|
|
7
7
|
const modelName = 'Account';
|
|
8
8
|
exports.modelName = modelName;
|
|
9
|
-
const schemaDefinition = {
|
|
9
|
+
const schemaDefinition = {
|
|
10
|
+
project: mongoose_1.SchemaTypes.Mixed,
|
|
11
|
+
typeOf: String,
|
|
12
|
+
accountType: String,
|
|
13
|
+
accountNumber: String,
|
|
14
|
+
name: String,
|
|
15
|
+
balance: Number,
|
|
16
|
+
availableBalance: Number,
|
|
17
|
+
pendingTransactions: [mongoose_1.SchemaTypes.Mixed],
|
|
18
|
+
openDate: Date,
|
|
19
|
+
closeDate: Date
|
|
20
|
+
};
|
|
10
21
|
const schemaOptions = {
|
|
11
22
|
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
12
23
|
autoCreate: false,
|
|
@@ -14,7 +25,7 @@ const schemaOptions = {
|
|
|
14
25
|
id: true,
|
|
15
26
|
read: settings_1.MONGO_READ_PREFERENCE,
|
|
16
27
|
writeConcern: writeConcern_1.writeConcern,
|
|
17
|
-
strict:
|
|
28
|
+
strict: true,
|
|
18
29
|
strictQuery: false,
|
|
19
30
|
timestamps: {
|
|
20
31
|
createdAt: 'createdAt',
|
|
@@ -33,17 +44,6 @@ const schemaOptions = {
|
|
|
33
44
|
versionKey: false
|
|
34
45
|
}
|
|
35
46
|
};
|
|
36
|
-
/**
|
|
37
|
-
* 口座スキーマ
|
|
38
|
-
*/
|
|
39
|
-
let schema;
|
|
40
|
-
function createSchema() {
|
|
41
|
-
if (schema === undefined) {
|
|
42
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
43
|
-
}
|
|
44
|
-
return schema;
|
|
45
|
-
}
|
|
46
|
-
exports.createSchema = createSchema;
|
|
47
47
|
const indexes = [
|
|
48
48
|
// 口座タイプと口座番号でユニーク
|
|
49
49
|
[
|
|
@@ -108,3 +108,19 @@ const indexes = [
|
|
|
108
108
|
]
|
|
109
109
|
];
|
|
110
110
|
exports.indexes = indexes;
|
|
111
|
+
/**
|
|
112
|
+
* 口座スキーマ
|
|
113
|
+
*/
|
|
114
|
+
let schema;
|
|
115
|
+
function createSchema() {
|
|
116
|
+
if (schema === undefined) {
|
|
117
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
118
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
119
|
+
indexes.forEach((indexParams) => {
|
|
120
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return schema;
|
|
125
|
+
}
|
|
126
|
+
exports.createSchema = createSchema;
|
|
@@ -19,6 +19,6 @@ type IModel = Model<IDocType>;
|
|
|
19
19
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
20
20
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
21
21
|
declare const modelName = "AccountingReport";
|
|
22
|
-
declare function createSchema(): ISchema;
|
|
23
22
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
23
|
+
declare function createSchema(): ISchema;
|
|
24
24
|
export { createSchema, IModel, indexes, modelName };
|
|
@@ -19,7 +19,7 @@ const schemaOptions = {
|
|
|
19
19
|
id: true,
|
|
20
20
|
read: settings_1.MONGO_READ_PREFERENCE,
|
|
21
21
|
writeConcern: writeConcern_1.writeConcern,
|
|
22
|
-
strict:
|
|
22
|
+
strict: true,
|
|
23
23
|
strictQuery: false,
|
|
24
24
|
timestamps: false,
|
|
25
25
|
versionKey: false,
|
|
@@ -36,17 +36,6 @@ const schemaOptions = {
|
|
|
36
36
|
versionKey: false
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
/**
|
|
40
|
-
* 経理レポートスキーマ
|
|
41
|
-
*/
|
|
42
|
-
let schema;
|
|
43
|
-
function createSchema() {
|
|
44
|
-
if (schema === undefined) {
|
|
45
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
46
|
-
}
|
|
47
|
-
return schema;
|
|
48
|
-
}
|
|
49
|
-
exports.createSchema = createSchema;
|
|
50
39
|
const indexes = [
|
|
51
40
|
[
|
|
52
41
|
{ 'mainEntity.orderDate': -1 },
|
|
@@ -138,3 +127,19 @@ const indexes = [
|
|
|
138
127
|
]
|
|
139
128
|
];
|
|
140
129
|
exports.indexes = indexes;
|
|
130
|
+
/**
|
|
131
|
+
* 経理レポートスキーマ
|
|
132
|
+
*/
|
|
133
|
+
let schema;
|
|
134
|
+
function createSchema() {
|
|
135
|
+
if (schema === undefined) {
|
|
136
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
137
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
138
|
+
indexes.forEach((indexParams) => {
|
|
139
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return schema;
|
|
144
|
+
}
|
|
145
|
+
exports.createSchema = createSchema;
|
|
@@ -5,6 +5,6 @@ type IModel = Model<IDocType>;
|
|
|
5
5
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
6
6
|
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
7
7
|
declare const modelName = "MerchantReturnPolicy";
|
|
8
|
-
declare function createSchema(): ISchema;
|
|
9
8
|
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
9
|
+
declare function createSchema(): ISchema;
|
|
10
10
|
export { createSchema, IModel, indexes, modelName };
|
|
@@ -27,10 +27,8 @@ const schemaOptions = {
|
|
|
27
27
|
writeConcern: writeConcern_1.writeConcern,
|
|
28
28
|
strict: true,
|
|
29
29
|
strictQuery: false,
|
|
30
|
-
timestamps:
|
|
31
|
-
|
|
32
|
-
updatedAt: 'updatedAt'
|
|
33
|
-
},
|
|
30
|
+
timestamps: false,
|
|
31
|
+
versionKey: false,
|
|
34
32
|
toJSON: {
|
|
35
33
|
getters: false,
|
|
36
34
|
virtuals: false,
|
|
@@ -44,6 +42,8 @@ const schemaOptions = {
|
|
|
44
42
|
versionKey: false
|
|
45
43
|
}
|
|
46
44
|
};
|
|
45
|
+
const indexes = [];
|
|
46
|
+
exports.indexes = indexes;
|
|
47
47
|
/**
|
|
48
48
|
* 返品ポリシースキーマ
|
|
49
49
|
*/
|
|
@@ -51,18 +51,12 @@ let schema;
|
|
|
51
51
|
function createSchema() {
|
|
52
52
|
if (schema === undefined) {
|
|
53
53
|
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
54
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
55
|
+
indexes.forEach((indexParams) => {
|
|
56
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
return schema;
|
|
56
61
|
}
|
|
57
62
|
exports.createSchema = createSchema;
|
|
58
|
-
const indexes = [
|
|
59
|
-
[
|
|
60
|
-
{ createdAt: 1 },
|
|
61
|
-
{ name: 'searchByCreatedAt' }
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
{ updatedAt: 1 },
|
|
65
|
-
{ name: 'searchByUpdatedAt' }
|
|
66
|
-
]
|
|
67
|
-
];
|
|
68
|
-
exports.indexes = indexes;
|
package/package.json
CHANGED