UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

55 lines (54 loc) 2.42 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 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) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ScheduleRepo = void 0; const schedule_1 = require("./mongoose/schemas/schedule"); /** * スケジュールリポジトリ */ class ScheduleRepo { constructor(connection) { this.scheduleModel = connection.model(schedule_1.modelName, (0, schedule_1.createSchema)()); } // public async saveOne(params: factory.schedule.IEventWithSchedule): Promise<void> { // await this.scheduleModel.create(params); // } findOne(filter) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; const andQuery = []; const idEq = (_a = filter.id) === null || _a === void 0 ? void 0 : _a.$eq; if (typeof idEq === 'string') { andQuery.push({ _id: { $eq: idEq } }); } const projectIdEq = (_c = (_b = filter.project) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.$eq; if (typeof projectIdEq === 'string') { andQuery.push({ 'project.id': { $eq: projectIdEq } }); } const filterQuery = Object.assign({}, (andQuery.length > 0) ? { $and: andQuery } : undefined); return this.scheduleModel.findOne(filterQuery) .lean() .exec(); }); } findOneId() { return __awaiter(this, void 0, void 0, function* () { return this.scheduleModel.findOne({}, { _id: 0, id: { $toString: '$_id' }, project: '$project' }) .lean() .exec(); }); } } exports.ScheduleRepo = ScheduleRepo;