@briswell/bw-domain
Version:
Domain Library for Node.js
45 lines (44 loc) • 2.3 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 Sequelize = require("sequelize");
const quotationSummary_1 = require("../model/quotationSummary");
const common_1 = require("../utils/common");
class QuotationSummaryRepository {
constructor(db) {
this.quotationSummaryModel = quotationSummary_1.default(db);
}
search(params) {
return __awaiter(this, void 0, void 0, function* () {
const strippedParams = common_1.stripUndefinedField(params);
const findOption = strippedParams;
if (strippedParams.where !== undefined) {
const where = findOption.where;
// 見積日の条件がある場合
if (typeof strippedParams.where.quotationDate === 'object' &&
!(strippedParams.where.quotationDate instanceof Date)) {
const quotationDate = strippedParams.where.quotationDate;
where.quotationDate = {};
if (quotationDate.from !== undefined) {
where.quotationDate = Object.assign({}, where.quotationDate, { [Sequelize.Op.gte]: quotationDate.from });
}
if (quotationDate.to !== undefined) {
where.quotationDate = Object.assign({}, where.quotationDate, { [Sequelize.Op.lte]: quotationDate.to });
}
}
}
if (params.sort !== undefined) {
findOption.order = [['id', params.sort]];
}
return this.quotationSummaryModel.findAll(findOption);
});
}
}
exports.default = QuotationSummaryRepository;