@chevre/domain
Version:
Chevre Domain Library for Node.js
105 lines (104 loc) • 4.13 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 place_1 = require("./mongoose/model/place");
const factory = require("../factory");
/**
* 場所リポジトリー
*/
class MongoRepository {
constructor(connection) {
this.placeModel = connection.model(place_1.default.modelName);
}
static CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params) {
// MongoDB検索条件
const andConditions = [
{
typeOf: factory.placeType.MovieTheater
}
];
// tslint:disable-next-line:no-single-line-block-comment
/* istanbul ignore else */
if (params.name !== undefined) {
andConditions.push({
$or: [
{ 'name.ja': new RegExp(params.name, 'i') },
{ 'name.en': new RegExp(params.name, 'i') },
{ kanaName: new RegExp(params.name, 'i') }
]
});
}
return andConditions;
}
/**
* 劇場を保管する
*/
saveMovieTheater(params) {
return __awaiter(this, void 0, void 0, function* () {
yield this.placeModel.findOneAndUpdate({
typeOf: factory.placeType.MovieTheater,
branchCode: params.branchCode
}, params, { upsert: true }).exec();
});
}
countMovieTheaters(params) {
return __awaiter(this, void 0, void 0, function* () {
const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
return this.placeModel.countDocuments({ $and: conditions }).setOptions({ maxTimeMS: 10000 })
.exec();
});
}
/**
* 劇場検索
*/
searchMovieTheaters(params) {
return __awaiter(this, void 0, void 0, function* () {
const conditions = MongoRepository.CREATE_MOVIE_THEATER_MONGO_CONDITIONS(params);
// containsPlaceを含めるとデータサイズが大きくなるので、検索結果には含めない
const query = this.placeModel.find({ $and: conditions }, {
__v: 0,
createdAt: 0,
updatedAt: 0,
containsPlace: 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()));
});
}
/**
* 枝番号で劇場検索
*/
findMovieTheaterByBranchCode(params) {
return __awaiter(this, void 0, void 0, function* () {
const doc = yield this.placeModel.findOne({
typeOf: factory.placeType.MovieTheater,
branchCode: params.branchCode
}, {
__v: 0,
createdAt: 0,
updatedAt: 0
}).exec();
if (doc === null) {
throw new factory.errors.NotFound('Movie Theater');
}
return doc.toObject();
});
}
}
exports.MongoRepository = MongoRepository;
;