UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

108 lines (107 loc) 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const mongoose = require("mongoose"); const safe = { j: true, w: 'majority', wtimeout: 10000 }; const agentSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const recipientSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const resultSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const errorSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const objectSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const purposeSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const locationSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); const potentialActionsSchema = new mongoose.Schema({}, { id: false, _id: false, strict: false }); /** * アクションスキーマ */ const schema = new mongoose.Schema({ actionStatus: String, typeOf: String, description: String, agent: agentSchema, recipient: recipientSchema, result: resultSchema, error: errorSchema, object: objectSchema, startDate: Date, endDate: Date, purpose: purposeSchema, potentialActions: potentialActionsSchema, amount: Number, fromLocation: locationSchema, toLocation: locationSchema }, { collection: 'actions', id: true, read: 'primaryPreferred', safe: safe, strict: true, useNestedStrict: true, timestamps: { createdAt: 'createdAt', updatedAt: 'updatedAt' }, toJSON: { getters: true }, toObject: { getters: true } }); schema.index({ createdAt: 1 }, { name: 'searchByCreatedAt' }); schema.index({ updatedAt: 1 }, { name: 'searchByUpdatedAt' }); schema.index({ typeOf: 1, _id: 1 }); schema.index({ 'fromLocation.accountNumber': 1, typeOf: 1 }, { partialFilterExpression: { 'fromLocation.accountNumber': { $exists: true } } }); schema.index({ 'toLocation.accountNumber': 1, typeOf: 1 }, { partialFilterExpression: { 'toLocation.accountNumber': { $exists: true } } }); schema.index({ 'purpose.typeOf': 1 }, { partialFilterExpression: { 'purpose.typeOf': { $exists: true } } }); schema.index({ typeOf: 1, startDate: 1, endDate: 1, actionStatus: 1 }, { name: 'searchActions' }); exports.default = mongoose.model('Action', schema).on('index', // tslint:disable-next-line:no-single-line-block-comment /* istanbul ignore next */ (error) => { if (error !== undefined) { // tslint:disable-next-line:no-console console.error(error); } });