@chevre/domain
Version:
Chevre Domain Library for Node.js
66 lines (65 loc) • 1.81 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.modelName = exports.indexes = void 0;
exports.createSchema = createSchema;
const mongoose_1 = require("mongoose");
const settings_1 = require("../../../../settings");
const writeConcern_1 = require("../../writeConcern");
const modelName = 'Service.AvailableHour';
exports.modelName = modelName;
const schemaDefinition = {
typeOf: { type: String, required: true },
opens: { type: String, required: false },
validFrom: { type: Date, required: true },
validThrough: { type: Date, required: true }
};
const schemaOptions = {
autoIndex: settings_1.MONGO_AUTO_INDEX,
autoCreate: false,
collection: 'service.availableHours',
id: true,
read: settings_1.MONGO_READ_PREFERENCE,
writeConcern: writeConcern_1.writeConcern,
strict: true,
strictQuery: false,
timestamps: false,
versionKey: false,
toJSON: {
getters: false,
virtuals: false,
minimize: false,
versionKey: false
},
toObject: {
getters: false,
virtuals: true,
minimize: false,
versionKey: false
}
};
const indexes = [
[
{ validFrom: 1 },
{ name: 'validFrom' }
],
[
{ validThrough: 1, validFrom: 1 },
{ name: 'validThrough' }
]
];
exports.indexes = indexes;
/**
* サービス利用可能時間スキーマ
*/
let schema;
function createSchema() {
if (schema === undefined) {
schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
if (settings_1.MONGO_AUTO_INDEX) {
indexes.forEach((indexParams) => {
schema === null || schema === void 0 ? void 0 : schema.index(...indexParams);
});
}
}
return schema;
}
;