1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Column = void 0;
|
4 | const attribute_service_1 = require("./attribute-service");
|
5 | const data_type_service_1 = require("../../sequelize/data-type/data-type-service");
|
6 | const model_service_1 = require("../shared/model-service");
|
7 | function Column(...args) {
|
8 |
|
9 |
|
10 | if (args.length >= 2) {
|
11 | const target = args[0];
|
12 | const propertyName = args[1];
|
13 | const propertyDescriptor = args[2];
|
14 | annotate(target, propertyName, propertyDescriptor);
|
15 | return;
|
16 | }
|
17 | return (target, propertyName, propertyDescriptor) => {
|
18 | annotate(target, propertyName, propertyDescriptor, args[0]);
|
19 | };
|
20 | }
|
21 | exports.Column = Column;
|
22 | function annotate(target, propertyName, propertyDescriptor, optionsOrDataType = {}) {
|
23 | let options;
|
24 | if ((0, data_type_service_1.isDataType)(optionsOrDataType)) {
|
25 | options = {
|
26 | type: optionsOrDataType,
|
27 | };
|
28 | }
|
29 | else {
|
30 | options = Object.assign({}, optionsOrDataType);
|
31 | if (!options.type) {
|
32 | options.type = (0, model_service_1.getSequelizeTypeByDesignType)(target, propertyName);
|
33 | }
|
34 | }
|
35 | if (propertyDescriptor) {
|
36 | if (propertyDescriptor.get) {
|
37 | options.get = propertyDescriptor.get;
|
38 | }
|
39 | if (propertyDescriptor.set) {
|
40 | options.set = propertyDescriptor.set;
|
41 | }
|
42 | }
|
43 | (0, attribute_service_1.addAttribute)(target, propertyName, options);
|
44 | }
|
45 |
|
\ | No newline at end of file |