@chevre/domain 22.12.0-alpha.3 → 22.12.0

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.
@@ -0,0 +1,113 @@
1
+ // tslint:disable:no-console no-null-keyword
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 availableAtOrFromId = '51qbjcfr72h62m06vtv5kkhgje';
8
+ const SELLER_ID = '59d20831e53ebc2b4e774466';
9
+ const INVALID_SELLER_ID = '11d20831e53ebc2b4e111111';
10
+
11
+ async function main() {
12
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false, appName: 'sample' });
13
+
14
+ const sellerMakesOfferRepo = await chevre.repository.SellerMakesOffer.createInstance(mongoose.connection);
15
+
16
+ const offers = await sellerMakesOfferRepo.findOffers(
17
+ {
18
+ limit: 20,
19
+ page: 1,
20
+ project: { id: { $eq: project.id } },
21
+ availableAtOrFrom: { id: { $eq: availableAtOrFromId } },
22
+ offeredBy: { id: { $eq: SELLER_ID } }
23
+ }
24
+ );
25
+ console.dir(offers, { depth: null });
26
+ console.log(offers.length, 'offers found');
27
+
28
+ if (offers.length > 0) {
29
+ const sellerId = offers[0].offeredBy.id;
30
+ let deleteResult = await sellerMakesOfferRepo.deleteOffersIfExists({
31
+ project: { id: project.id },
32
+ offers: [
33
+ {
34
+ availableAtOrFrom: { id: availableAtOrFromId },
35
+ offeredBy: { id: sellerId }
36
+ },
37
+ {
38
+ availableAtOrFrom: { id: availableAtOrFromId },
39
+ offeredBy: { id: INVALID_SELLER_ID }
40
+ }
41
+ ]
42
+ });
43
+ console.log('deleted.', deleteResult);
44
+ deleteResult = await sellerMakesOfferRepo.deleteOffersIfExists({
45
+ project: { id: project.id },
46
+ offers: [
47
+ {
48
+ availableAtOrFrom: { id: availableAtOrFromId },
49
+ offeredBy: { id: sellerId }
50
+ },
51
+ {
52
+ availableAtOrFrom: { id: availableAtOrFromId },
53
+ offeredBy: { id: INVALID_SELLER_ID }
54
+ }
55
+ ]
56
+ });
57
+ console.log('deleted.', deleteResult);
58
+ }
59
+
60
+ let createResult = await sellerMakesOfferRepo.createOffersIfNotExists({
61
+ project: { id: project.id },
62
+ offers: [
63
+ {
64
+ availableAtOrFrom: { id: availableAtOrFromId },
65
+ offeredBy: { id: SELLER_ID },
66
+ eligibleTransactionDuration: {
67
+ typeOf: 'QuantitativeValue',
68
+ unitCode: chevre.factory.unitCode.Sec,
69
+ maxValue: 900
70
+ }
71
+ },
72
+ {
73
+ availableAtOrFrom: { id: availableAtOrFromId },
74
+ offeredBy: { id: INVALID_SELLER_ID },
75
+ eligibleTransactionDuration: {
76
+ typeOf: 'QuantitativeValue',
77
+ unitCode: chevre.factory.unitCode.Sec,
78
+ maxValue: 900
79
+ }
80
+ }
81
+ ]
82
+ });
83
+ console.log('created.', createResult);
84
+
85
+ createResult = await sellerMakesOfferRepo.createOffersIfNotExists({
86
+ project: { id: project.id },
87
+ offers: [
88
+ {
89
+ availableAtOrFrom: { id: availableAtOrFromId },
90
+ offeredBy: { id: SELLER_ID },
91
+ eligibleTransactionDuration: {
92
+ typeOf: 'QuantitativeValue',
93
+ unitCode: chevre.factory.unitCode.Sec,
94
+ maxValue: 900
95
+ }
96
+ },
97
+ {
98
+ availableAtOrFrom: { id: availableAtOrFromId },
99
+ offeredBy: { id: INVALID_SELLER_ID },
100
+ eligibleTransactionDuration: {
101
+ typeOf: 'QuantitativeValue',
102
+ unitCode: chevre.factory.unitCode.Sec,
103
+ maxValue: 900
104
+ }
105
+ }
106
+ ]
107
+ });
108
+ console.log('created.', createResult);
109
+ }
110
+
111
+ main()
112
+ .then()
113
+ .catch(console.error);
@@ -9,20 +9,18 @@ import { chevre } from '../../../lib/index';
9
9
  async function main() {
10
10
  await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
11
11
 
12
- const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
12
+ const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
13
13
 
14
14
  let updateResult: any;
15
15
 
16
- updateResult = await settingRepo.unsetUnnecessaryFields({
16
+ updateResult = await eventRepo.unsetUnnecessaryFields({
17
17
  filter: {
18
- 'project.id': { $eq: '*' }
18
+ // 'project.id': { $eq: '*' }
19
+ // 'location.maximumAttendeeCapacity': { $exists: true },
20
+ maximumPhysicalAttendeeCapacity: { $exists: true }
19
21
  },
20
- $unset: {
21
- useMongoAsStockHolder: 1,
22
- useMongoAsStockHolderProjects: 1
23
- // useMongo4confirmationNumberFrom: 1,
24
- // useMongo4orderNumberFrom: 1,
25
- // useMongo4transactionNumberFrom: 1
22
+ $unset: <any>{
23
+ 'location.maximumAttendeeCapacity': 1
26
24
  }
27
25
  });
28
26
  console.log(updateResult);
@@ -0,0 +1,72 @@
1
+ import type { BulkWriteResult } from 'mongodb';
2
+ import { Connection } from 'mongoose';
3
+ import * as factory from '../factory';
4
+ type IMakesOffer = Pick<factory.seller.IMakesOffer, 'typeOf' | 'availableAtOrFrom' | 'eligibleTransactionDuration'>;
5
+ type IMakesOfferAsFindResult = IMakesOffer & {
6
+ offeredBy: {
7
+ id: string;
8
+ name: {
9
+ ja: string;
10
+ };
11
+ };
12
+ };
13
+ /**
14
+ * 販売者提供オファーリポジトリ
15
+ */
16
+ export declare class SellerMakesOfferRepo {
17
+ private readonly sellerModel;
18
+ constructor(connection: Connection);
19
+ findOffers(params: {
20
+ limit?: number;
21
+ page?: number;
22
+ project?: {
23
+ id?: {
24
+ $eq?: string;
25
+ };
26
+ };
27
+ offeredBy?: {
28
+ id?: {
29
+ $eq?: string;
30
+ };
31
+ };
32
+ availableAtOrFrom?: {
33
+ id?: {
34
+ $eq?: string;
35
+ };
36
+ };
37
+ }): Promise<IMakesOfferAsFindResult[]>;
38
+ /**
39
+ * 販売者とアプリケーションに対してオファーが存在しなければ作成する
40
+ */
41
+ createOffersIfNotExists(params: {
42
+ project: {
43
+ id: string;
44
+ };
45
+ offers: {
46
+ availableAtOrFrom: {
47
+ id: string;
48
+ };
49
+ eligibleTransactionDuration: factory.seller.IEligibleTransactionDuration;
50
+ offeredBy: {
51
+ id: string;
52
+ };
53
+ }[];
54
+ }): Promise<BulkWriteResult | void>;
55
+ /**
56
+ * 販売者とアプリケーションに対してオファーが存在すれば削除する
57
+ */
58
+ deleteOffersIfExists(params: {
59
+ project: {
60
+ id: string;
61
+ };
62
+ offers: {
63
+ availableAtOrFrom: {
64
+ id: string;
65
+ };
66
+ offeredBy: {
67
+ id: string;
68
+ };
69
+ }[];
70
+ }): Promise<BulkWriteResult | void>;
71
+ }
72
+ export {};
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SellerMakesOfferRepo = void 0;
13
+ const mongoose_1 = require("mongoose");
14
+ const factory = require("../factory");
15
+ const settings_1 = require("../settings");
16
+ const seller_1 = require("./mongoose/schemas/seller");
17
+ /**
18
+ * 販売者提供オファーリポジトリ
19
+ */
20
+ class SellerMakesOfferRepo {
21
+ constructor(connection) {
22
+ this.sellerModel = connection.model(seller_1.modelName, (0, seller_1.createSchema)());
23
+ }
24
+ findOffers(params) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ var _a, _b, _c, _d, _e, _f;
27
+ const matchStages = [];
28
+ const projectIdEq = (_b = (_a = params.project) === null || _a === void 0 ? void 0 : _a.id) === null || _b === void 0 ? void 0 : _b.$eq;
29
+ if (typeof projectIdEq === 'string') {
30
+ matchStages.push({ $match: { 'project.id': { $eq: projectIdEq } } });
31
+ }
32
+ const offeredByIdEq = (_d = (_c = params.offeredBy) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.$eq;
33
+ if (typeof offeredByIdEq === 'string') {
34
+ matchStages.push({ $match: { _id: { $eq: new mongoose_1.Types.ObjectId(offeredByIdEq) } } });
35
+ }
36
+ const availableAtOrFromIdEq = (_f = (_e = params.availableAtOrFrom) === null || _e === void 0 ? void 0 : _e.id) === null || _f === void 0 ? void 0 : _f.$eq;
37
+ if (typeof availableAtOrFromIdEq === 'string') {
38
+ matchStages.push({ $match: { 'makesOffer.availableAtOrFrom.id': { $exists: true, $eq: availableAtOrFromIdEq } } });
39
+ }
40
+ const aggregate = this.sellerModel.aggregate([
41
+ {
42
+ $unwind: {
43
+ path: '$makesOffer'
44
+ }
45
+ },
46
+ ...matchStages,
47
+ { $sort: { branchCode: factory.sortType.Ascending } },
48
+ {
49
+ $project: {
50
+ _id: 0,
51
+ typeOf: '$makesOffer.typeOf',
52
+ availableAtOrFrom: '$makesOffer.availableAtOrFrom',
53
+ eligibleTransactionDuration: '$makesOffer.eligibleTransactionDuration',
54
+ offeredBy: {
55
+ id: { $toString: '$_id' },
56
+ name: { ja: '$name.ja' }
57
+ }
58
+ }
59
+ }
60
+ ]);
61
+ if (typeof params.limit === 'number' && params.limit > 0) {
62
+ const page = (typeof params.page === 'number' && params.page > 0) ? params.page : 1;
63
+ aggregate.skip(params.limit * (page - 1))
64
+ .limit(params.limit);
65
+ }
66
+ return aggregate.option({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
67
+ .exec();
68
+ });
69
+ }
70
+ /**
71
+ * 販売者とアプリケーションに対してオファーが存在しなければ作成する
72
+ */
73
+ createOffersIfNotExists(params) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const { project, offers } = params;
76
+ const bulkWriteOps = [];
77
+ if (Array.isArray(offers)) {
78
+ offers.forEach((createOfferParams) => {
79
+ const { availableAtOrFrom, eligibleTransactionDuration, offeredBy } = createOfferParams;
80
+ const creatingMakesOffer = {
81
+ typeOf: factory.offerType.Offer,
82
+ availableAtOrFrom: { id: availableAtOrFrom.id },
83
+ eligibleTransactionDuration
84
+ };
85
+ const filter = {
86
+ _id: { $eq: new mongoose_1.Types.ObjectId(offeredBy.id) },
87
+ 'project.id': { $eq: project.id },
88
+ 'makesOffer.availableAtOrFrom.id': { $ne: availableAtOrFrom.id } // 対象アプリケーションが存在しなければ
89
+ };
90
+ const updateFilter = {
91
+ $push: { makesOffer: creatingMakesOffer }
92
+ };
93
+ const updateOne = {
94
+ filter,
95
+ update: updateFilter,
96
+ upsert: false
97
+ };
98
+ bulkWriteOps.push({ updateOne });
99
+ });
100
+ }
101
+ if (bulkWriteOps.length > 0) {
102
+ return this.sellerModel.bulkWrite(bulkWriteOps, { ordered: false });
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * 販売者とアプリケーションに対してオファーが存在すれば削除する
108
+ */
109
+ deleteOffersIfExists(params) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ const { project, offers } = params;
112
+ const bulkWriteOps = [];
113
+ if (Array.isArray(offers)) {
114
+ offers.forEach((deleteOfferParams) => {
115
+ const { availableAtOrFrom, offeredBy } = deleteOfferParams;
116
+ const filter = {
117
+ _id: { $eq: new mongoose_1.Types.ObjectId(offeredBy.id) },
118
+ 'project.id': { $eq: project.id },
119
+ 'makesOffer.availableAtOrFrom.id': { $exists: true, $eq: availableAtOrFrom.id }
120
+ };
121
+ const updateFilter = {
122
+ $pull: { makesOffer: { 'availableAtOrFrom.id': availableAtOrFrom.id } }
123
+ };
124
+ const updateOne = {
125
+ filter,
126
+ update: updateFilter,
127
+ upsert: false
128
+ };
129
+ bulkWriteOps.push({ updateOne });
130
+ });
131
+ }
132
+ if (bulkWriteOps.length > 0) {
133
+ return this.sellerModel.bulkWrite(bulkWriteOps, { ordered: false });
134
+ }
135
+ });
136
+ }
137
+ }
138
+ exports.SellerMakesOfferRepo = SellerMakesOfferRepo;
@@ -66,6 +66,7 @@ import type { ReserveInterfaceRepo } from './repo/reserveInterface';
66
66
  import type { RoleRepo } from './repo/role';
67
67
  import type { ScheduleRepo } from './repo/schedule';
68
68
  import type { SellerRepo } from './repo/seller';
69
+ import type { SellerMakesOfferRepo } from './repo/sellerMakesOffer';
69
70
  import type { SellerPaymentAcceptedRepo } from './repo/sellerPaymentAccepted';
70
71
  import type { SellerReturnPolicyRepo } from './repo/sellerReturnPolicy';
71
72
  import type { ServiceAvailableHourRepo } from './repo/service/availableHour';
@@ -383,6 +384,10 @@ export type Seller = SellerRepo;
383
384
  export declare namespace Seller {
384
385
  function createInstance(...params: ConstructorParameters<typeof SellerRepo>): Promise<SellerRepo>;
385
386
  }
387
+ export type SellerMakesOffer = SellerMakesOfferRepo;
388
+ export declare namespace SellerMakesOffer {
389
+ function createInstance(...params: ConstructorParameters<typeof SellerMakesOfferRepo>): Promise<SellerMakesOfferRepo>;
390
+ }
386
391
  export type SellerPaymentAccepted = SellerPaymentAcceptedRepo;
387
392
  export declare namespace SellerPaymentAccepted {
388
393
  function createInstance(...params: ConstructorParameters<typeof SellerPaymentAcceptedRepo>): Promise<SellerPaymentAcceptedRepo>;
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.Permit = exports.Person = exports.paymentMethod = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.Note = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Comment = exports.Authorization = exports.CategoryCode = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AdvanceBookingRequirement = exports.AdditionalProperty = exports.Action = exports.AccountTransaction = exports.AccountTitle = exports.AccountingReport = exports.Account = exports.AcceptedOffer = void 0;
13
- exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = void 0;
13
+ exports.WebSite = exports.rateLimit = exports.Trip = exports.TransactionProcess = exports.TransactionNumber = exports.Transaction = exports.Ticket = exports.Telemetry = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceOutputIdentifier = exports.ServiceOutput = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductOffer = exports.ProductModel = exports.Product = exports.PriceSpecification = exports.PotentialAction = exports.place = void 0;
14
14
  var AcceptedOffer;
15
15
  (function (AcceptedOffer) {
16
16
  let repo;
@@ -919,6 +919,19 @@ var Seller;
919
919
  }
920
920
  Seller.createInstance = createInstance;
921
921
  })(Seller || (exports.Seller = Seller = {}));
922
+ var SellerMakesOffer;
923
+ (function (SellerMakesOffer) {
924
+ let repo;
925
+ function createInstance(...params) {
926
+ return __awaiter(this, void 0, void 0, function* () {
927
+ if (repo === undefined) {
928
+ repo = (yield Promise.resolve().then(() => require('./repo/sellerMakesOffer'))).SellerMakesOfferRepo;
929
+ }
930
+ return new repo(...params);
931
+ });
932
+ }
933
+ SellerMakesOffer.createInstance = createInstance;
934
+ })(SellerMakesOffer || (exports.SellerMakesOffer = SellerMakesOffer = {}));
922
935
  var SellerPaymentAccepted;
923
936
  (function (SellerPaymentAccepted) {
924
937
  let repo;
package/package.json CHANGED
@@ -11,8 +11,8 @@
11
11
  "dependencies": {
12
12
  "@aws-sdk/client-cognito-identity-provider": "3.600.0",
13
13
  "@aws-sdk/credential-providers": "3.600.0",
14
- "@chevre/factory": "4.397.0-alpha.0",
15
- "@cinerino/sdk": "12.0.0-alpha.1",
14
+ "@chevre/factory": "4.397.0",
15
+ "@cinerino/sdk": "12.2.0",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.4.0-alpha.1",
18
18
  "@sendgrid/client": "8.1.4",
@@ -115,5 +115,5 @@
115
115
  "postversion": "git push origin --tags",
116
116
  "prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
117
117
  },
118
- "version": "22.12.0-alpha.3"
118
+ "version": "22.12.0"
119
119
  }