@chevre/domain 22.9.0-alpha.83 → 22.9.0-alpha.84
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/aggregation/{aggregateOrderOfSeat.ts → aggregateOrderOfSeatByRoyalCustomers.ts} +17 -4
- package/example/src/chevre/{countPotentiallyExpired.ts → countPotentiallyExportTasks.ts} +2 -2
- package/example/src/chevre/migrateIdentities.ts +82 -0
- package/lib/chevre/repo/aggregateOrder.d.ts +11 -0
- package/lib/chevre/repo/aggregateOrder.js +25 -0
- package/lib/chevre/repo/assetTransaction.d.ts +9 -1
- package/lib/chevre/repo/assetTransaction.js +29 -0
- package/lib/chevre/repo/identityProvider.d.ts +4 -4
- package/lib/chevre/repo/order.d.ts +5 -0
- package/lib/chevre/repo/order.js +6 -9
- package/lib/chevre/repo/potentialAction.d.ts +4 -4
- package/lib/chevre/repo/seller.d.ts +4 -4
- package/lib/chevre/repo/task.d.ts +12 -12
- package/lib/chevre/repo/transaction.d.ts +9 -13
- package/lib/chevre/repo/transaction.js +29 -46
- package/lib/chevre/service/notification.d.ts +1 -12
- package/lib/chevre/service/notification.js +92 -66
- package/lib/chevre/service/task.d.ts +1 -12
- package/lib/chevre/service/task.js +41 -22
- package/package.json +1 -1
- package/example/src/chevre/migratePaymentServiceChannelIds.ts +0 -107
|
@@ -8,17 +8,29 @@ import { chevre } from '../../../../lib/index';
|
|
|
8
8
|
const PROJECT_ID = String(process.env.PROJECT_ID);
|
|
9
9
|
// const SCREEN_CODE = '10';
|
|
10
10
|
// const MOVIE_THEATER_CODE = '118';
|
|
11
|
-
|
|
12
|
-
const SCREEN_CODE = '211';
|
|
11
|
+
const SCREEN_CODE = '130';
|
|
12
|
+
// const SCREEN_CODE = '211';
|
|
13
13
|
const MOVIE_THEATER_CODE = '020';
|
|
14
14
|
const AGGREGATE_PERIOD_IN_MONTHS = 12;
|
|
15
15
|
// tslint:disable-next-line:max-func-body-length
|
|
16
16
|
async function main() {
|
|
17
17
|
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
18
18
|
|
|
19
|
+
const aggregateOrderRepo = await chevre.repository.AggregateOrder.createInstance(mongoose.connection);
|
|
19
20
|
const seatRepo = await chevre.repository.place.Seat.createInstance(mongoose.connection);
|
|
20
21
|
const orderRepo = await chevre.repository.Order.createInstance(mongoose.connection);
|
|
21
22
|
|
|
23
|
+
const royalCustomers = await aggregateOrderRepo.searchRoyalCustomers({
|
|
24
|
+
limit: 300,
|
|
25
|
+
project: { id: PROJECT_ID },
|
|
26
|
+
aggregateOrder: { orderCount: { $gte: 12 } }
|
|
27
|
+
});
|
|
28
|
+
// tslint:disable-next-line:no-null-keyword
|
|
29
|
+
console.dir(royalCustomers, { depth: null });
|
|
30
|
+
console.log(royalCustomers.length, 'royalCustomers found');
|
|
31
|
+
|
|
32
|
+
const customerEmails = royalCustomers.map(({ identifier }) => identifier);
|
|
33
|
+
|
|
22
34
|
const seats = <Pick<chevre.factory.place.seat.IPlace, 'branchCode'>[]>await seatRepo.searchSeats({
|
|
23
35
|
// limit: 50,
|
|
24
36
|
$projection: {
|
|
@@ -76,11 +88,12 @@ async function main() {
|
|
|
76
88
|
},
|
|
77
89
|
reservedTicket: { ticketedSeat: { seatNumber: branchCode } }
|
|
78
90
|
}
|
|
79
|
-
}
|
|
91
|
+
},
|
|
92
|
+
customer: { email: { $in: customerEmails } }
|
|
80
93
|
});
|
|
81
94
|
console.log('aggregateOrder:result', aggregateResult, orderDateGte, orderDateLte, i);
|
|
82
95
|
const diff = process.hrtime(startTime);
|
|
83
|
-
console.log(`
|
|
96
|
+
console.log(`aggregateOrderOfSeat took ${diff[0]} seconds and ${diff[1]} nanoseconds.`);
|
|
84
97
|
|
|
85
98
|
const emailCount = (typeof aggregateResult.aggregation.emailCount === 'number')
|
|
86
99
|
? aggregateResult.aggregation.emailCount
|
|
@@ -13,8 +13,8 @@ async function main() {
|
|
|
13
13
|
const transactionRepo = await chevre.repository.Transaction.createInstance(mongoose.connection);
|
|
14
14
|
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
15
15
|
|
|
16
|
-
let result = await transactionRepo.
|
|
17
|
-
|
|
16
|
+
let result = await transactionRepo.countPotentiallyExportTasks({
|
|
17
|
+
endDate: {
|
|
18
18
|
$lt: moment()
|
|
19
19
|
// tslint:disable-next-line:no-magic-numbers
|
|
20
20
|
.add(-60, 'seconds')
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
+
|
|
9
|
+
// tslint:disable-next-line:max-func-body-length
|
|
10
|
+
async function main() {
|
|
11
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
+
|
|
13
|
+
const identityRepo = await chevre.repository.Identity.createInstance(mongoose.connection);
|
|
14
|
+
const memberRepo = await chevre.repository.Member.createInstance(mongoose.connection);
|
|
15
|
+
|
|
16
|
+
const cursor = memberRepo.getCursor(
|
|
17
|
+
{
|
|
18
|
+
'member.typeOf': {
|
|
19
|
+
$in: [
|
|
20
|
+
chevre.factory.creativeWorkType.WebApplication
|
|
21
|
+
]
|
|
22
|
+
},
|
|
23
|
+
'project.id': { $ne: '*' }
|
|
24
|
+
// _id: { $eq: '5f9a4fed4f3709000abe6415' }
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
_id: 1,
|
|
28
|
+
member: 1,
|
|
29
|
+
project: 1,
|
|
30
|
+
typeOf: 1
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
console.log('docs found');
|
|
34
|
+
|
|
35
|
+
let i = 0;
|
|
36
|
+
let updateCount = 0;
|
|
37
|
+
await cursor.eachAsync(async (doc) => {
|
|
38
|
+
i += 1;
|
|
39
|
+
const iamMember: Pick<
|
|
40
|
+
chevre.factory.iam.IMember,
|
|
41
|
+
'member' | 'project' | 'typeOf'
|
|
42
|
+
> = doc.toObject();
|
|
43
|
+
|
|
44
|
+
// console.log(
|
|
45
|
+
// 'alreadyMigrated?', iamMember.project.id, iamMember.member.id, i);
|
|
46
|
+
let alreadyMigrated = false;
|
|
47
|
+
try {
|
|
48
|
+
const clientId = iamMember.member.id;
|
|
49
|
+
const existingIdentity = (await identityRepo.projectFields(
|
|
50
|
+
{
|
|
51
|
+
limit: 1,
|
|
52
|
+
page: 1,
|
|
53
|
+
project: { id: { $eq: iamMember.project.id } },
|
|
54
|
+
about: { id: { $eq: clientId } }
|
|
55
|
+
},
|
|
56
|
+
['issuedBy']
|
|
57
|
+
)).shift();
|
|
58
|
+
if (existingIdentity !== undefined) {
|
|
59
|
+
alreadyMigrated = true;
|
|
60
|
+
}
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// no op
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (alreadyMigrated) {
|
|
66
|
+
// console.log(
|
|
67
|
+
// 'already migrated.', iamMember.project.id, iamMember.member.id, i);
|
|
68
|
+
} else {
|
|
69
|
+
const roleNames = iamMember.member.hasRole.map(({ roleName }) => roleName);
|
|
70
|
+
updateCount += 1;
|
|
71
|
+
console.log(
|
|
72
|
+
'updated.', iamMember.project.id, iamMember.member.id, roleNames, i);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
console.log(i, 'docs checked');
|
|
77
|
+
console.log(updateCount, 'docs updated');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
main()
|
|
81
|
+
.then()
|
|
82
|
+
.catch(console.error);
|
|
@@ -24,4 +24,15 @@ export declare class AggregateOrderRepo {
|
|
|
24
24
|
save(filter: Pick<IDocType, 'project' | 'identifier' | 'typeOf'>, update: {
|
|
25
25
|
$set: Pick<IDocType, 'aggregateOrder'>;
|
|
26
26
|
}): Promise<void>;
|
|
27
|
+
searchRoyalCustomers(params: {
|
|
28
|
+
limit: number;
|
|
29
|
+
project: {
|
|
30
|
+
id: string;
|
|
31
|
+
};
|
|
32
|
+
aggregateOrder: {
|
|
33
|
+
orderCount: {
|
|
34
|
+
$gte: number;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}): Promise<Pick<IDocType, 'aggregateOrder' | 'identifier'>[]>;
|
|
27
38
|
}
|
|
@@ -144,5 +144,30 @@ class AggregateOrderRepo {
|
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
146
|
}
|
|
147
|
+
searchRoyalCustomers(params) {
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const { limit, project, aggregateOrder } = params;
|
|
150
|
+
const query = this.aggregateOrderModel.find({
|
|
151
|
+
typeOf: { $eq: factory.personType.Person },
|
|
152
|
+
'project.id': { $eq: project.id },
|
|
153
|
+
'aggregateOrder.orderCount': { $exists: true, $gte: aggregateOrder.orderCount.$gte }
|
|
154
|
+
}, {
|
|
155
|
+
_id: 0,
|
|
156
|
+
aggregateOrder: 1,
|
|
157
|
+
identifier: 1
|
|
158
|
+
})
|
|
159
|
+
.sort({ 'aggregateOrder.orderCount': factory.sortType.Descending })
|
|
160
|
+
.limit(limit);
|
|
161
|
+
// if (typeof params.limit === 'number' && params.limit > 0) {
|
|
162
|
+
// const page: number = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
163
|
+
// aggregate.limit(params.limit * page)
|
|
164
|
+
// .skip(params.limit * (page - 1));
|
|
165
|
+
// }
|
|
166
|
+
return query
|
|
167
|
+
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
168
|
+
.lean()
|
|
169
|
+
.exec();
|
|
170
|
+
});
|
|
171
|
+
}
|
|
147
172
|
}
|
|
148
173
|
exports.AggregateOrderRepo = AggregateOrderRepo;
|
|
@@ -75,6 +75,14 @@ export declare class AssetTransactionRepo {
|
|
|
75
75
|
}): Promise<{
|
|
76
76
|
id: string;
|
|
77
77
|
}>;
|
|
78
|
+
countPotentiallyExportTasks(params: {
|
|
79
|
+
endDate: {
|
|
80
|
+
$lt: Date;
|
|
81
|
+
};
|
|
82
|
+
limit?: number;
|
|
83
|
+
}): Promise<{
|
|
84
|
+
count: number;
|
|
85
|
+
}>;
|
|
78
86
|
/**
|
|
79
87
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
80
88
|
*/
|
|
@@ -115,7 +123,7 @@ export declare class AssetTransactionRepo {
|
|
|
115
123
|
$in: factory.transactionStatusType[];
|
|
116
124
|
};
|
|
117
125
|
limit: number;
|
|
118
|
-
}): Promise<Pick<import("@chevre/factory/lib/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/assetTransaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/assetTransaction/registerService").ITransaction | import("@chevre/factory/lib/assetTransaction/reserve").ITransaction, "id" | "
|
|
126
|
+
}): Promise<Pick<import("@chevre/factory/lib/assetTransaction/cancelReservation").ITransaction | import("@chevre/factory/lib/assetTransaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/assetTransaction/pay").ITransaction | import("@chevre/factory/lib/assetTransaction/refund").ITransaction | import("@chevre/factory/lib/assetTransaction/registerService").ITransaction | import("@chevre/factory/lib/assetTransaction/reserve").ITransaction, "id" | "status" | "typeOf">[]>;
|
|
119
127
|
/**
|
|
120
128
|
* set task status exported by transaction id
|
|
121
129
|
* IDでタスクをエクスポート済に変更する
|
|
@@ -453,6 +453,35 @@ class AssetTransactionRepo {
|
|
|
453
453
|
return { id: params.id };
|
|
454
454
|
});
|
|
455
455
|
}
|
|
456
|
+
countPotentiallyExportTasks(params) {
|
|
457
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
458
|
+
const { endDate, limit } = params;
|
|
459
|
+
const endDateLt = endDate === null || endDate === void 0 ? void 0 : endDate.$lt;
|
|
460
|
+
if (!(endDateLt instanceof Date)) {
|
|
461
|
+
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
462
|
+
}
|
|
463
|
+
const query = this.transactionModel.countDocuments({
|
|
464
|
+
status: {
|
|
465
|
+
$in: [
|
|
466
|
+
factory.transactionStatusType.Canceled,
|
|
467
|
+
factory.transactionStatusType.Confirmed,
|
|
468
|
+
factory.transactionStatusType.Expired
|
|
469
|
+
]
|
|
470
|
+
},
|
|
471
|
+
'tasksExportAction.actionStatus': {
|
|
472
|
+
$exists: true,
|
|
473
|
+
$eq: factory.actionStatusType.PotentialActionStatus
|
|
474
|
+
},
|
|
475
|
+
endDate: { $exists: true, $lt: endDateLt }
|
|
476
|
+
});
|
|
477
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
478
|
+
query.limit(limit);
|
|
479
|
+
}
|
|
480
|
+
const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
481
|
+
.exec();
|
|
482
|
+
return { count };
|
|
483
|
+
});
|
|
484
|
+
}
|
|
456
485
|
/**
|
|
457
486
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
458
487
|
*/
|
|
@@ -33,23 +33,23 @@ export declare class IdentityProviderRepo {
|
|
|
33
33
|
};
|
|
34
34
|
}): Promise<void>;
|
|
35
35
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
36
|
+
identifier: string;
|
|
36
37
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
37
38
|
typeOf: factory.organizationType.Organization;
|
|
38
|
-
identifier: string;
|
|
39
39
|
}> & {
|
|
40
|
+
identifier: string;
|
|
40
41
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
41
42
|
typeOf: factory.organizationType.Organization;
|
|
42
|
-
identifier: string;
|
|
43
43
|
} & {
|
|
44
44
|
_id: import("mongoose").Types.ObjectId;
|
|
45
45
|
}, QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
46
|
+
identifier: string;
|
|
46
47
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
47
48
|
typeOf: factory.organizationType.Organization;
|
|
48
|
-
identifier: string;
|
|
49
49
|
}> & {
|
|
50
|
+
identifier: string;
|
|
50
51
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
51
52
|
typeOf: factory.organizationType.Organization;
|
|
52
|
-
identifier: string;
|
|
53
53
|
} & {
|
|
54
54
|
_id: import("mongoose").Types.ObjectId;
|
|
55
55
|
}>>;
|
package/lib/chevre/repo/order.js
CHANGED
|
@@ -1102,20 +1102,17 @@ class OrderRepo {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
aggregateOrderOfSeat(params) {
|
|
1104
1104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1105
|
+
var _a, _b;
|
|
1105
1106
|
const seatNumber = params.acceptedOffers.itemOffered.reservedTicket.ticketedSeat.seatNumber;
|
|
1106
1107
|
const screenCode = params.acceptedOffers.itemOffered.reservationFor.location.branchCode;
|
|
1107
1108
|
const movieTheaterCode = params.acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode;
|
|
1108
|
-
const
|
|
1109
|
-
|
|
1109
|
+
const customerEmailIn = (_b = (_a = params.customer) === null || _a === void 0 ? void 0 : _a.email) === null || _b === void 0 ? void 0 : _b.$in;
|
|
1110
|
+
const matchConditions = Object.assign({ orderDate: {
|
|
1110
1111
|
$gte: params.orderDate.$gte,
|
|
1111
1112
|
$lte: params.orderDate.$lte
|
|
1112
|
-
},
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode': { $exists: true, $eq: movieTheaterCode },
|
|
1116
|
-
'acceptedOffers.itemOffered.reservationFor.location.branchCode': { $exists: true, $eq: screenCode },
|
|
1117
|
-
'acceptedOffers.itemOffered.reservedTicket.ticketedSeat.seatNumber': { $exists: true, $eq: seatNumber }
|
|
1118
|
-
};
|
|
1113
|
+
}, typeOf: { $eq: factory.order.OrderType.Order }, 'project.id': { $eq: params.project.id.$eq }, 'acceptedOffers.itemOffered.reservationFor.superEvent.location.branchCode': { $exists: true, $eq: movieTheaterCode }, 'acceptedOffers.itemOffered.reservationFor.location.branchCode': { $exists: true, $eq: screenCode }, 'acceptedOffers.itemOffered.reservedTicket.ticketedSeat.seatNumber': { $exists: true, $eq: seatNumber } }, (Array.isArray(customerEmailIn))
|
|
1114
|
+
? { 'customer.email': { $exists: true, $in: customerEmailIn } }
|
|
1115
|
+
: undefined);
|
|
1119
1116
|
const aggregations4email = yield this.orderModel.aggregate([
|
|
1120
1117
|
{ $match: matchConditions },
|
|
1121
1118
|
{
|
|
@@ -24,30 +24,30 @@ export declare class PotentialActionRepo {
|
|
|
24
24
|
}>;
|
|
25
25
|
projectFields(conditions: factory.potentialAction.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<factory.potentialAction.IPotentialAction[]>;
|
|
26
26
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
27
|
+
identifier: string;
|
|
27
28
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
28
29
|
typeOf: factory.actionType.InformAction;
|
|
29
30
|
recipient: factory.potentialAction.IInformRecipient;
|
|
30
|
-
identifier: string;
|
|
31
31
|
target: factory.entryPoint.IEntryPoint;
|
|
32
32
|
}> & {
|
|
33
|
+
identifier: string;
|
|
33
34
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
34
35
|
typeOf: factory.actionType.InformAction;
|
|
35
36
|
recipient: factory.potentialAction.IInformRecipient;
|
|
36
|
-
identifier: string;
|
|
37
37
|
target: factory.entryPoint.IEntryPoint;
|
|
38
38
|
} & {
|
|
39
39
|
_id: import("mongoose").Types.ObjectId;
|
|
40
40
|
}, QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
41
|
+
identifier: string;
|
|
41
42
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
42
43
|
typeOf: factory.actionType.InformAction;
|
|
43
44
|
recipient: factory.potentialAction.IInformRecipient;
|
|
44
|
-
identifier: string;
|
|
45
45
|
target: factory.entryPoint.IEntryPoint;
|
|
46
46
|
}> & {
|
|
47
|
+
identifier: string;
|
|
47
48
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
48
49
|
typeOf: factory.actionType.InformAction;
|
|
49
50
|
recipient: factory.potentialAction.IInformRecipient;
|
|
50
|
-
identifier: string;
|
|
51
51
|
target: factory.entryPoint.IEntryPoint;
|
|
52
52
|
} & {
|
|
53
53
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -78,8 +78,8 @@ export declare class SellerRepo {
|
|
|
78
78
|
getCursor(conditions: FilterQuery<factory.seller.ISeller>, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
79
79
|
url?: string | undefined;
|
|
80
80
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
81
|
-
typeOf: factory.organizationType.Corporation;
|
|
82
81
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
82
|
+
typeOf: factory.organizationType.Corporation;
|
|
83
83
|
location?: factory.organization.ILocation | undefined;
|
|
84
84
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
85
85
|
branchCode: string;
|
|
@@ -90,8 +90,8 @@ export declare class SellerRepo {
|
|
|
90
90
|
}> & {
|
|
91
91
|
url?: string | undefined;
|
|
92
92
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
93
|
-
typeOf: factory.organizationType.Corporation;
|
|
94
93
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
94
|
+
typeOf: factory.organizationType.Corporation;
|
|
95
95
|
location?: factory.organization.ILocation | undefined;
|
|
96
96
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
97
97
|
branchCode: string;
|
|
@@ -104,8 +104,8 @@ export declare class SellerRepo {
|
|
|
104
104
|
}, QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
105
105
|
url?: string | undefined;
|
|
106
106
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
107
|
-
typeOf: factory.organizationType.Corporation;
|
|
108
107
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
108
|
+
typeOf: factory.organizationType.Corporation;
|
|
109
109
|
location?: factory.organization.ILocation | undefined;
|
|
110
110
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
111
111
|
branchCode: string;
|
|
@@ -116,8 +116,8 @@ export declare class SellerRepo {
|
|
|
116
116
|
}> & {
|
|
117
117
|
url?: string | undefined;
|
|
118
118
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
119
|
-
typeOf: factory.organizationType.Corporation;
|
|
120
119
|
name: import("@chevre/factory/lib/multilingualString").IMultilingualString;
|
|
120
|
+
typeOf: factory.organizationType.Corporation;
|
|
121
121
|
location?: factory.organization.ILocation | undefined;
|
|
122
122
|
additionalProperty?: import("@chevre/factory/lib/propertyValue").IPropertyValue<string>[] | undefined;
|
|
123
123
|
branchCode: string;
|
|
@@ -225,11 +225,9 @@ export declare class TaskRepo {
|
|
|
225
225
|
count: number;
|
|
226
226
|
}>;
|
|
227
227
|
getCursor(conditions: any, projection: any): import("mongoose").Cursor<import("mongoose").Document<unknown, {}, {
|
|
228
|
+
identifier?: string | undefined;
|
|
228
229
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
229
|
-
expires?: Date | undefined;
|
|
230
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
231
230
|
name: factory.taskName;
|
|
232
|
-
identifier?: string | undefined;
|
|
233
231
|
status: factory.taskStatus;
|
|
234
232
|
runsAt: Date;
|
|
235
233
|
remainingNumberOfTries: number;
|
|
@@ -237,13 +235,13 @@ export declare class TaskRepo {
|
|
|
237
235
|
numberOfTried: number;
|
|
238
236
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
239
237
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
238
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
240
239
|
dateAborted?: Date | undefined;
|
|
240
|
+
expires?: Date | undefined;
|
|
241
241
|
}> & {
|
|
242
|
+
identifier?: string | undefined;
|
|
242
243
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
243
|
-
expires?: Date | undefined;
|
|
244
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
245
244
|
name: factory.taskName;
|
|
246
|
-
identifier?: string | undefined;
|
|
247
245
|
status: factory.taskStatus;
|
|
248
246
|
runsAt: Date;
|
|
249
247
|
remainingNumberOfTries: number;
|
|
@@ -251,15 +249,15 @@ export declare class TaskRepo {
|
|
|
251
249
|
numberOfTried: number;
|
|
252
250
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
253
251
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
252
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
254
253
|
dateAborted?: Date | undefined;
|
|
254
|
+
expires?: Date | undefined;
|
|
255
255
|
} & {
|
|
256
256
|
_id: import("mongoose").Types.ObjectId;
|
|
257
257
|
}, import("mongoose").QueryOptions<import("mongoose").Document<unknown, {}, {
|
|
258
|
+
identifier?: string | undefined;
|
|
258
259
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
259
|
-
expires?: Date | undefined;
|
|
260
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
261
260
|
name: factory.taskName;
|
|
262
|
-
identifier?: string | undefined;
|
|
263
261
|
status: factory.taskStatus;
|
|
264
262
|
runsAt: Date;
|
|
265
263
|
remainingNumberOfTries: number;
|
|
@@ -267,13 +265,13 @@ export declare class TaskRepo {
|
|
|
267
265
|
numberOfTried: number;
|
|
268
266
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
269
267
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
268
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
270
269
|
dateAborted?: Date | undefined;
|
|
270
|
+
expires?: Date | undefined;
|
|
271
271
|
}> & {
|
|
272
|
+
identifier?: string | undefined;
|
|
272
273
|
project: Pick<factory.project.IProject, "id" | "typeOf">;
|
|
273
|
-
expires?: Date | undefined;
|
|
274
|
-
data: import("@chevre/factory/lib/task").IData;
|
|
275
274
|
name: factory.taskName;
|
|
276
|
-
identifier?: string | undefined;
|
|
277
275
|
status: factory.taskStatus;
|
|
278
276
|
runsAt: Date;
|
|
279
277
|
remainingNumberOfTries: number;
|
|
@@ -281,7 +279,9 @@ export declare class TaskRepo {
|
|
|
281
279
|
numberOfTried: number;
|
|
282
280
|
executionResults: import("@chevre/factory/lib/task").IExecutionResult[];
|
|
283
281
|
executor?: import("@chevre/factory/lib/task").IExecutor | undefined;
|
|
282
|
+
data: import("@chevre/factory/lib/task").IData;
|
|
284
283
|
dateAborted?: Date | undefined;
|
|
284
|
+
expires?: Date | undefined;
|
|
285
285
|
} & {
|
|
286
286
|
_id: import("mongoose").Types.ObjectId;
|
|
287
287
|
}>>;
|
|
@@ -107,6 +107,14 @@ export declare class TransactionRepo {
|
|
|
107
107
|
result: factory.transaction.IResult<T>;
|
|
108
108
|
potentialActions: factory.transaction.IPotentialActions<T>;
|
|
109
109
|
}): Promise<void>;
|
|
110
|
+
countPotentiallyExportTasks(params: {
|
|
111
|
+
endDate: {
|
|
112
|
+
$lt: Date;
|
|
113
|
+
};
|
|
114
|
+
limit?: number;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
count: number;
|
|
117
|
+
}>;
|
|
110
118
|
/**
|
|
111
119
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
112
120
|
*/
|
|
@@ -128,18 +136,6 @@ export declare class TransactionRepo {
|
|
|
128
136
|
startDate?: factory.sortType;
|
|
129
137
|
};
|
|
130
138
|
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
|
|
131
|
-
findExportableTransaction(params: {
|
|
132
|
-
status?: {
|
|
133
|
-
$eq?: factory.transactionStatusType;
|
|
134
|
-
};
|
|
135
|
-
endDate: {
|
|
136
|
-
$lt: Date;
|
|
137
|
-
};
|
|
138
|
-
sort?: {
|
|
139
|
-
endDate?: factory.sortType;
|
|
140
|
-
startDate?: factory.sortType;
|
|
141
|
-
};
|
|
142
|
-
}): Promise<Pick<factory.transaction.ITransaction<factory.transactionType>, 'id' | 'typeOf'> | null>;
|
|
143
139
|
/**
|
|
144
140
|
* tasksExportAction.actionStatusがActiveActionStatusのまま一定時間経過した取引について
|
|
145
141
|
* PotentialActionStatusに変更する
|
|
@@ -160,7 +156,7 @@ export declare class TransactionRepo {
|
|
|
160
156
|
$in: factory.transactionStatusType[];
|
|
161
157
|
};
|
|
162
158
|
limit: number;
|
|
163
|
-
}): Promise<Pick<import("@chevre/factory/lib/transaction/placeOrder").ITransaction | import("@chevre/factory/lib/transaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/transaction/returnOrder").ITransaction, "id" | "
|
|
159
|
+
}): Promise<Pick<import("@chevre/factory/lib/transaction/placeOrder").ITransaction | import("@chevre/factory/lib/transaction/moneyTransfer").ITransaction | import("@chevre/factory/lib/transaction/returnOrder").ITransaction, "id" | "status" | "typeOf">[]>;
|
|
164
160
|
/**
|
|
165
161
|
* set task status exported by transaction id
|
|
166
162
|
* IDでタスクをエクスポート済に変更する
|
|
@@ -548,6 +548,35 @@ class TransactionRepo {
|
|
|
548
548
|
});
|
|
549
549
|
});
|
|
550
550
|
}
|
|
551
|
+
countPotentiallyExportTasks(params) {
|
|
552
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
553
|
+
const { endDate, limit } = params;
|
|
554
|
+
const endDateLt = endDate === null || endDate === void 0 ? void 0 : endDate.$lt;
|
|
555
|
+
if (!(endDateLt instanceof Date)) {
|
|
556
|
+
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
557
|
+
}
|
|
558
|
+
const query = this.transactionModel.countDocuments({
|
|
559
|
+
status: {
|
|
560
|
+
$in: [
|
|
561
|
+
factory.transactionStatusType.Canceled,
|
|
562
|
+
factory.transactionStatusType.Confirmed,
|
|
563
|
+
factory.transactionStatusType.Expired
|
|
564
|
+
]
|
|
565
|
+
},
|
|
566
|
+
'tasksExportAction.actionStatus': {
|
|
567
|
+
$exists: true,
|
|
568
|
+
$eq: factory.actionStatusType.PotentialActionStatus
|
|
569
|
+
},
|
|
570
|
+
endDate: { $exists: true, $lt: endDateLt }
|
|
571
|
+
});
|
|
572
|
+
if (typeof limit === 'number' && limit >= 0) {
|
|
573
|
+
query.limit(limit);
|
|
574
|
+
}
|
|
575
|
+
const count = yield query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
576
|
+
.exec();
|
|
577
|
+
return { count };
|
|
578
|
+
});
|
|
579
|
+
}
|
|
551
580
|
/**
|
|
552
581
|
* タスク未エクスポートの取引をひとつ取得してエクスポートを開始する
|
|
553
582
|
*/
|
|
@@ -603,52 +632,6 @@ class TransactionRepo {
|
|
|
603
632
|
.then((doc) => (doc === null) ? null : doc);
|
|
604
633
|
});
|
|
605
634
|
}
|
|
606
|
-
findExportableTransaction(params) {
|
|
607
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
608
|
-
var _a, _b, _c, _d;
|
|
609
|
-
const statusEq = (_a = params.status) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
610
|
-
const endDateLt = (_b = params.endDate) === null || _b === void 0 ? void 0 : _b.$lt;
|
|
611
|
-
if (typeof statusEq === 'string') {
|
|
612
|
-
switch (statusEq) {
|
|
613
|
-
case factory.transactionStatusType.InProgress:
|
|
614
|
-
throw new factory.errors.NotImplemented(`status "${params.status}" not implemented on startExportTasks`);
|
|
615
|
-
default:
|
|
616
|
-
// no op
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
if (!(endDateLt instanceof Date)) {
|
|
620
|
-
throw new factory.errors.Argument('endDate.$lt', 'must be Date');
|
|
621
|
-
}
|
|
622
|
-
const query = this.transactionModel.findOne({
|
|
623
|
-
status: Object.assign({}, (typeof statusEq === 'string')
|
|
624
|
-
? { $eq: statusEq }
|
|
625
|
-
: {
|
|
626
|
-
$in: [
|
|
627
|
-
factory.transactionStatusType.Canceled,
|
|
628
|
-
factory.transactionStatusType.Confirmed,
|
|
629
|
-
factory.transactionStatusType.Expired
|
|
630
|
-
]
|
|
631
|
-
}),
|
|
632
|
-
'tasksExportAction.actionStatus': {
|
|
633
|
-
$exists: true,
|
|
634
|
-
$eq: factory.actionStatusType.PotentialActionStatus
|
|
635
|
-
},
|
|
636
|
-
endDate: { $exists: true, $lt: endDateLt }
|
|
637
|
-
}, {
|
|
638
|
-
_id: 0,
|
|
639
|
-
id: { $toString: '$_id' },
|
|
640
|
-
typeOf: 1
|
|
641
|
-
});
|
|
642
|
-
if (typeof ((_c = params.sort) === null || _c === void 0 ? void 0 : _c.endDate) === 'number' || typeof ((_d = params.sort) === null || _d === void 0 ? void 0 : _d.startDate) === 'number') {
|
|
643
|
-
query.sort(params.sort);
|
|
644
|
-
}
|
|
645
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
646
|
-
.lean() // 2024-08-26~
|
|
647
|
-
.exec()
|
|
648
|
-
// tslint:disable-next-line:no-null-keyword
|
|
649
|
-
.then((doc) => (doc === null) ? null : doc);
|
|
650
|
-
});
|
|
651
|
-
}
|
|
652
635
|
// discontinue(2025-03-10~)
|
|
653
636
|
// public async reexportTasksByExportAction(params: {
|
|
654
637
|
// intervalInMinutes: number;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { LINENotifyCredentials } from '../credentials/lineNotify';
|
|
2
1
|
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
3
2
|
import * as factory from '../factory';
|
|
4
3
|
import type { ActionRepo } from '../repo/action';
|
|
@@ -6,9 +5,6 @@ import type { MessageRepo } from '../repo/message';
|
|
|
6
5
|
import type { PotentialActionRepo } from '../repo/potentialAction';
|
|
7
6
|
import type { ProjectRepo } from '../repo/project';
|
|
8
7
|
import type { SettingRepo } from '../repo/setting';
|
|
9
|
-
type ILineNotifyOperation<T> = (repos: undefined, credentials: {
|
|
10
|
-
lineNotify: LINENotifyCredentials;
|
|
11
|
-
}) => Promise<T>;
|
|
12
8
|
/**
|
|
13
9
|
* Eメールメッセージを送信する
|
|
14
10
|
* https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html
|
|
@@ -34,13 +30,6 @@ declare function notifyByEmail(params: {
|
|
|
34
30
|
result: import("@chevre/factory/lib/action/transfer/send/message/email").IResult;
|
|
35
31
|
}>;
|
|
36
32
|
type LineNotifyLogLevel = 'log' | 'error' | 'info';
|
|
37
|
-
declare function lineNotify({ subject, content, imageThumbnail, imageFullsize, logLevel }: {
|
|
38
|
-
subject: string;
|
|
39
|
-
content: string;
|
|
40
|
-
imageThumbnail?: string;
|
|
41
|
-
imageFullsize?: string;
|
|
42
|
-
logLevel: LineNotifyLogLevel;
|
|
43
|
-
}): ILineNotifyOperation<void>;
|
|
44
33
|
declare function triggerWebhook(params: factory.task.IData<factory.taskName.TriggerWebhook> & {
|
|
45
34
|
project: {
|
|
46
35
|
id: string;
|
|
@@ -50,4 +39,4 @@ declare function triggerWebhook(params: factory.task.IData<factory.taskName.Trig
|
|
|
50
39
|
potentialAction: PotentialActionRepo;
|
|
51
40
|
setting: SettingRepo;
|
|
52
41
|
}) => Promise<void>;
|
|
53
|
-
export {
|
|
42
|
+
export { notifyByEmail, sendEmailMessage, triggerWebhook };
|
|
@@ -9,7 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.lineNotify = lineNotify;
|
|
13
12
|
exports.notifyByEmail = notifyByEmail;
|
|
14
13
|
exports.sendEmailMessage = sendEmailMessage;
|
|
15
14
|
exports.triggerWebhook = triggerWebhook;
|
|
@@ -23,6 +22,12 @@ const http_status_1 = require("http-status");
|
|
|
23
22
|
const util = require("util");
|
|
24
23
|
const factory = require("../factory");
|
|
25
24
|
const factory_1 = require("./notification/factory");
|
|
25
|
+
// type ILineNotifyOperation<T> = (
|
|
26
|
+
// repos: undefined,
|
|
27
|
+
// credentials: {
|
|
28
|
+
// lineNotify: LINENotifyCredentials;
|
|
29
|
+
// }
|
|
30
|
+
// ) => Promise<T>;
|
|
26
31
|
function createSendEmailMessageActionAttributes(params) {
|
|
27
32
|
var _a;
|
|
28
33
|
const { agent, object, project, purpose, recipient, typeOf } = params;
|
|
@@ -223,72 +228,93 @@ function notifyByEmail(params) {
|
|
|
223
228
|
return { result };
|
|
224
229
|
});
|
|
225
230
|
}
|
|
226
|
-
const MAX_LINE_NOTIFY_SUBJECT_LENGTH = 100;
|
|
227
|
-
function lineNotify(
|
|
228
|
-
//
|
|
229
|
-
//
|
|
230
|
-
//
|
|
231
|
+
// const MAX_LINE_NOTIFY_SUBJECT_LENGTH = 100;
|
|
232
|
+
// function lineNotify(
|
|
233
|
+
// { subject, content, imageThumbnail, imageFullsize, logLevel }: {
|
|
234
|
+
// subject: string;
|
|
235
|
+
// content: string;
|
|
236
|
+
// imageThumbnail?: string;
|
|
237
|
+
// imageFullsize?: string;
|
|
238
|
+
// logLevel: LineNotifyLogLevel;
|
|
239
|
+
// }
|
|
240
|
+
// ): ILineNotifyOperation<void> {
|
|
241
|
+
// return async (
|
|
242
|
+
// __: undefined,
|
|
243
|
+
// credentials: {
|
|
244
|
+
// lineNotify: LINENotifyCredentials;
|
|
245
|
+
// }
|
|
246
|
+
// ) => {
|
|
247
|
+
// const timeout = 10000;
|
|
248
|
+
// const LINE_NOTIFY_URL = credentials.lineNotify.url;
|
|
249
|
+
// if (typeof LINE_NOTIFY_URL !== 'string') {
|
|
250
|
+
// throw new factory.errors.Internal('Environment variable LINE_NOTIFY_URL not set');
|
|
251
|
+
// }
|
|
252
|
+
// let accessToken: string | undefined;
|
|
253
|
+
// switch (logLevel) {
|
|
254
|
+
// case 'error':
|
|
255
|
+
// accessToken = credentials.lineNotify.accessTokenAlert;
|
|
256
|
+
// break;
|
|
257
|
+
// case 'info':
|
|
258
|
+
// accessToken = credentials.lineNotify.accessTokenInfo;
|
|
259
|
+
// break;
|
|
260
|
+
// default:
|
|
261
|
+
// accessToken = credentials.lineNotify.accessToken;
|
|
262
|
+
// }
|
|
263
|
+
// if (typeof accessToken !== 'string') {
|
|
264
|
+
// throw new factory.errors.Internal('credentials.lineNotify.accessToken not set');
|
|
265
|
+
// }
|
|
266
|
+
// const shortSubject = (subject.length > MAX_LINE_NOTIFY_SUBJECT_LENGTH)
|
|
267
|
+
// ? `${subject.slice(0, MAX_LINE_NOTIFY_SUBJECT_LENGTH)}...`
|
|
268
|
+
// : subject;
|
|
269
|
+
// const message: string = util.format(
|
|
270
|
+
// '\n%s\n%s\n%s\n%s\n%s\n\n%s',
|
|
271
|
+
// `[${logLevel}] ${shortSubject}`,
|
|
272
|
+
// `now:${(new Date()).toISOString()}`,
|
|
273
|
+
// `pid:${process.pid}`,
|
|
274
|
+
// `GAE_APPLICATION:${process.env.GAE_APPLICATION}`,
|
|
275
|
+
// // `GAE_INSTANCE:${process.env.GAE_INSTANCE}`,
|
|
276
|
+
// `GAE_SERVICE:${process.env.GAE_SERVICE}`,
|
|
277
|
+
// content
|
|
278
|
+
// );
|
|
279
|
+
// try {
|
|
280
|
+
// const form = new FormData();
|
|
281
|
+
// form.set('message', message);
|
|
282
|
+
// if (typeof imageThumbnail === 'string') {
|
|
283
|
+
// form.set('imageThumbnail', imageThumbnail);
|
|
284
|
+
// }
|
|
285
|
+
// if (typeof imageFullsize === 'string') {
|
|
286
|
+
// form.set('imageFullsize', imageFullsize);
|
|
287
|
+
// }
|
|
288
|
+
// const res = await fetch(
|
|
289
|
+
// LINE_NOTIFY_URL,
|
|
290
|
+
// {
|
|
291
|
+
// method: 'POST',
|
|
292
|
+
// headers: {
|
|
293
|
+
// Authorization: `Bearer ${accessToken}`
|
|
294
|
+
// },
|
|
295
|
+
// body: form,
|
|
296
|
+
// ...(typeof timeout === 'number')
|
|
297
|
+
// ? { signal: AbortSignal.timeout(timeout) }
|
|
298
|
+
// : undefined
|
|
299
|
+
// }
|
|
300
|
+
// );
|
|
301
|
+
// let body: any;
|
|
302
|
+
// try {
|
|
303
|
+
// body = await res.json();
|
|
304
|
+
// } catch (error) {
|
|
305
|
+
// // no op
|
|
306
|
+
// }
|
|
307
|
+
// switch (res.status) {
|
|
308
|
+
// case OK:
|
|
309
|
+
// break;
|
|
310
|
+
// default:
|
|
311
|
+
// throw new factory.errors.Internal(`${res.status} ${body?.message}`);
|
|
312
|
+
// }
|
|
313
|
+
// } catch (err) {
|
|
314
|
+
// throw err;
|
|
315
|
+
// }
|
|
316
|
+
// };
|
|
231
317
|
// }
|
|
232
|
-
) {
|
|
233
|
-
return (__, credentials) => __awaiter(this, void 0, void 0, function* () {
|
|
234
|
-
const timeout = 10000;
|
|
235
|
-
const LINE_NOTIFY_URL = credentials.lineNotify.url;
|
|
236
|
-
if (typeof LINE_NOTIFY_URL !== 'string') {
|
|
237
|
-
throw new factory.errors.Internal('Environment variable LINE_NOTIFY_URL not set');
|
|
238
|
-
}
|
|
239
|
-
let accessToken;
|
|
240
|
-
switch (logLevel) {
|
|
241
|
-
case 'error':
|
|
242
|
-
accessToken = credentials.lineNotify.accessTokenAlert;
|
|
243
|
-
break;
|
|
244
|
-
case 'info':
|
|
245
|
-
accessToken = credentials.lineNotify.accessTokenInfo;
|
|
246
|
-
break;
|
|
247
|
-
default:
|
|
248
|
-
accessToken = credentials.lineNotify.accessToken;
|
|
249
|
-
}
|
|
250
|
-
if (typeof accessToken !== 'string') {
|
|
251
|
-
throw new factory.errors.Internal('credentials.lineNotify.accessToken not set');
|
|
252
|
-
}
|
|
253
|
-
const shortSubject = (subject.length > MAX_LINE_NOTIFY_SUBJECT_LENGTH)
|
|
254
|
-
? `${subject.slice(0, MAX_LINE_NOTIFY_SUBJECT_LENGTH)}...`
|
|
255
|
-
: subject;
|
|
256
|
-
const message = util.format('\n%s\n%s\n%s\n%s\n%s\n\n%s', `[${logLevel}] ${shortSubject}`, `now:${(new Date()).toISOString()}`, `pid:${process.pid}`, `GAE_APPLICATION:${process.env.GAE_APPLICATION}`,
|
|
257
|
-
// `GAE_INSTANCE:${process.env.GAE_INSTANCE}`,
|
|
258
|
-
`GAE_SERVICE:${process.env.GAE_SERVICE}`, content);
|
|
259
|
-
try {
|
|
260
|
-
const form = new FormData();
|
|
261
|
-
form.set('message', message);
|
|
262
|
-
if (typeof imageThumbnail === 'string') {
|
|
263
|
-
form.set('imageThumbnail', imageThumbnail);
|
|
264
|
-
}
|
|
265
|
-
if (typeof imageFullsize === 'string') {
|
|
266
|
-
form.set('imageFullsize', imageFullsize);
|
|
267
|
-
}
|
|
268
|
-
const res = yield fetch(LINE_NOTIFY_URL, Object.assign({ method: 'POST', headers: {
|
|
269
|
-
Authorization: `Bearer ${accessToken}`
|
|
270
|
-
}, body: form }, (typeof timeout === 'number')
|
|
271
|
-
? { signal: AbortSignal.timeout(timeout) }
|
|
272
|
-
: undefined));
|
|
273
|
-
let body;
|
|
274
|
-
try {
|
|
275
|
-
body = yield res.json();
|
|
276
|
-
}
|
|
277
|
-
catch (error) {
|
|
278
|
-
// no op
|
|
279
|
-
}
|
|
280
|
-
switch (res.status) {
|
|
281
|
-
case http_status_1.OK:
|
|
282
|
-
break;
|
|
283
|
-
default:
|
|
284
|
-
throw new factory.errors.Internal(`${res.status} ${body === null || body === void 0 ? void 0 : body.message}`);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
catch (err) {
|
|
288
|
-
throw err;
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
318
|
const USERNAME_ARGUMENT_REQUIRED_MESSAGE = 'Missing required key \'Username\' in params';
|
|
293
319
|
function triggerWebhook(params) {
|
|
294
320
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { Connection } from 'mongoose';
|
|
2
2
|
import type { RedisClientType } from 'redis';
|
|
3
|
-
import { LINENotifyCredentials } from '../credentials/lineNotify';
|
|
4
3
|
import { SendGridCredentials } from '../credentials/sendGrid';
|
|
5
4
|
import * as factory from '../factory';
|
|
6
|
-
import type { SettingRepo } from '../repo/setting';
|
|
7
5
|
import type { IExecutableTask, IExecutableTaskKeys, TaskRepo } from '../repo/task';
|
|
8
6
|
import { Settings } from '../settings';
|
|
9
7
|
import { AggregationSettings } from '../settings/aggregation';
|
|
@@ -27,12 +25,6 @@ interface IExecuteOptions {
|
|
|
27
25
|
executeById: boolean;
|
|
28
26
|
executeByName: boolean;
|
|
29
27
|
}
|
|
30
|
-
type TaskOperation<T> = (repos: {
|
|
31
|
-
setting: SettingRepo;
|
|
32
|
-
task: TaskRepo;
|
|
33
|
-
}, settings: Settings, credentials: {
|
|
34
|
-
lineNotify: LINENotifyCredentials;
|
|
35
|
-
}) => Promise<T>;
|
|
36
28
|
type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
|
|
37
29
|
type IOperationExecute<T> = (settings: IExecuteSettings, options: IExecuteOptions) => Promise<T>;
|
|
38
30
|
type ICallResult = void | Pick<factory.task.IExecutionResult, 'error'>;
|
|
@@ -72,9 +64,6 @@ declare function execute(task: IExecutableTask<factory.taskName>): IOperationExe
|
|
|
72
64
|
/**
|
|
73
65
|
* トライ可能回数が0に達したタスクを実行中止する
|
|
74
66
|
*/
|
|
75
|
-
declare function notifyAbortedTasks(params: {
|
|
76
|
-
dateAbortedGte: Date;
|
|
77
|
-
}): TaskOperation<void>;
|
|
78
67
|
/**
|
|
79
68
|
* add(2025-03-13~)
|
|
80
69
|
*/
|
|
@@ -85,4 +74,4 @@ declare function notifyAbortedTasksByEmail(params: {
|
|
|
85
74
|
}, settings: Pick<Settings, "abortedTasksWithoutReport">, credentials: {
|
|
86
75
|
sendGrid: SendGridCredentials;
|
|
87
76
|
}) => Promise<void>;
|
|
88
|
-
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById, executeOneIfExists, execute,
|
|
77
|
+
export { ICallResult, IExecutableTaskKeys, IOperationExecute, executeById, executeOneIfExists, execute, notifyAbortedTasksByEmail };
|
|
@@ -12,7 +12,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.executeById = executeById;
|
|
13
13
|
exports.executeOneIfExists = executeOneIfExists;
|
|
14
14
|
exports.execute = execute;
|
|
15
|
-
exports.notifyAbortedTasks = notifyAbortedTasks;
|
|
16
15
|
exports.notifyAbortedTasksByEmail = notifyAbortedTasksByEmail;
|
|
17
16
|
/**
|
|
18
17
|
* タスクサービス
|
|
@@ -199,27 +198,47 @@ let notification;
|
|
|
199
198
|
// }
|
|
200
199
|
// };
|
|
201
200
|
// }
|
|
202
|
-
function notifyAbortedTasks(params
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
201
|
+
// function notifyAbortedTasks(params: {
|
|
202
|
+
// dateAbortedGte: Date;
|
|
203
|
+
// }): TaskOperation<void> {
|
|
204
|
+
// return async (
|
|
205
|
+
// repos: {
|
|
206
|
+
// setting: SettingRepo;
|
|
207
|
+
// task: TaskRepo;
|
|
208
|
+
// },
|
|
209
|
+
// settings: Pick<Settings, 'abortedTasksWithoutReport'>,
|
|
210
|
+
// credentials: {
|
|
211
|
+
// lineNotify: LINENotifyCredentials;
|
|
212
|
+
// }
|
|
213
|
+
// ) => {
|
|
214
|
+
// const { abortedTasksWithoutReport } = settings;
|
|
215
|
+
// const abortedTasks = await repos.task.projectFields(
|
|
216
|
+
// {
|
|
217
|
+
// statuses: [factory.taskStatus.Aborted],
|
|
218
|
+
// dateAborted: { $gte: params.dateAbortedGte },
|
|
219
|
+
// // 中止を報告しないタスク以外にフィルター
|
|
220
|
+
// ...(abortedTasksWithoutReport.length > 0)
|
|
221
|
+
// ? { name: { $nin: abortedTasksWithoutReport } }
|
|
222
|
+
// : undefined
|
|
223
|
+
// },
|
|
224
|
+
// []
|
|
225
|
+
// );
|
|
226
|
+
// if (abortedTasks.length > 0) {
|
|
227
|
+
// if (notification === undefined) {
|
|
228
|
+
// notification = await import('./notification');
|
|
229
|
+
// }
|
|
230
|
+
// // 開発者へ報告
|
|
231
|
+
// const message = tasks2lineNotify({ tasks: abortedTasks });
|
|
232
|
+
// await notification.lineNotify(
|
|
233
|
+
// {
|
|
234
|
+
// subject: message.subject, content: message.content,
|
|
235
|
+
// logLevel: 'error'
|
|
236
|
+
// }
|
|
237
|
+
// // { timeout, useFetchAPI }
|
|
238
|
+
// )(undefined, credentials);
|
|
239
|
+
// }
|
|
240
|
+
// };
|
|
241
|
+
// }
|
|
223
242
|
/**
|
|
224
243
|
* add(2025-03-13~)
|
|
225
244
|
*/
|
package/package.json
CHANGED
|
@@ -1,107 +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: String(process.env.PROJECT_ID) };
|
|
7
|
-
// const excludedProject = { id: String(process.env.EXCLUDED_PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
// tslint:disable-next-line:max-func-body-length
|
|
10
|
-
async function main() {
|
|
11
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
12
|
-
|
|
13
|
-
const paymentServiceRepo = await chevre.repository.PaymentService.createInstance(mongoose.connection);
|
|
14
|
-
|
|
15
|
-
const cursor = paymentServiceRepo.getCursor(
|
|
16
|
-
{
|
|
17
|
-
typeOf: {
|
|
18
|
-
$in: [
|
|
19
|
-
chevre.factory.service.paymentService.PaymentServiceType.CreditCard,
|
|
20
|
-
chevre.factory.service.paymentService.PaymentServiceType.MovieTicket
|
|
21
|
-
]
|
|
22
|
-
}
|
|
23
|
-
// _id: { $eq: '5f9a4fed4f3709000abe6415' }
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
_id: 1,
|
|
27
|
-
availableChannel: 1,
|
|
28
|
-
productID: 1,
|
|
29
|
-
project: 1,
|
|
30
|
-
typeOf: 1
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
console.log('docs found');
|
|
34
|
-
|
|
35
|
-
let i = 0;
|
|
36
|
-
let updateCount = 0;
|
|
37
|
-
await cursor.eachAsync(async (doc) => {
|
|
38
|
-
i += 1;
|
|
39
|
-
const paymentService: Pick<
|
|
40
|
-
chevre.factory.service.paymentService.IService,
|
|
41
|
-
'availableChannel' | 'id' | 'productID' | 'project' | 'typeOf'
|
|
42
|
-
> = doc.toObject();
|
|
43
|
-
|
|
44
|
-
console.log(
|
|
45
|
-
'alreadyMigrated?', paymentService.project.id, paymentService.productID, i);
|
|
46
|
-
if (typeof paymentService.id !== 'string') {
|
|
47
|
-
throw new Error('id must be string');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let alreadyMigrated = false;
|
|
51
|
-
try {
|
|
52
|
-
const channelId = paymentService.availableChannel?.id;
|
|
53
|
-
if (typeof channelId === 'string' && channelId !== '') {
|
|
54
|
-
if (paymentService.typeOf === chevre.factory.service.paymentService.PaymentServiceType.CreditCard) {
|
|
55
|
-
const existingChannel = await paymentServiceRepo.findAvailableChannelCreditCard({
|
|
56
|
-
project: { id: paymentService.project.id },
|
|
57
|
-
id: paymentService.id
|
|
58
|
-
});
|
|
59
|
-
if (typeof existingChannel.id === 'string'
|
|
60
|
-
&& existingChannel.id === channelId) {
|
|
61
|
-
alreadyMigrated = true;
|
|
62
|
-
}
|
|
63
|
-
} else if (paymentService.typeOf === chevre.factory.service.paymentService.PaymentServiceType.MovieTicket) {
|
|
64
|
-
const existingChannel = await paymentServiceRepo.findAvailableChannelMovieTicket({
|
|
65
|
-
project: { id: paymentService.project.id },
|
|
66
|
-
id: paymentService.id
|
|
67
|
-
});
|
|
68
|
-
if (typeof existingChannel.id === 'string'
|
|
69
|
-
&& existingChannel.id === channelId) {
|
|
70
|
-
alreadyMigrated = true;
|
|
71
|
-
}
|
|
72
|
-
} else {
|
|
73
|
-
throw new Error('invalid paymentServiceType');
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
// no op
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (alreadyMigrated) {
|
|
81
|
-
console.log(
|
|
82
|
-
'already migrated.', paymentService.project.id, paymentService.productID, i);
|
|
83
|
-
} else {
|
|
84
|
-
if (paymentService.typeOf === chevre.factory.service.paymentService.PaymentServiceType.CreditCard
|
|
85
|
-
|| paymentService.typeOf === chevre.factory.service.paymentService.PaymentServiceType.MovieTicket) {
|
|
86
|
-
// await paymentServiceRepo.migrateChannelId({
|
|
87
|
-
// project: { id: paymentService.project.id },
|
|
88
|
-
// id: paymentService.id,
|
|
89
|
-
// typeOf: paymentService.typeOf
|
|
90
|
-
// });
|
|
91
|
-
updateCount += 1;
|
|
92
|
-
console.log(
|
|
93
|
-
'updated.',
|
|
94
|
-
paymentService.project.id, paymentService.productID, i);
|
|
95
|
-
} else {
|
|
96
|
-
throw new Error('invalid paymentServiceType');
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
console.log(i, 'docs checked');
|
|
102
|
-
console.log(updateCount, 'docs updated');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
main()
|
|
106
|
-
.then()
|
|
107
|
-
.catch(console.error);
|