@chevre/domain
Version:
Chevre Domain Library for Node.js
88 lines (87 loc) • 2.12 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.modelName = exports.indexes = void 0;
exports.createSchema = createSchema;
const mongoose_1 = require("mongoose");
const writeConcern_1 = require("../writeConcern");
const settings_1 = require("../../../settings");
const modelName = 'ActionRecipe';
exports.modelName = modelName;
const schemaDefinition = {
project: {
type: mongoose_1.SchemaTypes.Mixed,
required: true
},
typeOf: {
type: String,
required: true
},
recipeCategory: {
type: String,
required: true
},
step: [mongoose_1.SchemaTypes.Mixed],
recipeFor: {
type: mongoose_1.SchemaTypes.Mixed,
required: true
},
dateCreated: {
type: Date,
required: true
},
dateModified: Date
};
const schemaOptions = {
autoIndex: settings_1.MONGO_AUTO_INDEX,
autoCreate: false,
collection: 'actionRecipes',
id: true,
read: 'primary',
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 = [
[
{ dateCreated: -1 },
{ name: 'searchByDateCreated' }
],
[
{ 'project.id': 1, dateCreated: -1 },
{ name: 'searchByProjectId' }
],
[
{ 'recipeFor.id': 1, dateCreated: -1 },
{ name: 'searchByRecipeForId' }
]
];
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;
}
;