@chevre/domain
Version:
Chevre Domain Library for Node.js
134 lines (133 loc) • 3.97 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 = 'AccountTitle';
exports.modelName = modelName;
const schemaDefinition = {
project: mongoose_1.SchemaTypes.Mixed,
typeOf: {
type: String,
required: true
},
codeValue: String,
name: String,
inCodeSet: mongoose_1.SchemaTypes.Mixed,
hasCategoryCode: mongoose_1.SchemaTypes.Mixed,
inDefinedTermSet: mongoose_1.SchemaTypes.Mixed,
hasDefinedTerm: mongoose_1.SchemaTypes.Mixed,
additionalProperty: mongoose_1.SchemaTypes.Mixed
};
const schemaOptions = {
autoIndex: settings_1.MONGO_AUTO_INDEX,
autoCreate: false,
collection: 'accountTitles',
id: true,
read: settings_1.MONGO_READ_PREFERENCE,
writeConcern: writeConcern_1.writeConcern,
strict: true, // 2024-09-24~
strictQuery: false,
timestamps: false, // 2024-09-03~
versionKey: false, // 2024-09-03~
toJSON: {
getters: false,
virtuals: false,
minimize: false,
versionKey: false
},
toObject: {
getters: false,
virtuals: true,
minimize: false,
versionKey: false
}
};
const indexes = [
[
{ codeValue: 1 },
{ name: 'searchByCodeValue' }
],
[
{ 'hasCategoryCode.codeValue': 1, codeValue: 1 },
{
name: 'searchByHasCategoryCodeCodeValue',
partialFilterExpression: {
'hasCategoryCode.codeValue': { $exists: true }
}
}
],
[
{ 'hasCategoryCode.hasCategoryCode.codeValue': 1, codeValue: 1 },
{
name: 'searchByHasCategoryCodeHasCategoryCodeCodeValue',
partialFilterExpression: {
'hasCategoryCode.hasCategoryCode.codeValue': { $exists: true }
}
}
],
[
{ 'hasCategoryCode.hasCategoryCode.name': 1, codeValue: 1 },
{
name: 'searchByHasCategoryCodeHasCategoryCodeName',
partialFilterExpression: {
'hasCategoryCode.hasCategoryCode.name': { $exists: true }
}
}
],
[
{ 'project.id': 1, codeValue: 1 },
{
name: 'uniqueCodeValue',
unique: true,
partialFilterExpression: {
'project.id': { $exists: true },
codeValue: { $exists: true }
}
}
],
[
{ 'project.id': 1, 'hasCategoryCode.codeValue': 1 },
{
name: 'uniqueHasCategoryCodeCodeValue',
unique: true,
partialFilterExpression: {
'project.id': { $exists: true },
'hasCategoryCode.codeValue': { $exists: true }
}
}
]
];
exports.indexes = indexes;
// 'hasCategoryCode.hasCategoryCode.codeValue': null のインデックスは作成されてうまくいかないので保留
// schema.index(
// {
// 'project.id': 1,
// 'hasCategoryCode.hasCategoryCode.codeValue': 1
// },
// {
// name: 'uniqueHasCategoryCodeHasCategoryCodeCodeValue',
// unique: true,
// partialFilterExpression: {
// 'project.id': { $exists: true },
// 'hasCategoryCode.hasCategoryCode.codeValue': { $exists: true }
// }
// }
// );
/**
* 勘定科目スキーマ
*/
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;
}
;