@chevre/domain 24.0.0-alpha.81 → 24.0.0-alpha.83
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/lib/chevre/repo/mongoose/schemas/setting.d.ts +0 -1
- package/lib/chevre/repository.d.ts +0 -10
- package/lib/chevre/repository.js +2 -24
- package/lib/chevre/service/assetTransaction/reserve/start.d.ts +0 -2
- package/lib/chevre/service/assetTransaction/reserve/start.js +0 -1
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.d.ts +0 -3
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest.js +1 -11
- package/lib/chevre/service/notification/triggerWebhook.js +43 -48
- package/lib/chevre/service/offer/event/authorize/processStartReserve4chevre.d.ts +0 -2
- package/lib/chevre/service/offer/event/authorize.d.ts +0 -2
- package/lib/chevre/service/offer/event/issueEventOfferTicket.d.ts +1 -3
- package/lib/chevre/service/offer/event/issueEventOfferTicket.js +11 -13
- package/lib/chevre/service/payment/creditCard/authorize/handleAuthorizeError.js +2 -7
- package/lib/chevre/service/payment/creditCard/gmoError.d.ts +1 -31
- package/lib/chevre/service/payment/creditCard/refundCreditCard.js +2 -2
- package/lib/chevre/service/payment/creditCard/searchGMOTrade.js +1 -1
- package/lib/chevre/service/payment/creditCard/voidTransaction.js +1 -1
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.d.ts +0 -2
- package/lib/chevre/service/task/onResourceDeleted/deleteResourcesBySeller.js +0 -6
- package/lib/chevre/service/task/onResourceDeleted.js +0 -2
- package/lib/chevre/service/task/onResourceUpdated.js +0 -2
- package/package.json +3 -3
- package/lib/chevre/repo/comment.d.ts +0 -42
- package/lib/chevre/repo/comment.js +0 -121
- package/lib/chevre/repo/mongoose/schemas/comments.d.ts +0 -11
- package/lib/chevre/repo/mongoose/schemas/comments.js +0 -103
- package/lib/chevre/repo/mongoose/schemas/productOffer.d.ts +0 -14
- package/lib/chevre/repo/mongoose/schemas/productOffer.js +0 -108
- package/lib/chevre/repo/productOffer.d.ts +0 -52
- package/lib/chevre/repo/productOffer.js +0 -209
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.d.ts +0 -16
- package/lib/chevre/service/assetTransaction/reserve/validateStartRequest/validateMemberTierIfExists.js +0 -129
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommentRepo = void 0;
|
|
4
|
-
const comments_1 = require("./mongoose/schemas/comments");
|
|
5
|
-
const factory_1 = require("../factory");
|
|
6
|
-
const settings_1 = require("../settings");
|
|
7
|
-
/**
|
|
8
|
-
* コメントリポジトリ
|
|
9
|
-
*/
|
|
10
|
-
class CommentRepo {
|
|
11
|
-
commentModel;
|
|
12
|
-
constructor(connection) {
|
|
13
|
-
this.commentModel = connection.model(comments_1.modelName, (0, comments_1.createSchema)());
|
|
14
|
-
}
|
|
15
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
16
|
-
const andConditions = [];
|
|
17
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
18
|
-
if (typeof projectIdEq === 'string') {
|
|
19
|
-
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
20
|
-
}
|
|
21
|
-
const aboutIdEq = params.about?.id?.$eq;
|
|
22
|
-
if (typeof aboutIdEq === 'string') {
|
|
23
|
-
andConditions.push({ 'about.id': { $exists: true, $eq: aboutIdEq } });
|
|
24
|
-
}
|
|
25
|
-
const aboutIdIn = params.about?.id?.$in;
|
|
26
|
-
if (Array.isArray(aboutIdIn)) {
|
|
27
|
-
andConditions.push({ 'about.id': { $exists: true, $in: aboutIdIn } });
|
|
28
|
-
}
|
|
29
|
-
return andConditions;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 検索
|
|
33
|
-
*/
|
|
34
|
-
async search(params) {
|
|
35
|
-
let projection = {};
|
|
36
|
-
if (Array.isArray(params.inclusion) && params.inclusion.length > 0) {
|
|
37
|
-
params.inclusion.forEach((field) => {
|
|
38
|
-
projection[field] = 1;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
projection = {
|
|
43
|
-
__v: 0,
|
|
44
|
-
createdAt: 0,
|
|
45
|
-
updatedAt: 0
|
|
46
|
-
};
|
|
47
|
-
if (Array.isArray(params.exclusion) && params.exclusion.length > 0) {
|
|
48
|
-
params.exclusion.forEach((field) => {
|
|
49
|
-
projection[field] = 0;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
const conditions = CommentRepo.CREATE_MONGO_CONDITIONS(params);
|
|
54
|
-
const query = this.commentModel.find((conditions.length > 0) ? { $and: conditions } : {})
|
|
55
|
-
.select(projection);
|
|
56
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
57
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
58
|
-
query.limit(params.limit)
|
|
59
|
-
.skip(params.limit * (page - 1));
|
|
60
|
-
}
|
|
61
|
-
/* istanbul ignore else */
|
|
62
|
-
if (params.sort?.dateCreated !== undefined) {
|
|
63
|
-
query.sort({ dateCreated: params.sort.dateCreated });
|
|
64
|
-
}
|
|
65
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
66
|
-
.exec()
|
|
67
|
-
.then((docs) => docs.map((doc) => doc.toObject()));
|
|
68
|
-
}
|
|
69
|
-
async findById(params) {
|
|
70
|
-
const doc = await this.commentModel.findOne({ _id: params.id }, {
|
|
71
|
-
__v: 0,
|
|
72
|
-
createdAt: 0,
|
|
73
|
-
updatedAt: 0
|
|
74
|
-
})
|
|
75
|
-
.exec();
|
|
76
|
-
if (doc === null) {
|
|
77
|
-
throw new factory_1.factory.errors.NotFound(this.commentModel.modelName);
|
|
78
|
-
}
|
|
79
|
-
return doc.toObject();
|
|
80
|
-
}
|
|
81
|
-
async create(params) {
|
|
82
|
-
const creatingDoc = {
|
|
83
|
-
about: params.about,
|
|
84
|
-
author: params.author,
|
|
85
|
-
dateCreated: new Date(),
|
|
86
|
-
project: params.project,
|
|
87
|
-
text: params.text,
|
|
88
|
-
typeOf: factory_1.factory.creativeWorkType.Comment,
|
|
89
|
-
...(Array.isArray(params.additionalProperty)) ? { additionalProperty: params.additionalProperty } : undefined,
|
|
90
|
-
...(Array.isArray(params.mentions)) ? { mentions: params.mentions } : undefined
|
|
91
|
-
};
|
|
92
|
-
const doc = await this.commentModel.create(creatingDoc);
|
|
93
|
-
return doc.toObject();
|
|
94
|
-
}
|
|
95
|
-
async updateById(params) {
|
|
96
|
-
const updateFields = {
|
|
97
|
-
$set: {
|
|
98
|
-
dateModified: new Date(),
|
|
99
|
-
...(typeof params.attributes.text === 'string') ? { text: params.attributes.text } : undefined
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const doc = await this.commentModel.findOneAndUpdate({ _id: params.id }, updateFields, { upsert: false, new: true })
|
|
103
|
-
.exec();
|
|
104
|
-
if (doc === null) {
|
|
105
|
-
throw new factory_1.factory.errors.NotFound(this.commentModel.modelName);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 削除する
|
|
110
|
-
*/
|
|
111
|
-
async deleteById(params) {
|
|
112
|
-
await this.commentModel.findOneAndDelete({ _id: { $eq: params.id } }, { projection: { _id: 1 } })
|
|
113
|
-
.exec();
|
|
114
|
-
}
|
|
115
|
-
getCursor(conditions, projection) {
|
|
116
|
-
return this.commentModel.find(conditions, projection)
|
|
117
|
-
.sort({ codeValue: factory_1.factory.sortType.Ascending })
|
|
118
|
-
.cursor();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
exports.CommentRepo = CommentRepo;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
-
import { IVirtuals } from '../virtuals';
|
|
3
|
-
import { factory } from '../../../factory';
|
|
4
|
-
type IDocType = factory.creativeWork.comment.IComment;
|
|
5
|
-
type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
|
|
6
|
-
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
7
|
-
type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
|
|
8
|
-
declare const modelName = "Comment";
|
|
9
|
-
declare function createSchema(): ISchema;
|
|
10
|
-
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
11
|
-
export { createSchema, IDocType, IModel, indexes, modelName };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.modelName = exports.indexes = void 0;
|
|
4
|
-
exports.createSchema = createSchema;
|
|
5
|
-
const mongoose_1 = require("mongoose");
|
|
6
|
-
const writeConcern_1 = require("../writeConcern");
|
|
7
|
-
const settings_1 = require("../../../settings");
|
|
8
|
-
const modelName = 'Comment';
|
|
9
|
-
exports.modelName = modelName;
|
|
10
|
-
const schemaDefinition = {
|
|
11
|
-
project: mongoose_1.SchemaTypes.Mixed,
|
|
12
|
-
typeOf: {
|
|
13
|
-
type: String,
|
|
14
|
-
required: true
|
|
15
|
-
},
|
|
16
|
-
about: mongoose_1.SchemaTypes.Mixed,
|
|
17
|
-
additionalProperty: [mongoose_1.SchemaTypes.Mixed],
|
|
18
|
-
author: mongoose_1.SchemaTypes.Mixed,
|
|
19
|
-
// commnet: Comment[]
|
|
20
|
-
commentCount: { type: Number, default: 0 },
|
|
21
|
-
dateCreated: Date,
|
|
22
|
-
dateModified: Date,
|
|
23
|
-
mentions: [mongoose_1.SchemaTypes.Mixed],
|
|
24
|
-
text: {
|
|
25
|
-
type: String,
|
|
26
|
-
required: true
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const schemaOptions = {
|
|
30
|
-
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
31
|
-
autoCreate: false,
|
|
32
|
-
collection: 'comments',
|
|
33
|
-
id: true,
|
|
34
|
-
read: 'primary',
|
|
35
|
-
writeConcern: writeConcern_1.writeConcern,
|
|
36
|
-
strict: true,
|
|
37
|
-
strictQuery: false,
|
|
38
|
-
timestamps: false, // 2024-08-07~
|
|
39
|
-
versionKey: false, // 2024-08-07~
|
|
40
|
-
toJSON: {
|
|
41
|
-
getters: false,
|
|
42
|
-
virtuals: false,
|
|
43
|
-
minimize: false,
|
|
44
|
-
versionKey: false
|
|
45
|
-
},
|
|
46
|
-
toObject: {
|
|
47
|
-
getters: false,
|
|
48
|
-
virtuals: true,
|
|
49
|
-
minimize: false,
|
|
50
|
-
versionKey: false
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* コメントスキーマ
|
|
55
|
-
*/
|
|
56
|
-
let schema;
|
|
57
|
-
function createSchema() {
|
|
58
|
-
if (schema === undefined) {
|
|
59
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
60
|
-
}
|
|
61
|
-
return schema;
|
|
62
|
-
}
|
|
63
|
-
const indexes = [
|
|
64
|
-
// [ // discontinue(2024-08-07~)
|
|
65
|
-
// { createdAt: 1 },
|
|
66
|
-
// { name: 'searchByCreatedAt' }
|
|
67
|
-
// ],
|
|
68
|
-
// [
|
|
69
|
-
// { updatedAt: 1 },
|
|
70
|
-
// { name: 'searchByUpdatedAt' }
|
|
71
|
-
// ],
|
|
72
|
-
[
|
|
73
|
-
{ dateCreated: 1 },
|
|
74
|
-
{
|
|
75
|
-
name: 'searchByDateCreated'
|
|
76
|
-
}
|
|
77
|
-
],
|
|
78
|
-
[
|
|
79
|
-
{ 'project.id': 1, dateCreated: 1 },
|
|
80
|
-
{
|
|
81
|
-
name: 'searchByProjectId'
|
|
82
|
-
}
|
|
83
|
-
],
|
|
84
|
-
[
|
|
85
|
-
{ 'about.id': 1, dateCreated: 1 },
|
|
86
|
-
{
|
|
87
|
-
name: 'searchByAboutId',
|
|
88
|
-
partialFilterExpression: {
|
|
89
|
-
'about.id': { $exists: true }
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
],
|
|
93
|
-
[
|
|
94
|
-
{ additionalProperty: 1, dateCreated: 1 },
|
|
95
|
-
{
|
|
96
|
-
name: 'searchByAdditionalProperty',
|
|
97
|
-
partialFilterExpression: {
|
|
98
|
-
additionalProperty: { $exists: true }
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
];
|
|
103
|
-
exports.indexes = indexes;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
-
import { factory } from '../../../factory';
|
|
3
|
-
import { IVirtuals } from '../virtuals';
|
|
4
|
-
type IDocType = Omit<factory.productOffer.IProductOffer, 'acceptedPaymentMethod' | 'validForMemberTier'> & {
|
|
5
|
-
acceptedPaymentMethod?: factory.productOffer.IAcceptedPaymentMethod;
|
|
6
|
-
validForMemberTier?: factory.productOffer.IValidForMemberTier;
|
|
7
|
-
};
|
|
8
|
-
type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
|
|
9
|
-
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
10
|
-
type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
|
|
11
|
-
declare const modelName = "ProductOffer";
|
|
12
|
-
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
13
|
-
declare function createSchema(): ISchema;
|
|
14
|
-
export { createSchema, IDocType, IModel, indexes, modelName };
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.modelName = exports.indexes = void 0;
|
|
4
|
-
exports.createSchema = createSchema;
|
|
5
|
-
const mongoose_1 = require("mongoose");
|
|
6
|
-
const settings_1 = require("../../../settings");
|
|
7
|
-
const writeConcern_1 = require("../writeConcern");
|
|
8
|
-
const modelName = 'ProductOffer';
|
|
9
|
-
exports.modelName = modelName;
|
|
10
|
-
const schemaDefinition = {
|
|
11
|
-
project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
12
|
-
typeOf: { type: String, required: true },
|
|
13
|
-
identifier: { type: String, required: true },
|
|
14
|
-
itemOffered: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
15
|
-
offeredBy: { type: mongoose_1.SchemaTypes.Mixed, required: true },
|
|
16
|
-
availability: { type: String, required: true },
|
|
17
|
-
validFrom: { type: Date, required: true },
|
|
18
|
-
validThrough: { type: Date, required: true },
|
|
19
|
-
// availableAtOrFrom: { type: SchemaTypes.Mixed, required: false },
|
|
20
|
-
validForMemberTier: { type: mongoose_1.SchemaTypes.Mixed, required: false },
|
|
21
|
-
acceptedPaymentMethod: { type: mongoose_1.SchemaTypes.Mixed, required: false }
|
|
22
|
-
};
|
|
23
|
-
const schemaOptions = {
|
|
24
|
-
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
25
|
-
autoCreate: false,
|
|
26
|
-
collection: 'productOffers',
|
|
27
|
-
id: true,
|
|
28
|
-
read: settings_1.MONGO_READ_PREFERENCE,
|
|
29
|
-
writeConcern: writeConcern_1.writeConcern,
|
|
30
|
-
strict: true,
|
|
31
|
-
strictQuery: false,
|
|
32
|
-
timestamps: false,
|
|
33
|
-
versionKey: false,
|
|
34
|
-
toJSON: {
|
|
35
|
-
getters: false,
|
|
36
|
-
virtuals: false,
|
|
37
|
-
minimize: false,
|
|
38
|
-
versionKey: false
|
|
39
|
-
},
|
|
40
|
-
toObject: {
|
|
41
|
-
getters: false,
|
|
42
|
-
virtuals: true,
|
|
43
|
-
minimize: false,
|
|
44
|
-
versionKey: false
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
const indexes = [
|
|
48
|
-
[
|
|
49
|
-
{ validFrom: 1 },
|
|
50
|
-
{ name: 'validFrom' }
|
|
51
|
-
],
|
|
52
|
-
[
|
|
53
|
-
{
|
|
54
|
-
'project.id': 1,
|
|
55
|
-
'itemOffered.identifier': 1,
|
|
56
|
-
identifier: 1
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: 'uniqueByItemOfferedAndIdentifier',
|
|
60
|
-
unique: true
|
|
61
|
-
}
|
|
62
|
-
],
|
|
63
|
-
[
|
|
64
|
-
{ 'project.id': 1, validFrom: 1 },
|
|
65
|
-
{ name: 'projectId' }
|
|
66
|
-
],
|
|
67
|
-
[
|
|
68
|
-
{ identifier: 1, validFrom: 1 },
|
|
69
|
-
{ name: 'identifier' }
|
|
70
|
-
],
|
|
71
|
-
[
|
|
72
|
-
{ 'itemOffered.identifier': 1, validFrom: 1 },
|
|
73
|
-
{ name: 'itemOfferedIdentifier' }
|
|
74
|
-
],
|
|
75
|
-
[
|
|
76
|
-
{ 'offeredBy.id': 1, validFrom: 1 },
|
|
77
|
-
{ name: 'offeredById' }
|
|
78
|
-
],
|
|
79
|
-
[
|
|
80
|
-
{ validThrough: 1, validFrom: 1 },
|
|
81
|
-
{ name: 'validThrough' }
|
|
82
|
-
],
|
|
83
|
-
[
|
|
84
|
-
{ 'validForMemberTier.identifier': 1, validFrom: 1 },
|
|
85
|
-
{
|
|
86
|
-
name: 'validForMemberTierIdentifier',
|
|
87
|
-
partialFilterExpression: {
|
|
88
|
-
'validForMemberTier.identifier': { $exists: true }
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
];
|
|
93
|
-
exports.indexes = indexes;
|
|
94
|
-
/**
|
|
95
|
-
* プロダクトオファー(汎用的なオファー設定)スキーマ
|
|
96
|
-
*/
|
|
97
|
-
let schema;
|
|
98
|
-
function createSchema() {
|
|
99
|
-
if (schema === undefined) {
|
|
100
|
-
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
101
|
-
if (settings_1.MONGO_AUTO_INDEX) {
|
|
102
|
-
indexes.forEach((indexParams) => {
|
|
103
|
-
schema?.index(...indexParams);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return schema;
|
|
108
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { BulkWriteResult, DeleteResult } from 'mongodb';
|
|
2
|
-
import { Connection, FilterQuery } from 'mongoose';
|
|
3
|
-
import { factory } from '../factory';
|
|
4
|
-
import { IDocType } from './mongoose/schemas/productOffer';
|
|
5
|
-
type IUnset = {
|
|
6
|
-
[key in keyof IDocType]?: 1;
|
|
7
|
-
};
|
|
8
|
-
type IDocWithId = factory.productOffer.IProductOffer & {
|
|
9
|
-
id: string;
|
|
10
|
-
};
|
|
11
|
-
type IKeyOfProjection = keyof IDocType;
|
|
12
|
-
/**
|
|
13
|
-
* プロダクトオファーリポジトリ
|
|
14
|
-
*/
|
|
15
|
-
export declare class ProductOfferRepo {
|
|
16
|
-
private readonly productOfferModel;
|
|
17
|
-
constructor(connection: Connection);
|
|
18
|
-
static CREATE_MONGO_CONDITIONS(params: factory.productOffer.ISearchConditions): FilterQuery<IDocType>[];
|
|
19
|
-
findProductOffers(params: factory.productOffer.ISearchConditions, inclusion: IKeyOfProjection[]): Promise<IDocWithId[]>;
|
|
20
|
-
/**
|
|
21
|
-
* オファーコードとオファーコレクションコードをキーにして冪等置換
|
|
22
|
-
*/
|
|
23
|
-
upsertOffersByIdentifier(params: {
|
|
24
|
-
$set: Pick<IDocType, 'acceptedPaymentMethod' | 'availability' | 'identifier' | 'itemOffered' | 'offeredBy' | 'project' | 'typeOf' | 'validForMemberTier' | 'validFrom' | 'validThrough'> & {
|
|
25
|
-
id?: never;
|
|
26
|
-
};
|
|
27
|
-
$unset: IUnset;
|
|
28
|
-
}[], options: {
|
|
29
|
-
/**
|
|
30
|
-
* falseの場合setOnInsertのみ
|
|
31
|
-
* trueの場合setのみ
|
|
32
|
-
*/
|
|
33
|
-
update: boolean;
|
|
34
|
-
}): Promise<{
|
|
35
|
-
bulkWriteResult?: BulkWriteResult;
|
|
36
|
-
modifiedProductOffers?: {
|
|
37
|
-
id: string;
|
|
38
|
-
}[];
|
|
39
|
-
}>;
|
|
40
|
-
/**
|
|
41
|
-
* 販売者の提供するプロダクトオファーを削除する
|
|
42
|
-
*/
|
|
43
|
-
deleteProductOffersBySeller(params: {
|
|
44
|
-
project: {
|
|
45
|
-
id: string;
|
|
46
|
-
};
|
|
47
|
-
offeredBy: {
|
|
48
|
-
id: string;
|
|
49
|
-
};
|
|
50
|
-
}): Promise<DeleteResult>;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProductOfferRepo = void 0;
|
|
4
|
-
const factory_1 = require("../factory");
|
|
5
|
-
const settings_1 = require("../settings");
|
|
6
|
-
const productOffer_1 = require("./mongoose/schemas/productOffer");
|
|
7
|
-
const AVAILABLE_PROJECT_FIELDS = [
|
|
8
|
-
'identifier',
|
|
9
|
-
'project',
|
|
10
|
-
'itemOffered',
|
|
11
|
-
'offeredBy',
|
|
12
|
-
'typeOf',
|
|
13
|
-
'validFrom',
|
|
14
|
-
'validThrough',
|
|
15
|
-
'availability',
|
|
16
|
-
'acceptedPaymentMethod',
|
|
17
|
-
'validForMemberTier'
|
|
18
|
-
];
|
|
19
|
-
/**
|
|
20
|
-
* プロダクトオファーリポジトリ
|
|
21
|
-
*/
|
|
22
|
-
class ProductOfferRepo {
|
|
23
|
-
productOfferModel;
|
|
24
|
-
constructor(connection) {
|
|
25
|
-
this.productOfferModel = connection.model(productOffer_1.modelName, (0, productOffer_1.createSchema)());
|
|
26
|
-
}
|
|
27
|
-
static CREATE_MONGO_CONDITIONS(params) {
|
|
28
|
-
const andConditions = [];
|
|
29
|
-
const idEq = params.id?.$eq;
|
|
30
|
-
if (typeof idEq === 'string') {
|
|
31
|
-
andConditions.push({ _id: { $eq: idEq } });
|
|
32
|
-
}
|
|
33
|
-
const projectIdEq = params.project?.id?.$eq;
|
|
34
|
-
if (typeof projectIdEq === 'string') {
|
|
35
|
-
andConditions.push({ 'project.id': { $eq: projectIdEq } });
|
|
36
|
-
}
|
|
37
|
-
const identifierEq = params.identifier?.$eq;
|
|
38
|
-
if (typeof identifierEq === 'string') {
|
|
39
|
-
andConditions.push({ identifier: { $eq: identifierEq } });
|
|
40
|
-
}
|
|
41
|
-
const identifierIn = params.identifier?.$in;
|
|
42
|
-
if (Array.isArray(identifierIn)) {
|
|
43
|
-
andConditions.push({ identifier: { $in: identifierIn } });
|
|
44
|
-
}
|
|
45
|
-
const itemOfferedIdentifierEq = params.itemOffered?.identifier?.$eq;
|
|
46
|
-
if (typeof itemOfferedIdentifierEq === 'string') {
|
|
47
|
-
andConditions.push({ 'itemOffered.identifier': { $eq: itemOfferedIdentifierEq } });
|
|
48
|
-
}
|
|
49
|
-
const itemOfferedIdentifierIn = params.itemOffered?.identifier?.$in;
|
|
50
|
-
if (Array.isArray(itemOfferedIdentifierIn)) {
|
|
51
|
-
andConditions.push({ 'itemOffered.identifier': { $in: itemOfferedIdentifierIn } });
|
|
52
|
-
}
|
|
53
|
-
const offeredByIdEq = params.offeredBy?.id?.$eq;
|
|
54
|
-
if (typeof offeredByIdEq === 'string') {
|
|
55
|
-
andConditions.push({ 'offeredBy.id': { $eq: offeredByIdEq } });
|
|
56
|
-
}
|
|
57
|
-
const sellerByIdEq = params.seller?.id?.$eq;
|
|
58
|
-
if (typeof sellerByIdEq === 'string') {
|
|
59
|
-
andConditions.push({ 'offeredBy.id': { $eq: sellerByIdEq } });
|
|
60
|
-
}
|
|
61
|
-
const validForMemberTierIdentifierEq = params.validForMemberTier?.identifier?.$eq;
|
|
62
|
-
if (typeof validForMemberTierIdentifierEq === 'string') {
|
|
63
|
-
andConditions.push({ 'validForMemberTier.identifier': { $exists: true, $eq: validForMemberTierIdentifierEq } });
|
|
64
|
-
}
|
|
65
|
-
const validFromLte = params.validFrom?.$lte;
|
|
66
|
-
if (validFromLte instanceof Date) {
|
|
67
|
-
andConditions.push({ validFrom: { $lte: validFromLte } });
|
|
68
|
-
}
|
|
69
|
-
const validThroughGte = params.validThrough?.$gte;
|
|
70
|
-
if (validThroughGte instanceof Date) {
|
|
71
|
-
andConditions.push({ validThrough: { $gte: validThroughGte } });
|
|
72
|
-
}
|
|
73
|
-
return andConditions;
|
|
74
|
-
}
|
|
75
|
-
async findProductOffers(params, inclusion) {
|
|
76
|
-
const conditions = ProductOfferRepo.CREATE_MONGO_CONDITIONS(params);
|
|
77
|
-
let positiveProjectionFields;
|
|
78
|
-
if (Array.isArray(inclusion) && inclusion.length > 0) {
|
|
79
|
-
positiveProjectionFields = inclusion.filter((key) => AVAILABLE_PROJECT_FIELDS.includes(key));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
throw new factory_1.factory.errors.ArgumentNull('inclusion', 'inclusion must be specified');
|
|
83
|
-
}
|
|
84
|
-
const projection = {
|
|
85
|
-
_id: 0,
|
|
86
|
-
id: { $toString: '$_id' },
|
|
87
|
-
...Object.fromEntries(positiveProjectionFields.map((key) => ([key, 1])))
|
|
88
|
-
};
|
|
89
|
-
const query = this.productOfferModel.find((conditions.length > 0) ? { $and: conditions } : {}, projection);
|
|
90
|
-
if (typeof params.sort?.validFrom === 'number') {
|
|
91
|
-
query.sort({ validFrom: params.sort.validFrom });
|
|
92
|
-
}
|
|
93
|
-
if (typeof params.limit === 'number' && params.limit > 0) {
|
|
94
|
-
const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
|
|
95
|
-
query.limit(params.limit)
|
|
96
|
-
.skip(params.limit * (page - 1));
|
|
97
|
-
}
|
|
98
|
-
return query.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
99
|
-
.lean()
|
|
100
|
-
.exec();
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* オファーコードとオファーコレクションコードをキーにして冪等置換
|
|
104
|
-
*/
|
|
105
|
-
async upsertOffersByIdentifier(params, options) {
|
|
106
|
-
const { update } = options;
|
|
107
|
-
const bulkWriteOps = [];
|
|
108
|
-
const queryFilters = [];
|
|
109
|
-
if (Array.isArray(params)) {
|
|
110
|
-
params.forEach(({ $set, $unset }) => {
|
|
111
|
-
const { availability, identifier, itemOffered, offeredBy, project, validFrom, validThrough, acceptedPaymentMethod, validForMemberTier } = $set;
|
|
112
|
-
if (typeof identifier !== 'string' || identifier === '') {
|
|
113
|
-
throw new factory_1.factory.errors.ArgumentNull('identifier');
|
|
114
|
-
}
|
|
115
|
-
if (typeof itemOffered.identifier !== 'string' || itemOffered.identifier === '') {
|
|
116
|
-
throw new factory_1.factory.errors.ArgumentNull('itemOffered.identifier');
|
|
117
|
-
}
|
|
118
|
-
// リソースのユニークネスを保証するfilter
|
|
119
|
-
const filter = {
|
|
120
|
-
'project.id': { $eq: project.id },
|
|
121
|
-
'itemOffered.identifier': { $eq: itemOffered.identifier },
|
|
122
|
-
identifier: { $eq: identifier }
|
|
123
|
-
};
|
|
124
|
-
queryFilters.push({
|
|
125
|
-
'project.id': { $eq: project.id },
|
|
126
|
-
'itemOffered.identifier': { $eq: itemOffered.identifier },
|
|
127
|
-
identifier: { $eq: identifier }
|
|
128
|
-
});
|
|
129
|
-
if (update === true) {
|
|
130
|
-
const setFields = {
|
|
131
|
-
availability,
|
|
132
|
-
validFrom,
|
|
133
|
-
validThrough,
|
|
134
|
-
...(typeof acceptedPaymentMethod?.typeOf === 'string') ? { acceptedPaymentMethod } : undefined,
|
|
135
|
-
...(typeof validForMemberTier?.typeOf === 'string') ? { validForMemberTier } : undefined
|
|
136
|
-
};
|
|
137
|
-
const updateFilter = {
|
|
138
|
-
$set: setFields,
|
|
139
|
-
...($unset !== undefined) ? { $unset } : undefined
|
|
140
|
-
};
|
|
141
|
-
const updateOne = {
|
|
142
|
-
filter,
|
|
143
|
-
update: updateFilter,
|
|
144
|
-
upsert: false
|
|
145
|
-
};
|
|
146
|
-
bulkWriteOps.push({ updateOne });
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
const setOnInsert = {
|
|
150
|
-
itemOffered, offeredBy, identifier, project,
|
|
151
|
-
typeOf: factory_1.factory.offerType.Offer,
|
|
152
|
-
availability,
|
|
153
|
-
validFrom,
|
|
154
|
-
validThrough,
|
|
155
|
-
...(typeof acceptedPaymentMethod?.typeOf === 'string') ? { acceptedPaymentMethod } : undefined,
|
|
156
|
-
...(typeof validForMemberTier?.typeOf === 'string') ? { validForMemberTier } : undefined
|
|
157
|
-
};
|
|
158
|
-
const updateFilter = {
|
|
159
|
-
$setOnInsert: setOnInsert
|
|
160
|
-
};
|
|
161
|
-
const updateOne = {
|
|
162
|
-
filter,
|
|
163
|
-
update: updateFilter,
|
|
164
|
-
upsert: true
|
|
165
|
-
};
|
|
166
|
-
bulkWriteOps.push({ updateOne });
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
if (bulkWriteOps.length > 0) {
|
|
171
|
-
const bulkWriteResult = await this.productOfferModel.bulkWrite(bulkWriteOps, { ordered: false });
|
|
172
|
-
// modifiedの場合upsertedIdsに含まれないので、idを検索する
|
|
173
|
-
const modifiedProductOffers = await this.productOfferModel.find({ $or: queryFilters }, {
|
|
174
|
-
_id: 0,
|
|
175
|
-
id: { $toString: '$_id' }
|
|
176
|
-
})
|
|
177
|
-
.lean()
|
|
178
|
-
.exec();
|
|
179
|
-
return { bulkWriteResult, modifiedProductOffers };
|
|
180
|
-
}
|
|
181
|
-
return {};
|
|
182
|
-
}
|
|
183
|
-
// public async deleteProductOffersByIds(params: {
|
|
184
|
-
// project: { id: string };
|
|
185
|
-
// ids: string[];
|
|
186
|
-
// }): Promise<DeleteResult | void> {
|
|
187
|
-
// const { project, ids } = params;
|
|
188
|
-
// if (Array.isArray(ids) && ids.length > 0) {
|
|
189
|
-
// return this.productOfferModel.deleteMany(
|
|
190
|
-
// {
|
|
191
|
-
// 'project.id': { $eq: project.id },
|
|
192
|
-
// _id: { $in: ids }
|
|
193
|
-
// }
|
|
194
|
-
// )
|
|
195
|
-
// .exec();
|
|
196
|
-
// }
|
|
197
|
-
// }
|
|
198
|
-
/**
|
|
199
|
-
* 販売者の提供するプロダクトオファーを削除する
|
|
200
|
-
*/
|
|
201
|
-
async deleteProductOffersBySeller(params) {
|
|
202
|
-
return this.productOfferModel.deleteMany({
|
|
203
|
-
'project.id': { $eq: params.project.id },
|
|
204
|
-
'offeredBy.id': { $eq: params.offeredBy.id }
|
|
205
|
-
})
|
|
206
|
-
.exec();
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
exports.ProductOfferRepo = ProductOfferRepo;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { factory } from '../../../../factory';
|
|
2
|
-
import { IMinimizedIndividualEvent } from '../../../../factory/event';
|
|
3
|
-
import type { IssuerRepo } from '../../../../repo/issuer';
|
|
4
|
-
import type { MemberProgramRepo } from '../../../../repo/memberProgram';
|
|
5
|
-
import type { ProductOfferRepo } from '../../../../repo/productOffer';
|
|
6
|
-
declare function validateMemberTierIfExists(params: {
|
|
7
|
-
event: Pick<IMinimizedIndividualEvent, 'offers' | 'id' | 'project'>;
|
|
8
|
-
now: Date;
|
|
9
|
-
makesOfferOnApplication: factory.event.screeningEvent.ISellerMakesOffer;
|
|
10
|
-
acceptedEventOffer?: factory.authorization.IOfferAsObject;
|
|
11
|
-
}): (repos: {
|
|
12
|
-
issuer: IssuerRepo;
|
|
13
|
-
memberProgram: MemberProgramRepo;
|
|
14
|
-
productOffer: ProductOfferRepo;
|
|
15
|
-
}) => Promise<void>;
|
|
16
|
-
export { validateMemberTierIfExists };
|