UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

73 lines (72 loc) 3.44 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.PermitRepo = void 0; const serviceOutput_1 = require("./mongoose/schemas/serviceOutput"); const factory = require("../factory"); /** * 許可証リポジトリ */ class PermitRepo { constructor(connection) { this.serviceOutputModel = connection.model(serviceOutput_1.modelName, (0, serviceOutput_1.createSchema)()); } findByIdentifier(params, projection) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const query = this.serviceOutputModel.findOne(Object.assign({ 'project.id': { $eq: params.project.id.$eq }, identifier: { $exists: true, $eq: params.identifier.$eq } }, (typeof ((_b = (_a = params.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === null || _b === void 0 ? void 0 : _b.$eq) === 'string') ? { 'issuedThrough.typeOf': { $exists: true, $eq: params.issuedThrough.typeOf.$eq } } : undefined), Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection)); const doc = yield query.exec(); if (doc === null) { throw new factory.errors.NotFound(this.serviceOutputModel.modelName); } return doc.toObject(); }); } findByIdentifierAndAccessCode(params, projection) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const query = this.serviceOutputModel.findOne(Object.assign({ 'project.id': { $eq: params.project.id.$eq }, accessCode: { $exists: true, $eq: params.accessCode.$eq }, identifier: { $exists: true, $eq: params.identifier.$eq } }, (typeof ((_b = (_a = params.issuedThrough) === null || _a === void 0 ? void 0 : _a.typeOf) === null || _b === void 0 ? void 0 : _b.$eq) === 'string') ? { 'issuedThrough.typeOf': { $exists: true, $eq: params.issuedThrough.typeOf.$eq } } : undefined), Object.assign({ __v: 0, createdAt: 0, updatedAt: 0 }, projection)); const doc = yield query.exec(); if (doc === null) { throw new factory.errors.NotFound(this.serviceOutputModel.modelName); } return doc.toObject(); }); } } exports.PermitRepo = PermitRepo;