json-api-nestjs
Version:
JsonApi Plugin for NestJs
20 lines • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.postRelationship = postRelationship;
const get_relationship_1 = require("../get-relationship/get-relationship");
async function postRelationship(id, rel, input) {
const idsResult = await this.microOrmUtilService.validateRelationInputData(rel, input);
const currentEntityRef = this.microOrmUtilService.entityManager.getReference(this.microOrmUtilService.entity, id);
const relEntity = this.microOrmUtilService.getRelation(rel).entity();
if (Array.isArray(idsResult)) {
const relRef = idsResult.map((i) => this.microOrmUtilService.entityManager.getReference(relEntity, i));
currentEntityRef[rel].add(...relRef);
}
else {
// @ts-ignore
currentEntityRef[rel] = this.microOrmUtilService.entityManager.getReference(relEntity, idsResult);
}
await this.microOrmUtilService.entityManager.flush();
return get_relationship_1.getRelationship.call(this, id, rel);
}
//# sourceMappingURL=post-relationship.js.map