@chevre/domain 22.3.0-alpha.1 → 22.3.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/example/src/chevre/aggregateScreeningEventMaxVersion.ts +36 -0
- package/example/src/chevre/aggregation/createAggregateEventTasks.ts +1 -1
- package/example/src/chevre/importEventsFromCOA.ts +2 -0
- package/example/src/chevre/migrateAccountTitleAdditionalProperties.ts +126 -0
- package/example/src/chevre/projectFields.ts +5 -15
- package/example/src/chevre/unsetUnnecessaryFields.ts +16 -3
- package/example/src/chevre/upsertScreeningEventSeriesByVersion.ts +2 -2
- package/lib/chevre/repo/accountTitle.d.ts +4 -0
- package/lib/chevre/repo/accountTitle.js +6 -0
- package/lib/chevre/repo/additionalProperty.d.ts +4 -0
- package/lib/chevre/repo/additionalProperty.js +6 -0
- package/lib/chevre/repo/customer.d.ts +12 -6
- package/lib/chevre/repo/customer.js +40 -13
- package/lib/chevre/repo/event.d.ts +30 -125
- package/lib/chevre/repo/event.js +199 -391
- package/lib/chevre/repo/eventSeries.d.ts +107 -0
- package/lib/chevre/repo/eventSeries.js +603 -0
- 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/accountTitle.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/accountTitle.js +37 -24
- 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/additionalProperty.js +10 -12
- package/lib/chevre/repo/mongoose/schemas/creativeWork.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/creativeWork.js +21 -23
- package/lib/chevre/repo/mongoose/schemas/event.js +5 -12
- package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/merchantReturnPolicy.js +9 -15
- package/lib/chevre/repo/mongoose/schemas/offerItemCondition.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/offerItemCondition.js +21 -23
- package/lib/chevre/repo/mongoose/schemas/place.d.ts +1 -1
- package/lib/chevre/repo/mongoose/schemas/place.js +21 -23
- package/lib/chevre/repo/mongoose/schemas/productModel.js +6 -14
- package/lib/chevre/repo/mongoose/schemas/trip.js +10 -4
- package/lib/chevre/repo/offerItemCondition.d.ts +4 -0
- package/lib/chevre/repo/offerItemCondition.js +6 -0
- package/lib/chevre/repo/place/movieTheater.d.ts +4 -0
- package/lib/chevre/repo/place/movieTheater.js +6 -0
- package/lib/chevre/repo/productModel.d.ts +4 -0
- package/lib/chevre/repo/productModel.js +6 -0
- package/lib/chevre/repo/trip.d.ts +4 -0
- package/lib/chevre/repo/trip.js +6 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +15 -2
- package/lib/chevre/service/aggregation/event/aggregateOffers.js +2 -2
- package/lib/chevre/service/aggregation/event/aggregateScreeningEvent.js +3 -3
- package/lib/chevre/service/aggregation/event/aggregateUseActionsOnEvent.js +1 -1
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +2 -0
- package/lib/chevre/service/assetTransaction/reserve/start.js +1 -1
- package/lib/chevre/service/event/createEvent.d.ts +2 -0
- package/lib/chevre/service/event/createEvent.js +1 -1
- package/lib/chevre/service/event.d.ts +3 -0
- package/lib/chevre/service/event.js +5 -4
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +2 -0
- package/lib/chevre/service/offer/event/authorize.d.ts +2 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.d.ts +3 -0
- package/lib/chevre/service/offer/event/searchEventTicketOffers.js +6 -6
- package/lib/chevre/service/offer/eventServiceByCOA/acceptOffer.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/authorize.js +1 -1
- package/lib/chevre/service/offer/eventServiceByCOA/changeOffers.js +1 -1
- package/lib/chevre/service/offer/onEventChanged.d.ts +2 -0
- package/lib/chevre/service/offer/onEventChanged.js +20 -4
- package/lib/chevre/service/offer.js +1 -1
- package/lib/chevre/service/payment/movieTicket/checkMovieTicket.js +1 -1
- package/lib/chevre/service/payment/movieTicket/payMovieTicket.js +1 -1
- package/lib/chevre/service/payment/movieTicket/validation.js +1 -1
- package/lib/chevre/service/reserve/potentialActions/onReservationCheckedIn.js +1 -1
- package/lib/chevre/service/task/createEvent.js +2 -0
- package/lib/chevre/service/task/importEventsFromCOA.js +2 -0
- package/lib/chevre/service/task/onEventChanged.js +2 -0
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.d.ts +2 -0
- package/lib/chevre/service/task/onResourceUpdated/onResourceDeleted.js +11 -6
- package/lib/chevre/service/task/onResourceUpdated.js +2 -0
- package/lib/chevre/service/transaction/returnOrder/preStart.js +1 -1
- package/package.json +2 -2
- package/example/src/chevre/createManyEvents.ts +0 -75
- package/example/src/chevre/projectEventFields.ts +0 -39
- package/example/src/chevre/searchAvaialbleAppliesToMovieTicketByOfferCatalogId.ts +0 -45
- package/example/src/chevre/searchEventIds.ts +0 -24
- package/example/src/chevre/searchScreeningEventSeries.ts +0 -34
|
@@ -0,0 +1,36 @@
|
|
|
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 eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
|
|
12
|
+
const result = await eventSeriesRepo.aggregateMaxVersion(
|
|
13
|
+
{
|
|
14
|
+
project: {
|
|
15
|
+
id: { $eq: project.id }
|
|
16
|
+
},
|
|
17
|
+
workPerformed: {
|
|
18
|
+
identifier: {
|
|
19
|
+
$eq: '00001'
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
location: {
|
|
23
|
+
branchCode: {
|
|
24
|
+
$in: ['118']
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
// tslint:disable-next-line:no-null-keyword
|
|
30
|
+
console.dir(result, { depth: null });
|
|
31
|
+
console.log(result);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
main()
|
|
35
|
+
.then(console.log)
|
|
36
|
+
.catch(console.error);
|
|
@@ -15,7 +15,7 @@ async function main() {
|
|
|
15
15
|
const events = <Pick<
|
|
16
16
|
chevre.factory.event.IEvent<chevre.factory.eventType.ScreeningEvent>,
|
|
17
17
|
'id' | 'typeOf' | 'startDate' | 'project'
|
|
18
|
-
>[]>await eventRepo.
|
|
18
|
+
>[]>await eventRepo.projectEventFields<chevre.factory.eventType.ScreeningEvent>(
|
|
19
19
|
{
|
|
20
20
|
typeOf: chevre.factory.eventType.ScreeningEvent,
|
|
21
21
|
project: { id: { $eq: PROJECT.id } },
|
|
@@ -14,6 +14,7 @@ async function main() {
|
|
|
14
14
|
const categoryCodeRepo = await chevre.repository.CategoryCode.createInstance(mongoose.connection);
|
|
15
15
|
const creativeWorkRepo = await chevre.repository.CreativeWork.createInstance(mongoose.connection);
|
|
16
16
|
const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
|
|
17
|
+
const eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
|
|
17
18
|
const screeningRoomRepo = await chevre.repository.place.ScreeningRoom.createInstance(mongoose.connection);
|
|
18
19
|
const movieTheaterRepo = await chevre.repository.place.MovieTheater.createInstance(mongoose.connection);
|
|
19
20
|
const sellerRepo = await chevre.repository.Seller.createInstance(mongoose.connection);
|
|
@@ -50,6 +51,7 @@ async function main() {
|
|
|
50
51
|
categoryCode: categoryCodeRepo,
|
|
51
52
|
creativeWork: creativeWorkRepo,
|
|
52
53
|
event: eventRepo,
|
|
54
|
+
eventSeries: eventSeriesRepo,
|
|
53
55
|
movieTheater: movieTheaterRepo,
|
|
54
56
|
screeningRoom: screeningRoomRepo,
|
|
55
57
|
seller: sellerRepo,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
// import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
|
|
5
|
+
import { chevre } from '../../../lib/index';
|
|
6
|
+
|
|
7
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
+
// const EXCLUDED_PROJECT_ID = process.env.EXCLUDED_PROJECT_ID;
|
|
9
|
+
|
|
10
|
+
// tslint:disable-next-line:max-func-body-length
|
|
11
|
+
async function main() {
|
|
12
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
13
|
+
|
|
14
|
+
const additionalPropertyRepo = await chevre.repository.AdditionalProperty.createInstance(mongoose.connection);
|
|
15
|
+
const accountTitleRepo = await chevre.repository.AccountTitle.createInstance(mongoose.connection);
|
|
16
|
+
|
|
17
|
+
const cursor = accountTitleRepo.getCursor(
|
|
18
|
+
{
|
|
19
|
+
// 'project.id': { $eq: project.id },
|
|
20
|
+
// 'project.id': { $ne: EXCLUDED_PROJECT_ID },
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
// paymentMethods: 1,
|
|
24
|
+
// project: 1,
|
|
25
|
+
// orderDate: 1
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
console.log('docs found');
|
|
29
|
+
|
|
30
|
+
const additionalPropertyNames: string[] = [];
|
|
31
|
+
const projectIds: string[] = [];
|
|
32
|
+
const unexpextedprojectIds: string[] = [];
|
|
33
|
+
let checked: number = 0;
|
|
34
|
+
let created: number = 0;
|
|
35
|
+
|
|
36
|
+
let i = 0;
|
|
37
|
+
await cursor.eachAsync(async (doc) => {
|
|
38
|
+
i += 1;
|
|
39
|
+
const accountTitleCategory: chevre.factory.accountTitle.IAccountTitle = doc.toObject();
|
|
40
|
+
const accountTitleSets: Pick<chevre.factory.accountTitle.IAccountTitle, 'additionalProperty' | 'codeValue' | 'typeOf' | 'hasCategoryCode'>[] =
|
|
41
|
+
(Array.isArray(accountTitleCategory.hasCategoryCode))
|
|
42
|
+
? accountTitleCategory.hasCategoryCode
|
|
43
|
+
: [];
|
|
44
|
+
for (const accountTitleSet of accountTitleSets) {
|
|
45
|
+
const accountTitles: Pick<chevre.factory.accountTitle.IAccountTitle, 'additionalProperty' | 'codeValue' | 'typeOf'>[] =
|
|
46
|
+
(Array.isArray(accountTitleSet.hasCategoryCode))
|
|
47
|
+
? accountTitleSet.hasCategoryCode
|
|
48
|
+
: [];
|
|
49
|
+
for (const accountTitle of accountTitles) {
|
|
50
|
+
const additionalPropertyNamesOnResource = (Array.isArray(accountTitle.additionalProperty))
|
|
51
|
+
? accountTitle.additionalProperty?.map((p) => p.name)
|
|
52
|
+
: [];
|
|
53
|
+
if (Array.isArray(additionalPropertyNamesOnResource) && additionalPropertyNamesOnResource.length > 0) {
|
|
54
|
+
console.log(
|
|
55
|
+
additionalPropertyNamesOnResource.join(','),
|
|
56
|
+
additionalPropertyNamesOnResource.length,
|
|
57
|
+
'additionalPropertyNamesOnResource found',
|
|
58
|
+
accountTitleCategory.project.id,
|
|
59
|
+
accountTitle.codeValue
|
|
60
|
+
);
|
|
61
|
+
additionalPropertyNames.push(...additionalPropertyNamesOnResource);
|
|
62
|
+
projectIds.push(accountTitleCategory.project.id);
|
|
63
|
+
additionalPropertyNamesOnResource.forEach((name) => {
|
|
64
|
+
if (!name.match(/^[a-zA-Z]*$/)) {
|
|
65
|
+
// throw new Error(`not matched ${creativeWork.project.id} ${creativeWork.id}`);
|
|
66
|
+
unexpextedprojectIds.push(accountTitleCategory.project.id);
|
|
67
|
+
}
|
|
68
|
+
// tslint:disable-next-line:no-magic-numbers
|
|
69
|
+
if (name.length < 5) {
|
|
70
|
+
// throw new Error(`length matched ${creativeWork.project.id} ${creativeWork.id} ${name}`);
|
|
71
|
+
unexpextedprojectIds.push(accountTitleCategory.project.id);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
for (const additionalPropertyNameOnResource of additionalPropertyNamesOnResource) {
|
|
76
|
+
checked += 1;
|
|
77
|
+
const existingAdditionalProperties = await additionalPropertyRepo.search({
|
|
78
|
+
limit: 1,
|
|
79
|
+
project: { id: { $eq: accountTitleCategory.project.id } },
|
|
80
|
+
codeValue: { $eq: additionalPropertyNameOnResource },
|
|
81
|
+
inCodeSet: { identifier: { $eq: accountTitle.typeOf } }
|
|
82
|
+
});
|
|
83
|
+
if (existingAdditionalProperties.length === 0) {
|
|
84
|
+
const additionalProperty: chevre.factory.additionalProperty.IAdditionalProperty = {
|
|
85
|
+
project: accountTitleCategory.project,
|
|
86
|
+
// id?: string;
|
|
87
|
+
typeOf: 'CategoryCode',
|
|
88
|
+
codeValue: additionalPropertyNameOnResource,
|
|
89
|
+
inCodeSet: {
|
|
90
|
+
typeOf: 'CategoryCodeSet',
|
|
91
|
+
identifier: accountTitle.typeOf
|
|
92
|
+
},
|
|
93
|
+
name: { ja: additionalPropertyNameOnResource }
|
|
94
|
+
};
|
|
95
|
+
await additionalPropertyRepo.save({ attributes: additionalProperty });
|
|
96
|
+
created += 1;
|
|
97
|
+
console.log(
|
|
98
|
+
'additionalProerty created',
|
|
99
|
+
additionalPropertyNameOnResource,
|
|
100
|
+
accountTitleCategory.project.id,
|
|
101
|
+
accountTitle.codeValue
|
|
102
|
+
);
|
|
103
|
+
} else {
|
|
104
|
+
console.log(
|
|
105
|
+
'additionalProerty existed',
|
|
106
|
+
additionalPropertyNameOnResource,
|
|
107
|
+
accountTitleCategory.project.id,
|
|
108
|
+
accountTitle.codeValue
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
console.log(i, 'docs checked');
|
|
117
|
+
console.log('additionalPropertyNames:', [...new Set(additionalPropertyNames)]);
|
|
118
|
+
console.log('projectIds:', [...new Set(projectIds)]);
|
|
119
|
+
console.log('unexpextedprojectIds:', [...new Set(unexpextedprojectIds)]);
|
|
120
|
+
console.log('checked:', checked);
|
|
121
|
+
console.log('created:', created);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
main()
|
|
125
|
+
.then()
|
|
126
|
+
.catch(console.error);
|
|
@@ -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()
|
|
@@ -6,14 +6,27 @@ import { chevre } from '../../../lib/index';
|
|
|
6
6
|
async function main() {
|
|
7
7
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
8
8
|
|
|
9
|
-
const
|
|
9
|
+
const creativeWorkRepo = await chevre.repository.CreativeWork.createInstance(mongoose.connection);
|
|
10
|
+
const offerItemConditionRepo = await chevre.repository.OfferItemCondition.createInstance(mongoose.connection);
|
|
10
11
|
|
|
11
12
|
let updateResult: any;
|
|
12
|
-
updateResult = await
|
|
13
|
+
updateResult = await creativeWorkRepo.unsetUnnecessaryFields({
|
|
13
14
|
filter: {
|
|
14
15
|
_id: { $exists: true }
|
|
15
16
|
},
|
|
16
|
-
$unset: {
|
|
17
|
+
$unset: <any>{
|
|
18
|
+
createdAt: 1,
|
|
19
|
+
updatedAt: 1,
|
|
20
|
+
__v: 1
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
console.log(updateResult);
|
|
24
|
+
|
|
25
|
+
updateResult = await offerItemConditionRepo.unsetUnnecessaryFields({
|
|
26
|
+
filter: {
|
|
27
|
+
_id: { $exists: true }
|
|
28
|
+
},
|
|
29
|
+
$unset: <any>{
|
|
17
30
|
createdAt: 1,
|
|
18
31
|
updatedAt: 1,
|
|
19
32
|
__v: 1
|
|
@@ -10,9 +10,9 @@ const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
|
10
10
|
async function main() {
|
|
11
11
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const eventSeriesRepo = await chevre.repository.EventSeries.createInstance(mongoose.connection);
|
|
14
14
|
|
|
15
|
-
const result = await
|
|
15
|
+
const result = await eventSeriesRepo.upsertByVersion(
|
|
16
16
|
[
|
|
17
17
|
{
|
|
18
18
|
$set: {
|
|
@@ -41,4 +41,8 @@ export declare class AccountTitleRepo {
|
|
|
41
41
|
}, never>, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, factory.accountTitle.IAccountTitle> & Omit<factory.accountTitle.IAccountTitle & {
|
|
42
42
|
_id: import("mongoose").Types.ObjectId;
|
|
43
43
|
}, never>>>;
|
|
44
|
+
unsetUnnecessaryFields(params: {
|
|
45
|
+
filter: any;
|
|
46
|
+
$unset: any;
|
|
47
|
+
}): Promise<import("mongodb").UpdateResult>;
|
|
44
48
|
}
|
|
@@ -32,5 +32,11 @@ class AccountTitleRepo {
|
|
|
32
32
|
.sort({ codeValue: factory.sortType.Descending })
|
|
33
33
|
.cursor();
|
|
34
34
|
}
|
|
35
|
+
unsetUnnecessaryFields(params) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return this.accountTitleModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
38
|
+
.exec();
|
|
39
|
+
});
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
exports.AccountTitleRepo = AccountTitleRepo;
|
|
@@ -202,5 +202,11 @@ class AdditionalPropertyRepo {
|
|
|
202
202
|
.exec();
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
+
unsetUnnecessaryFields(params) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
return this.additionalPropertyModel.updateMany(params.filter, { $unset: params.$unset }, { timestamps: false })
|
|
208
|
+
.exec();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
205
211
|
}
|
|
206
212
|
exports.AdditionalPropertyRepo = AdditionalPropertyRepo;
|
|
@@ -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
|
}
|