@chevre/domain 25.0.0-alpha.3 → 25.0.0-alpha.4
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.
|
@@ -1,15 +1,23 @@
|
|
|
1
|
-
import type { Connection } from 'mongoose';
|
|
1
|
+
import type { Connection, FilterQuery } from 'mongoose';
|
|
2
|
+
import { IDocType } from './mongoose/schemas/emailMessages';
|
|
2
3
|
import { factory } from '../factory';
|
|
3
|
-
export type IEmailMessage =
|
|
4
|
+
export type IEmailMessage = IDocType & {
|
|
5
|
+
id: string;
|
|
6
|
+
};
|
|
4
7
|
export interface ISearchConditions {
|
|
5
8
|
limit?: number;
|
|
6
9
|
page?: number;
|
|
7
|
-
sort?:
|
|
10
|
+
sort?: {
|
|
11
|
+
identifier?: factory.sortType;
|
|
12
|
+
};
|
|
8
13
|
project?: {
|
|
9
14
|
id?: {
|
|
10
15
|
$eq?: string;
|
|
11
16
|
};
|
|
12
17
|
};
|
|
18
|
+
id?: {
|
|
19
|
+
$eq?: string;
|
|
20
|
+
};
|
|
13
21
|
identifier?: {
|
|
14
22
|
$eq?: string;
|
|
15
23
|
};
|
|
@@ -29,12 +37,9 @@ export interface ISearchConditions {
|
|
|
29
37
|
export declare class EmailMessageRepo {
|
|
30
38
|
private readonly emailMessageModel;
|
|
31
39
|
constructor(connection: Connection);
|
|
32
|
-
static CREATE_MONGO_CONDITIONS(params: ISearchConditions):
|
|
40
|
+
static CREATE_MONGO_CONDITIONS(params: ISearchConditions): FilterQuery<IDocType>[];
|
|
33
41
|
save(params: IEmailMessage): Promise<any>;
|
|
34
|
-
|
|
35
|
-
id: string;
|
|
36
|
-
}): Promise<IEmailMessage>;
|
|
37
|
-
search(params: ISearchConditions): Promise<IEmailMessage[]>;
|
|
42
|
+
findEmailMessages(params: ISearchConditions): Promise<IEmailMessage[]>;
|
|
38
43
|
deleteById(params: {
|
|
39
44
|
id: string;
|
|
40
45
|
}): Promise<void>;
|
|
@@ -4,6 +4,17 @@ exports.EmailMessageRepo = void 0;
|
|
|
4
4
|
const emailMessages_1 = require("./mongoose/schemas/emailMessages");
|
|
5
5
|
const factory_1 = require("../factory");
|
|
6
6
|
const settings_1 = require("../settings");
|
|
7
|
+
const DEFAULT_PROJECTION = {
|
|
8
|
+
_id: 0,
|
|
9
|
+
id: { $toString: '$_id' },
|
|
10
|
+
project: 1,
|
|
11
|
+
typeOf: 1,
|
|
12
|
+
identifier: 1,
|
|
13
|
+
name: 1,
|
|
14
|
+
about: 1,
|
|
15
|
+
sender: 1,
|
|
16
|
+
text: 1,
|
|
17
|
+
};
|
|
7
18
|
/**
|
|
8
19
|
* Eメールメッセージリポジトリ
|
|
9
20
|
*/
|
|
@@ -13,28 +24,24 @@ class EmailMessageRepo {
|
|
|
13
24
|
this.emailMessageModel = connection.model(emailMessages_1.modelName, (0, emailMessages_1.createSchema)());
|
|
14
25
|
}
|
|
15
26
|
static CREATE_MONGO_CONDITIONS(params) {
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
const andConditions = [
|
|
28
|
+
// { typeOf: factory.creativeWorkType.EmailMessage }
|
|
29
|
+
];
|
|
18
30
|
const projectIdEq = params.project?.id?.$eq;
|
|
19
31
|
if (typeof projectIdEq === 'string') {
|
|
20
|
-
andConditions.push({
|
|
21
|
-
|
|
22
|
-
|
|
32
|
+
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
33
|
+
}
|
|
34
|
+
const idEq = params.id?.$eq;
|
|
35
|
+
if (typeof idEq === 'string') {
|
|
36
|
+
andConditions.push({ _id: { $eq: idEq } });
|
|
23
37
|
}
|
|
24
38
|
const identifierEq = params.identifier?.$eq;
|
|
25
39
|
if (typeof identifierEq === 'string') {
|
|
26
|
-
andConditions.push({
|
|
27
|
-
identifier: { $eq: identifierEq }
|
|
28
|
-
});
|
|
40
|
+
andConditions.push({ identifier: { $eq: identifierEq } });
|
|
29
41
|
}
|
|
30
42
|
const aboutIdentifierEq = params.about?.identifier?.$eq;
|
|
31
43
|
if (typeof aboutIdentifierEq === 'string') {
|
|
32
|
-
andConditions.push({
|
|
33
|
-
'about.identifier': {
|
|
34
|
-
$exists: true,
|
|
35
|
-
$eq: aboutIdentifierEq
|
|
36
|
-
}
|
|
37
|
-
});
|
|
44
|
+
andConditions.push({ 'about.identifier': { $exists: true, $eq: aboutIdentifierEq } });
|
|
38
45
|
}
|
|
39
46
|
return andConditions;
|
|
40
47
|
}
|
|
@@ -45,7 +52,7 @@ class EmailMessageRepo {
|
|
|
45
52
|
}
|
|
46
53
|
else {
|
|
47
54
|
// 上書き禁止属性を除外(2022-08-24~)
|
|
48
|
-
const { id, identifier, project, typeOf, ...updateFields } = params;
|
|
55
|
+
const { id: _id, identifier: _identifier, project: _project, typeOf: _typeOf, ...updateFields } = params;
|
|
49
56
|
doc = await this.emailMessageModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
|
|
50
57
|
.exec();
|
|
51
58
|
}
|
|
@@ -54,37 +61,20 @@ class EmailMessageRepo {
|
|
|
54
61
|
}
|
|
55
62
|
return doc.toObject();
|
|
56
63
|
}
|
|
57
|
-
async
|
|
58
|
-
const doc = await this.emailMessageModel.findOne({ _id: params.id }, {
|
|
59
|
-
__v: 0,
|
|
60
|
-
createdAt: 0,
|
|
61
|
-
updatedAt: 0
|
|
62
|
-
})
|
|
63
|
-
.exec();
|
|
64
|
-
if (doc === null) {
|
|
65
|
-
throw new factory_1.factory.errors.NotFound(this.emailMessageModel.modelName);
|
|
66
|
-
}
|
|
67
|
-
return doc.toObject();
|
|
68
|
-
}
|
|
69
|
-
async search(params) {
|
|
64
|
+
async findEmailMessages(params) {
|
|
70
65
|
const conditions = EmailMessageRepo.CREATE_MONGO_CONDITIONS(params);
|
|
71
|
-
const query = this.emailMessageModel.find({ $and: conditions },
|
|
72
|
-
__v: 0,
|
|
73
|
-
createdAt: 0,
|
|
74
|
-
updatedAt: 0
|
|
75
|
-
});
|
|
66
|
+
const query = this.emailMessageModel.find({ $and: conditions }, DEFAULT_PROJECTION);
|
|
76
67
|
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
77
68
|
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
78
69
|
query.limit(params.limit)
|
|
79
70
|
.skip(params.limit * (page - 1));
|
|
80
71
|
}
|
|
81
|
-
/* istanbul ignore else */
|
|
82
72
|
if (params.sort !== undefined) {
|
|
83
73
|
query.sort(params.sort);
|
|
84
74
|
}
|
|
85
75
|
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
86
|
-
.
|
|
87
|
-
.
|
|
76
|
+
.lean()
|
|
77
|
+
.exec();
|
|
88
78
|
}
|
|
89
79
|
async deleteById(params) {
|
|
90
80
|
await this.emailMessageModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
2
|
import { IVirtuals } from '../virtuals';
|
|
3
3
|
import { factory } from '../../../factory';
|
|
4
|
-
type IDocType = factory.creativeWork.message.email.ICreativeWork
|
|
4
|
+
type IDocType = Pick<factory.creativeWork.message.email.ICreativeWork, 'identifier' | 'name' | 'project' | 'sender' | 'text' | 'typeOf'> & {
|
|
5
|
+
about: Pick<factory.creativeWork.message.email.IAbout, 'name' | 'typeOf'> & {
|
|
6
|
+
/**
|
|
7
|
+
* 現時点でOnEventStatusChangedしかサポートしていない
|
|
8
|
+
* 2026-06-18
|
|
9
|
+
*/
|
|
10
|
+
identifier: factory.creativeWork.message.email.AboutIdentifier.OnEventStatusChanged;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
5
13
|
type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
|
|
6
14
|
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
7
15
|
type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
|
|
@@ -8,12 +8,9 @@ const settings_1 = require("../../../settings");
|
|
|
8
8
|
const modelName = 'EmailMessage';
|
|
9
9
|
exports.modelName = modelName;
|
|
10
10
|
const schemaDefinition = {
|
|
11
|
-
project: mongoose_1.SchemaTypes.Mixed,
|
|
12
|
-
typeOf: {
|
|
13
|
-
|
|
14
|
-
required: true
|
|
15
|
-
},
|
|
16
|
-
identifier: String,
|
|
11
|
+
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
|
+
typeOf: { type: String, required: true },
|
|
13
|
+
identifier: { type: String, required: true },
|
|
17
14
|
name: mongoose_1.SchemaTypes.Mixed,
|
|
18
15
|
about: mongoose_1.SchemaTypes.Mixed,
|
|
19
16
|
sender: mongoose_1.SchemaTypes.Mixed,
|
|
@@ -54,25 +51,13 @@ function createSchema() {
|
|
|
54
51
|
return schema;
|
|
55
52
|
}
|
|
56
53
|
const indexes = [
|
|
57
|
-
// [ // discontinue(2024-08-07~)
|
|
58
|
-
// { createdAt: 1 },
|
|
59
|
-
// { name: 'searchByCreatedAt' }
|
|
60
|
-
// ],
|
|
61
|
-
// [
|
|
62
|
-
// { updatedAt: 1 },
|
|
63
|
-
// { name: 'searchByUpdatedAt' }
|
|
64
|
-
// ],
|
|
65
54
|
[
|
|
66
55
|
{ identifier: 1 },
|
|
67
|
-
{
|
|
68
|
-
name: 'searchByIdentifier'
|
|
69
|
-
}
|
|
56
|
+
{ name: 'searchByIdentifier' }
|
|
70
57
|
],
|
|
71
58
|
[
|
|
72
59
|
{ 'project.id': 1, identifier: 1 },
|
|
73
|
-
{
|
|
74
|
-
name: 'searchByProjectId'
|
|
75
|
-
}
|
|
60
|
+
{ name: 'searchByProjectId' }
|
|
76
61
|
]
|
|
77
62
|
];
|
|
78
63
|
exports.indexes = indexes;
|
package/package.json
CHANGED