UNPKG

json-api-nestjs

Version:
24 lines 998 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getRelationship = getRelationship; const common_1 = require("@nestjs/common"); const core_1 = require("@mikro-orm/core"); async function getRelationship(id, rel) { const result = await this.microOrmUtilService .queryBuilder() .leftJoinAndSelect(`${this.microOrmUtilService.currentAlias}.${rel.toString()}`, rel.toString(), {}, [this.microOrmUtilService.getPrimaryNameFor(rel)]) .where({ [this.microOrmUtilService.currentPrimaryColumn]: id, }) .getSingleResult(); if (!result) { const error = { code: 'invalid_arguments', message: `Resource '${this.microOrmUtilService.currentAlias}' with id '${id}' does not exist`, path: ['fields'], }; throw new common_1.NotFoundException([error]); } return (0, core_1.serialize)(result, { forceObject: true }); } //# sourceMappingURL=get-relationship.js.map