UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

151 lines (150 loc) 4.02 kB
"use strict"; 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 factory = require("../../../factory"); const settings_1 = require("../../../settings"); const modelName = 'CategoryCode'; exports.modelName = modelName; const schemaDefinition = { project: { type: mongoose_1.SchemaTypes.Mixed, required: true }, typeOf: { type: String, required: true }, additionalProperty: [mongoose_1.SchemaTypes.Mixed], color: String, image: String, codeValue: { type: String, required: true }, inCodeSet: { type: mongoose_1.SchemaTypes.Mixed, required: true }, name: mongoose_1.SchemaTypes.Mixed, paymentMethod: mongoose_1.SchemaTypes.Mixed }; const schemaOptions = { autoIndex: settings_1.MONGO_AUTO_INDEX, autoCreate: false, collection: 'categoryCodes', id: true, read: settings_1.MONGO_READ_PREFERENCE, writeConcern: writeConcern_1.writeConcern, strict: true, strictQuery: false, timestamps: false, // 2024-08-22~ versionKey: false, // 2024-08-22~ toJSON: { getters: false, virtuals: false, minimize: false, versionKey: false }, toObject: { getters: false, virtuals: true, minimize: false, versionKey: false } }; const indexes = [ [ { codeValue: 1 }, { name: 'searchByCodeValue' } ], [ { 'inCodeSet.identifier': 1, codeValue: 1 }, { name: 'inCodeSetIdentifier' } ], [ { 'name.ja': 1, codeValue: 1 }, { name: 'searchByNameJa', partialFilterExpression: { 'name.ja': { $exists: true } } } ], [ { 'name.en': 1, codeValue: 1 }, { name: 'searchByNameEn', partialFilterExpression: { 'name.en': { $exists: true } } } ], [ { 'paymentMethod.typeOf': 1, codeValue: 1 }, { name: 'searchByPaymentMethodTypeOf', partialFilterExpression: { 'paymentMethod.typeOf': { $exists: true } } } ], [ { 'project.id': 1, codeValue: 1 }, { name: 'searchByProjectId-v20220721' } ], [ { additionalProperty: 1, codeValue: 1 }, { name: 'searchByAdditionalProperty', partialFilterExpression: { additionalProperty: { $exists: true } } } ], // add unique index(2024-11-14~) [ { 'project.id': 1, 'inCodeSet.identifier': 1, codeValue: 1 }, { unique: true, name: 'uniqueByCodeValueAndInCodeSet', partialFilterExpression: { // tslint:disable-next-line:no-null-keyword 'paymentMethod.typeOf': null } } ], [ { 'project.id': 1, 'paymentMethod.typeOf': 1, codeValue: 1 }, { unique: true, name: 'uniqueByCodeValueAndPaymentMethod', partialFilterExpression: { 'inCodeSet.identifier': { $eq: factory.categoryCode.CategorySetIdentifier.MovieTicketType }, 'paymentMethod.typeOf': { $exists: true } } } ] ]; 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; }