UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

160 lines (159 loc) 3.97 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 = 'Authorization'; exports.modelName = modelName; const schemaDefinition = { project: { type: mongoose_1.SchemaTypes.Mixed, required: true }, typeOf: { type: String, required: true }, code: { type: String, required: true }, object: mongoose_1.SchemaTypes.Mixed, validFrom: { type: Date, required: true }, validUntil: { type: Date, required: true }, audience: mongoose_1.SchemaTypes.Mixed, // add(2024-05-02~) author: mongoose_1.SchemaTypes.Mixed, // add(2024-05-02~) issuedBy: mongoose_1.SchemaTypes.Mixed // add(2024-05-06~) }; const schemaOptions = { autoIndex: settings_1.MONGO_AUTO_INDEX, autoCreate: false, collection: 'authorizations', 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 = [ [ // コードはユニークなはず { code: 1 }, { unique: true, name: 'uniqueCode' } ], [ { validFrom: 1 }, { name: 'searchByValidFrom' } ], [ { 'project.id': 1, validFrom: 1 }, { name: 'searchByProjectId-v20220721' } ], [ { typeOf: 1, validFrom: 1 }, { name: 'searchByTypeOf-v2' } ], [ { code: 1, validFrom: 1 }, { name: 'searchByCode-v2' } ], [ { validUntil: 1, validFrom: 1 }, { name: 'searchByValidUntil-v2' } ], [ { 'object.typeOf': 1, validFrom: 1 }, { name: 'searchByObjectTypeOf', partialFilterExpression: { 'object.typeOf': { $exists: true } } } ], [ { 'object.id': 1, validFrom: 1 }, { name: 'searchByObjectId', partialFilterExpression: { 'object.id': { $exists: true } } } ], [ { 'object.orderNumber': 1, validFrom: 1 }, { name: 'objectOrderNumber', partialFilterExpression: { 'object.orderNumber': { $exists: true } } } ], [ { 'object.typeOfGood.typeOf': 1, validFrom: 1 }, { name: 'searchByObjectTypeOfGoodTypeOf', partialFilterExpression: { 'object.typeOfGood.typeOf': { $exists: true } } } ], [ { 'object.typeOfGood.id': 1, validFrom: 1 }, { name: 'searchByObjectTypeOfGoodId', partialFilterExpression: { 'object.typeOfGood.id': { $exists: true } } } ], [ { 'audience.id': 1, validFrom: 1 }, { name: 'audienceId', partialFilterExpression: { 'audience.id': { $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; }