@chevre/domain
Version:
Chevre Domain Library for Node.js
82 lines (81 loc) • 2.29 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 = 'OfferCatalogItem';
exports.modelName = modelName;
const schemaDefinition = {
project: mongoose_1.SchemaTypes.Mixed,
identifier: {
type: String,
required: true
},
name: mongoose_1.SchemaTypes.Mixed,
description: mongoose_1.SchemaTypes.Mixed,
alternateName: mongoose_1.SchemaTypes.Mixed,
typeOf: {
type: String,
required: true
},
itemListElement: [mongoose_1.SchemaTypes.Mixed],
itemOffered: mongoose_1.SchemaTypes.Mixed,
additionalProperty: [mongoose_1.SchemaTypes.Mixed],
dateSynced: Date,
relatedOffer: mongoose_1.SchemaTypes.Mixed
// createdAt: SchemaTypes.Mixed,
// updatedAt: SchemaTypes.Mixed,
// __v: SchemaTypes.Mixed
};
const schemaOptions = {
autoIndex: settings_1.MONGO_AUTO_INDEX,
autoCreate: false,
collection: 'offerCatalogItems',
id: true,
read: settings_1.MONGO_READ_PREFERENCE,
writeConcern: writeConcern_1.writeConcern,
strict: true,
strictQuery: false,
timestamps: false, // 2024-11-13~
versionKey: false, // 2024-11-13~
toJSON: {
getters: false,
virtuals: false,
minimize: false,
versionKey: false
},
toObject: {
getters: false,
virtuals: true,
minimize: false,
versionKey: false
}
};
const indexes = [
[
// add unique index(2024-11-12~)
{ 'project.id': 1, identifier: 1 },
{
unique: true,
name: 'uniqueIdentifier'
}
]
];
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;
}
;