@chevre/domain
Version:
Chevre Domain Library for Node.js
78 lines (77 loc) • 3.48 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const priceSpecification_1 = require("./mongoose/model/priceSpecification");
/**
* 価格仕様リポジトリー
*/
class MongoRepository {
constructor(connection) {
this.priceSpecificationModel = connection.model(priceSpecification_1.default.modelName);
}
static CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params) {
const andConditions = [
{
typeOf: params.typeOf
}
];
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.validFrom !== undefined) {
andConditions.push({
validThrough: { $exists: true, $gt: params.validFrom }
});
}
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.validThrough !== undefined) {
andConditions.push({
validFrom: { $exists: true, $lt: params.validThrough }
});
}
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.priceComponent !== undefined) {
andConditions.push({
'priceComponent.typeOf': { $exists: true, $eq: params.priceComponent.typeOf }
});
}
return andConditions;
}
countCompoundPriceSpecifications(params) {
return __awaiter(this, void 0, void 0, function* () {
const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
return this.priceSpecificationModel.countDocuments({ $and: conditions }).setOptions({ maxTimeMS: 10000 })
.exec();
});
}
searchCompoundPriceSpecifications(params) {
return __awaiter(this, void 0, void 0, function* () {
const conditions = MongoRepository.CREATE_COMPOUND_PRICE_SPECIFICATION_MONGO_CONDITIONS(params);
const query = this.priceSpecificationModel.find({ $and: conditions }, {
__v: 0,
createdAt: 0,
updatedAt: 0
});
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.limit !== undefined && params.page !== undefined) {
query.limit(params.limit).skip(params.limit * (params.page - 1));
}
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.sort !== undefined) {
query.sort(params.sort);
}
return query.setOptions({ maxTimeMS: 10000 }).exec().then((docs) => docs.map((doc) => doc.toObject()));
});
}
}
exports.MongoRepository = MongoRepository;
;