1 | "use strict";
|
2 | var __assign = (this && this.__assign) || function () {
|
3 | __assign = Object.assign || function(t) {
|
4 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
5 | s = arguments[i];
|
6 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
7 | t[p] = s[p];
|
8 | }
|
9 | return t;
|
10 | };
|
11 | return __assign.apply(this, arguments);
|
12 | };
|
13 | var __spreadArrays = (this && this.__spreadArrays) || function () {
|
14 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
15 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
16 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
17 | r[k] = a[j];
|
18 | return r;
|
19 | };
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | exports.ManyToOne = void 0;
|
22 | require("reflect-metadata");
|
23 | var type_graphql_1 = require("type-graphql");
|
24 | var typeorm_1 = require("typeorm");
|
25 | var decorators_1 = require("../decorators");
|
26 | var utils_1 = require("../utils");
|
27 | function ManyToOne(parentType, joinFunc, options) {
|
28 | if (options === void 0) { options = {}; }
|
29 |
|
30 | var klass;
|
31 | var extractClassName = function (target) {
|
32 | klass = target.constructor.name;
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var createForeignKeyField = function (target, propertyKey, descriptor) {
|
39 | klass = target.constructor.name;
|
40 | Reflect.defineProperty(target, klass + "Id", {});
|
41 | decorators_1.IdField(options)(target, propertyKey + "Id", descriptor);
|
42 | };
|
43 |
|
44 |
|
45 | var graphQLdecorator = [
|
46 | type_graphql_1.Field(parentType, __assign({ nullable: true }, options))
|
47 | ];
|
48 |
|
49 | var factories = __spreadArrays([
|
50 | extractClassName
|
51 | ], graphQLdecorator, [
|
52 | typeorm_1.ManyToOne(parentType, joinFunc, options),
|
53 | typeorm_1.JoinColumn(),
|
54 | createForeignKeyField
|
55 | ]);
|
56 | return utils_1.composeMethodDecorators.apply(void 0, factories);
|
57 | }
|
58 | exports.ManyToOne = ManyToOne;
|
59 |
|
\ | No newline at end of file |