UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

141 lines (140 loc) 4 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 settings_1 = require("../../../settings"); const modelName = 'Product'; exports.modelName = modelName; const schemaDefinition = { project: mongoose_1.SchemaTypes.Mixed, typeOf: { type: String, required: true }, additionalProperty: [mongoose_1.SchemaTypes.Mixed], availableChannel: mongoose_1.SchemaTypes.Mixed, description: mongoose_1.SchemaTypes.Mixed, hasOfferCatalog: mongoose_1.SchemaTypes.Mixed, name: mongoose_1.SchemaTypes.Mixed, offers: [mongoose_1.SchemaTypes.Mixed], productID: { type: String, required: true }, // provider: [SchemaTypes.Mixed], // 廃止(2024-04-12~) serviceOutput: mongoose_1.SchemaTypes.Mixed, serviceType: mongoose_1.SchemaTypes.Mixed }; const schemaOptions = { autoIndex: settings_1.MONGO_AUTO_INDEX, autoCreate: false, collection: 'products', 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 = [ [ { productID: 1 }, { name: 'searchByProductID' } ], [ { 'project.id': 1, productID: 1 }, { name: 'searchByProjectId-v20220721' } ], [ { 'hasOfferCatalog.id': 1, productID: 1 }, { name: 'searchByHasOfferCatalog', partialFilterExpression: { 'hasOfferCatalog.id': { $exists: true } } } ], [ { 'hasOfferCatalog.itemListElement.id': 1, productID: 1 }, // add(2024-09-27~) { name: 'offerCatalogItemId', partialFilterExpression: { 'hasOfferCatalog.itemListElement.id': { $exists: true } } } ], [ { 'serviceOutput.typeOf': 1, productID: 1 }, { name: 'searchByServiceOutputTypeOf', partialFilterExpression: { 'serviceOutput.typeOf': { $exists: true } } } ], [ { 'serviceOutput.amount.currency': 1, productID: 1 }, { name: 'searchByServiceOutputAmountCurrency', partialFilterExpression: { 'serviceOutput.amount.currency': { $exists: true } } } ], [ { 'serviceType.codeValue': 1, productID: 1 }, { name: 'searchByServiceTypeCodeValue', partialFilterExpression: { 'serviceType.codeValue': { $exists: true } } } ], [ { typeOf: 1, productID: 1 }, { name: 'searchByTypeOf' } ], [ { 'name.ja': 1, productID: 1 }, { name: 'searchByNameJa', partialFilterExpression: { 'name.ja': { $exists: true } } } ], [ { 'name.en': 1, productID: 1 }, { name: 'searchByNameEn', partialFilterExpression: { 'name.en': { $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; }