@chevre/domain 22.10.0-alpha.8 → 22.10.0-alpha.9
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/findOneAvailableHours.ts +39 -0
- package/lib/chevre/repo/mongoose/schemas/service/availableHour.d.ts +18 -0
- package/lib/chevre/repo/mongoose/schemas/service/availableHour.js +65 -0
- package/lib/chevre/repo/service/availableHour.d.ts +15 -0
- package/lib/chevre/repo/service/availableHour.js +53 -0
- package/lib/chevre/repository.d.ts +5 -0
- package/lib/chevre/repository.js +14 -1
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// tslint:disable:no-console
|
|
2
|
+
import * as moment from 'moment';
|
|
3
|
+
import * as mongoose from 'mongoose';
|
|
4
|
+
import { chevre } from '../../../lib/index';
|
|
5
|
+
|
|
6
|
+
async function main() {
|
|
7
|
+
await mongoose.connect(String(process.env.MONGOLAB_URI), { autoIndex: false });
|
|
8
|
+
|
|
9
|
+
const availableHourRepo = await chevre.repository.ServiceAvailableHour.createInstance(mongoose.connection);
|
|
10
|
+
|
|
11
|
+
const setting = await availableHourRepo.findValidOne(
|
|
12
|
+
{
|
|
13
|
+
// now: new Date(),
|
|
14
|
+
now: moment('2025-05-15T00:00:00Z')
|
|
15
|
+
.toDate()
|
|
16
|
+
},
|
|
17
|
+
['opens', 'typeOf']
|
|
18
|
+
);
|
|
19
|
+
console.log('setting:', setting);
|
|
20
|
+
// const result = await availableHourRepo.saveOne(
|
|
21
|
+
// {
|
|
22
|
+
// // opens: '09:00:00',
|
|
23
|
+
// validFrom: moment('2025-05-15T00:00:00Z')
|
|
24
|
+
// .toDate(),
|
|
25
|
+
// validThrough: moment('2025-05-15T01:00:00Z')
|
|
26
|
+
// .toDate(),
|
|
27
|
+
// typeOf: 'OpeningHoursSpecification'
|
|
28
|
+
// }
|
|
29
|
+
// );
|
|
30
|
+
// console.log('saved', result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
main()
|
|
34
|
+
.then(() => {
|
|
35
|
+
console.log('success!');
|
|
36
|
+
})
|
|
37
|
+
.catch((err) => {
|
|
38
|
+
console.error(err);
|
|
39
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
|
|
2
|
+
/**
|
|
3
|
+
* The place is open if the opens property is specified, and closed otherwise.
|
|
4
|
+
*/
|
|
5
|
+
interface IOpeningHoursSpecification {
|
|
6
|
+
typeOf: 'OpeningHoursSpecification';
|
|
7
|
+
opens?: string;
|
|
8
|
+
validFrom: Date;
|
|
9
|
+
validThrough: Date;
|
|
10
|
+
}
|
|
11
|
+
type IDocType = IOpeningHoursSpecification;
|
|
12
|
+
type IModel = Model<IDocType>;
|
|
13
|
+
type ISchemaDefinition = SchemaDefinition<IDocType>;
|
|
14
|
+
type ISchema = Schema<IDocType, IModel, {}, {}, {}, {}, ISchemaDefinition, IDocType>;
|
|
15
|
+
declare const modelName = "Service.AvailableHour";
|
|
16
|
+
declare const indexes: [d: IndexDefinition, o: IndexOptions][];
|
|
17
|
+
declare function createSchema(): ISchema;
|
|
18
|
+
export { createSchema, IDocType, IModel, indexes, modelName };
|
|
@@ -0,0 +1,65 @@
|
|
|
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 = 'Service.AvailableHour';
|
|
9
|
+
exports.modelName = modelName;
|
|
10
|
+
const schemaDefinition = {
|
|
11
|
+
typeOf: { type: String, required: true },
|
|
12
|
+
opens: { type: String, required: false },
|
|
13
|
+
validFrom: { type: Date, required: true },
|
|
14
|
+
validThrough: { type: Date, required: true }
|
|
15
|
+
};
|
|
16
|
+
const schemaOptions = {
|
|
17
|
+
autoIndex: settings_1.MONGO_AUTO_INDEX,
|
|
18
|
+
autoCreate: false,
|
|
19
|
+
collection: 'service.availableHours',
|
|
20
|
+
id: true,
|
|
21
|
+
read: settings_1.MONGO_READ_PREFERENCE,
|
|
22
|
+
writeConcern: writeConcern_1.writeConcern,
|
|
23
|
+
strict: true,
|
|
24
|
+
strictQuery: false,
|
|
25
|
+
timestamps: false,
|
|
26
|
+
versionKey: false,
|
|
27
|
+
toJSON: {
|
|
28
|
+
getters: false,
|
|
29
|
+
virtuals: false,
|
|
30
|
+
minimize: false,
|
|
31
|
+
versionKey: false
|
|
32
|
+
},
|
|
33
|
+
toObject: {
|
|
34
|
+
getters: false,
|
|
35
|
+
virtuals: true,
|
|
36
|
+
minimize: false,
|
|
37
|
+
versionKey: false
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const indexes = [
|
|
41
|
+
[
|
|
42
|
+
{ validFrom: 1 },
|
|
43
|
+
{ name: 'validFrom' }
|
|
44
|
+
],
|
|
45
|
+
[
|
|
46
|
+
{ validThrough: 1, validFrom: 1 },
|
|
47
|
+
{ name: 'validThrough' }
|
|
48
|
+
]
|
|
49
|
+
];
|
|
50
|
+
exports.indexes = indexes;
|
|
51
|
+
/**
|
|
52
|
+
* サービス利用可能時間スキーマ
|
|
53
|
+
*/
|
|
54
|
+
let schema;
|
|
55
|
+
function createSchema() {
|
|
56
|
+
if (schema === undefined) {
|
|
57
|
+
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
|
|
58
|
+
if (settings_1.MONGO_AUTO_INDEX) {
|
|
59
|
+
indexes.forEach((indexParams) => {
|
|
60
|
+
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return schema;
|
|
65
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Connection } from 'mongoose';
|
|
2
|
+
import { IDocType } from '../mongoose/schemas/service/availableHour';
|
|
3
|
+
type IKeyOfProjection = keyof IDocType;
|
|
4
|
+
/**
|
|
5
|
+
* サービス利用可能時間リポジトリ
|
|
6
|
+
*/
|
|
7
|
+
export declare class ServiceAvailableHourRepo {
|
|
8
|
+
private readonly availableHoursModel;
|
|
9
|
+
constructor(connection: Connection);
|
|
10
|
+
saveOne(params: IDocType): Promise<void>;
|
|
11
|
+
findValidOne(filter: {
|
|
12
|
+
now: Date;
|
|
13
|
+
}, inclusion: IKeyOfProjection[]): Promise<IDocType | undefined>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
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.ServiceAvailableHourRepo = void 0;
|
|
13
|
+
const availableHour_1 = require("../mongoose/schemas/service/availableHour");
|
|
14
|
+
/**
|
|
15
|
+
* サービス利用可能時間リポジトリ
|
|
16
|
+
*/
|
|
17
|
+
class ServiceAvailableHourRepo {
|
|
18
|
+
constructor(connection) {
|
|
19
|
+
this.availableHoursModel = connection.model(availableHour_1.modelName, (0, availableHour_1.createSchema)());
|
|
20
|
+
}
|
|
21
|
+
saveOne(params) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
yield this.availableHoursModel.create(params);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
findValidOne(filter, inclusion) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const andQuery = [];
|
|
29
|
+
const now = filter.now;
|
|
30
|
+
andQuery.push({ validFrom: { $lte: now } }, { validThrough: { $gte: now } });
|
|
31
|
+
const filterQuery = Object.assign({}, (andQuery.length > 0) ? { $and: andQuery } : undefined);
|
|
32
|
+
// eslint-disable-next-line no-magic-numbers
|
|
33
|
+
const projection = {
|
|
34
|
+
// const projection: { [key: string]: AnyExpression } = {
|
|
35
|
+
_id: 0
|
|
36
|
+
// id: { $toString: '$_id' },
|
|
37
|
+
};
|
|
38
|
+
if (Array.isArray(inclusion)) {
|
|
39
|
+
inclusion.forEach((field) => {
|
|
40
|
+
projection[field] = 1;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
const doc = yield this.availableHoursModel.findOne(filterQuery, projection, { sort: { validFrom: 1 } })
|
|
44
|
+
.lean()
|
|
45
|
+
.exec();
|
|
46
|
+
if (doc !== null) {
|
|
47
|
+
return doc;
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.ServiceAvailableHourRepo = ServiceAvailableHourRepo;
|
|
@@ -68,6 +68,7 @@ import type { ScheduleRepo } from './repo/schedule';
|
|
|
68
68
|
import type { SellerRepo } from './repo/seller';
|
|
69
69
|
import type { SellerPaymentAcceptedRepo } from './repo/sellerPaymentAccepted';
|
|
70
70
|
import type { SellerReturnPolicyRepo } from './repo/sellerReturnPolicy';
|
|
71
|
+
import type { ServiceAvailableHourRepo } from './repo/service/availableHour';
|
|
71
72
|
import type { ServiceOutputRepo } from './repo/serviceOutput';
|
|
72
73
|
import type { ServiceOutputIdentifierRepo } from './repo/serviceOutputIdentifier';
|
|
73
74
|
import type { SettingRepo } from './repo/setting';
|
|
@@ -390,6 +391,10 @@ export type SellerReturnPolicy = SellerReturnPolicyRepo;
|
|
|
390
391
|
export declare namespace SellerReturnPolicy {
|
|
391
392
|
function createInstance(...params: ConstructorParameters<typeof SellerReturnPolicyRepo>): Promise<SellerReturnPolicyRepo>;
|
|
392
393
|
}
|
|
394
|
+
export type ServiceAvailableHour = ServiceAvailableHourRepo;
|
|
395
|
+
export declare namespace ServiceAvailableHour {
|
|
396
|
+
function createInstance(...params: ConstructorParameters<typeof ServiceAvailableHourRepo>): Promise<ServiceAvailableHourRepo>;
|
|
397
|
+
}
|
|
393
398
|
export type ServiceOutput = ServiceOutputRepo;
|
|
394
399
|
export declare namespace ServiceOutput {
|
|
395
400
|
function createInstance(...params: ConstructorParameters<typeof ServiceOutputRepo>): Promise<ServiceOutputRepo>;
|
package/lib/chevre/repository.js
CHANGED
|
@@ -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.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.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;
|
|
@@ -945,6 +945,19 @@ var SellerReturnPolicy;
|
|
|
945
945
|
}
|
|
946
946
|
SellerReturnPolicy.createInstance = createInstance;
|
|
947
947
|
})(SellerReturnPolicy || (exports.SellerReturnPolicy = SellerReturnPolicy = {}));
|
|
948
|
+
var ServiceAvailableHour;
|
|
949
|
+
(function (ServiceAvailableHour) {
|
|
950
|
+
let repo;
|
|
951
|
+
function createInstance(...params) {
|
|
952
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
953
|
+
if (repo === undefined) {
|
|
954
|
+
repo = (yield Promise.resolve().then(() => require('./repo/service/availableHour'))).ServiceAvailableHourRepo;
|
|
955
|
+
}
|
|
956
|
+
return new repo(...params);
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
ServiceAvailableHour.createInstance = createInstance;
|
|
960
|
+
})(ServiceAvailableHour || (exports.ServiceAvailableHour = ServiceAvailableHour = {}));
|
|
948
961
|
var ServiceOutput;
|
|
949
962
|
(function (ServiceOutput) {
|
|
950
963
|
let repo;
|
package/package.json
CHANGED