nicot 1.2.4 → 1.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -783,6 +783,18 @@ var QueryOr = (...decs) => {
783
783
  });
784
784
  };
785
785
 
786
+ // src/decorators/binding.ts
787
+ var DefaultBindingKey = "default";
788
+ var BindingColumn = (bindingKey = DefaultBindingKey) => Metadata.set("bindingColumn", bindingKey, "bindingColumnFields");
789
+ var BindingValue = (bindingKey = DefaultBindingKey) => (obj, key, des) => {
790
+ const isMethod = !!des && typeof des.value === "function";
791
+ Metadata.set(
792
+ "bindingValue",
793
+ { bindingKey, isMethod },
794
+ "bindingValueFields"
795
+ )(obj, key);
796
+ };
797
+
786
798
  // src/dto/cursor-pagination.ts
787
799
  var CursorPaginationDto = class {
788
800
  };
@@ -1033,6 +1045,7 @@ import { camelCase } from "typeorm/util/StringUtils";
1033
1045
  import _3, { omit } from "lodash";
1034
1046
  import {
1035
1047
  BlankReturnMessageDto as BlankReturnMessageDto2,
1048
+ GenericReturnMessageDto,
1036
1049
  PaginatedReturnMessageDto,
1037
1050
  ReturnMessageDto
1038
1051
  } from "nesties";
@@ -1381,6 +1394,30 @@ async function getPaginatedResult(qb, entityClass, entityAliasName, take, cursor
1381
1394
 
1382
1395
  // src/crud-base.ts
1383
1396
  import PQueue from "p-queue";
1397
+
1398
+ // src/utility/observe-diff.ts
1399
+ var observeDiff = (obj, cb) => {
1400
+ return new Proxy(obj, {
1401
+ set(target, key, value) {
1402
+ const oldValue = target[key];
1403
+ const type = Object.prototype.hasOwnProperty.call(target, key) ? "update" : "add";
1404
+ target[key] = value;
1405
+ cb({ type, key, oldValue, newValue: value });
1406
+ return true;
1407
+ },
1408
+ deleteProperty(target, key) {
1409
+ if (Object.prototype.hasOwnProperty.call(target, key)) {
1410
+ const oldValue = target[key];
1411
+ delete target[key];
1412
+ cb({ type: "delete", key, oldValue, newValue: void 0 });
1413
+ return true;
1414
+ }
1415
+ return false;
1416
+ }
1417
+ });
1418
+ };
1419
+
1420
+ // src/crud-base.ts
1384
1421
  var Relation = (name, options = {}) => {
1385
1422
  return { name, inner: false, ...options };
1386
1423
  };
@@ -1414,7 +1451,11 @@ var CrudBase = class {
1414
1451
  });
1415
1452
  this.log = new ConsoleLogger(`${this.entityClass.name}Service`);
1416
1453
  this._typeormRelations = getTypeormRelations(this.entityClass);
1454
+ // binding things
1455
+ this._tmpBindingMap = /* @__PURE__ */ new Map();
1456
+ this._bindingCache = /* @__PURE__ */ new Map();
1417
1457
  }
1458
+ // cleaning entities
1418
1459
  _cleanEntityNotInResultFields(ent) {
1419
1460
  const visited = /* @__PURE__ */ new Set();
1420
1461
  const runSingleObject = (o, cl) => {
@@ -1458,6 +1499,105 @@ var CrudBase = class {
1458
1499
  return this._cleanEntityNotInResultFields(ents);
1459
1500
  }
1460
1501
  }
1502
+ _lookForBindingValueField(bindingKey) {
1503
+ if (this._bindingCache.has(bindingKey)) {
1504
+ return this._bindingCache.get(bindingKey);
1505
+ }
1506
+ const bindingServiceFields = getSpecificFields(this, "bindingValue");
1507
+ const useField = bindingServiceFields.find((f) => {
1508
+ const meta = reflector.get("bindingValue", this, f);
1509
+ return meta?.bindingKey === bindingKey;
1510
+ });
1511
+ if (useField) {
1512
+ const meta = reflector.get("bindingValue", this, useField);
1513
+ const res = {
1514
+ ...meta,
1515
+ field: useField
1516
+ };
1517
+ this._bindingCache.set(bindingKey, res);
1518
+ return res;
1519
+ }
1520
+ return void 0;
1521
+ }
1522
+ _resolveBindingValue(entityField) {
1523
+ const bindingKey = reflector.get(
1524
+ "bindingColumn",
1525
+ this.entityClass,
1526
+ entityField
1527
+ );
1528
+ if (!bindingKey) {
1529
+ return void 0;
1530
+ }
1531
+ if (this._tmpBindingMap.has(bindingKey)) {
1532
+ return this._tmpBindingMap.get(bindingKey);
1533
+ }
1534
+ const bindingValueField = this._lookForBindingValueField(bindingKey);
1535
+ if (!bindingValueField) {
1536
+ return void 0;
1537
+ }
1538
+ if (bindingValueField.isMethod) {
1539
+ return this[bindingValueField.field]();
1540
+ } else {
1541
+ return this[bindingValueField.field];
1542
+ }
1543
+ }
1544
+ // MUST be called 1st on every CRUD operation
1545
+ async getBindingPartialEntity() {
1546
+ const bindingFields = getSpecificFields(this.entityClass, "bindingColumn");
1547
+ if (!bindingFields.length) {
1548
+ return {};
1549
+ }
1550
+ const values = bindingFields.map((field, i) => {
1551
+ return {
1552
+ field,
1553
+ value: this._resolveBindingValue(field),
1554
+ i
1555
+ };
1556
+ });
1557
+ this._tmpBindingMap.clear();
1558
+ const containingPromiseValues = values.filter(
1559
+ (v) => v.value instanceof Promise
1560
+ );
1561
+ if (containingPromiseValues.length) {
1562
+ await Promise.all(
1563
+ containingPromiseValues.map(async (v) => {
1564
+ v.value = await v.value;
1565
+ })
1566
+ );
1567
+ }
1568
+ const res = {};
1569
+ for (const v of values) {
1570
+ if (v.value != null) {
1571
+ res[v.field] = v.value;
1572
+ }
1573
+ }
1574
+ return res;
1575
+ }
1576
+ useBinding(value, bindngKey = DefaultBindingKey) {
1577
+ this._tmpBindingMap.set(bindngKey, value);
1578
+ return this;
1579
+ }
1580
+ _freezeBindings() {
1581
+ const res = {};
1582
+ for (const [key, value] of this._tmpBindingMap.entries()) {
1583
+ res[key] = value;
1584
+ }
1585
+ this._tmpBindingMap.clear();
1586
+ return res;
1587
+ }
1588
+ _restoreBindings(frozen) {
1589
+ this._tmpBindingMap.clear();
1590
+ for (const key of Object.keys(frozen)) {
1591
+ this._tmpBindingMap.set(key, frozen[key]);
1592
+ }
1593
+ return this;
1594
+ }
1595
+ async beforeSuper(fn) {
1596
+ const snap = this._freezeBindings();
1597
+ const res = await fn();
1598
+ this._restoreBindings(snap);
1599
+ return res;
1600
+ }
1461
1601
  async _batchCreate(ents, beforeCreate, skipErrors = false) {
1462
1602
  const entsWithId = ents.filter((ent) => ent.id != null);
1463
1603
  return this.repo.manager.transaction(async (mdb) => {
@@ -1563,6 +1703,7 @@ var CrudBase = class {
1563
1703
  });
1564
1704
  }
1565
1705
  async create(_ent, beforeCreate) {
1706
+ const bindingEnt = await this.getBindingPartialEntity();
1566
1707
  if (!_ent) {
1567
1708
  throw new BlankReturnMessageDto2(400, "Invalid entity").toException();
1568
1709
  }
@@ -1597,6 +1738,7 @@ var CrudBase = class {
1597
1738
  }
1598
1739
  }
1599
1740
  }
1741
+ Object.assign(ent, bindingEnt);
1600
1742
  if (beforeCreate) {
1601
1743
  await beforeCreate(repo);
1602
1744
  }
@@ -1662,10 +1804,20 @@ var CrudBase = class {
1662
1804
  queryBuilder() {
1663
1805
  return this.repo.createQueryBuilder(this.entityAliasName);
1664
1806
  }
1807
+ _applyQueryFromBinding(bindingEnt, qb) {
1808
+ for (const [key, value] of Object.entries(bindingEnt)) {
1809
+ const typeormKey = `_binding_${key}`;
1810
+ qb.andWhere(`${this.entityAliasName}.${key} = :${typeormKey}`, {
1811
+ [typeormKey]: value
1812
+ });
1813
+ }
1814
+ }
1665
1815
  async findOne(id, extraQuery = () => {
1666
1816
  }) {
1817
+ const bindingEnt = await this.getBindingPartialEntity();
1667
1818
  const query = this.queryBuilder().where(`${this.entityAliasName}.id = :id`, { id }).take(1);
1668
1819
  this._applyQueryRelations(query);
1820
+ this._applyQueryFromBinding(bindingEnt, query);
1669
1821
  this.extraGetQuery(query);
1670
1822
  extraQuery(query);
1671
1823
  query.take(1);
@@ -1696,6 +1848,7 @@ var CrudBase = class {
1696
1848
  }
1697
1849
  async _preFindAll(ent, extraQuery = () => {
1698
1850
  }) {
1851
+ const bindingEnt = await this.getBindingPartialEntity();
1699
1852
  const query = this.queryBuilder().where("1 = 1");
1700
1853
  const newEnt = new this.entityClass();
1701
1854
  if (ent) {
@@ -1705,6 +1858,7 @@ var CrudBase = class {
1705
1858
  }
1706
1859
  this._applyQueryRelations(query);
1707
1860
  this._applyQueryFilters(query, newEnt);
1861
+ this._applyQueryFromBinding(bindingEnt, query);
1708
1862
  const pageSettings = newEnt instanceof PageSettingsDto ? newEnt : Object.assign(new PageSettingsDto(), newEnt);
1709
1863
  this.extraGetQuery(query);
1710
1864
  extraQuery(query);
@@ -1763,6 +1917,7 @@ var CrudBase = class {
1763
1917
  }
1764
1918
  }
1765
1919
  async update(id, entPart, cond = {}) {
1920
+ const bindingEnt = await this.getBindingPartialEntity();
1766
1921
  let result;
1767
1922
  const ent = new this.entityClass();
1768
1923
  Object.assign(ent, entPart);
@@ -1775,6 +1930,7 @@ var CrudBase = class {
1775
1930
  result = await this.repo.update(
1776
1931
  {
1777
1932
  id,
1933
+ ...bindingEnt,
1778
1934
  ...cond
1779
1935
  },
1780
1936
  ent
@@ -1796,9 +1952,11 @@ var CrudBase = class {
1796
1952
  return new BlankReturnMessageDto2(200, "success");
1797
1953
  }
1798
1954
  async delete(id, cond = {}) {
1955
+ const bindingEnt = await this.getBindingPartialEntity();
1799
1956
  let result;
1800
1957
  const searchCond = {
1801
1958
  id,
1959
+ ...bindingEnt,
1802
1960
  ...cond
1803
1961
  };
1804
1962
  try {
@@ -1816,6 +1974,7 @@ var CrudBase = class {
1816
1974
  return new BlankReturnMessageDto2(200, "success");
1817
1975
  }
1818
1976
  async importEntities(_ents, extraChecking) {
1977
+ const bindingEnt = await this.getBindingPartialEntity();
1819
1978
  const ents = _ents.map((ent) => {
1820
1979
  const newEnt = new this.entityClass();
1821
1980
  Object.assign(
@@ -1843,6 +2002,9 @@ var CrudBase = class {
1843
2002
  const remainingEnts = ents.filter(
1844
2003
  (ent) => !invalidResults.find((result) => result.entry === ent)
1845
2004
  );
2005
+ for (const ent of remainingEnts) {
2006
+ Object.assign(ent, bindingEnt);
2007
+ }
1846
2008
  await Promise.all(remainingEnts.map((ent) => ent.beforeCreate?.()));
1847
2009
  const data = await this._batchCreate(remainingEnts, void 0, true);
1848
2010
  await Promise.all(data.results.map((e) => e.afterCreate?.()));
@@ -1862,9 +2024,72 @@ var CrudBase = class {
1862
2024
  })
1863
2025
  );
1864
2026
  }
1865
- async exists(id) {
1866
- const ent = await this.repo.findOne({ where: { id }, select: ["id"] });
1867
- return !!ent;
2027
+ async exists(id, cond = {}) {
2028
+ const bindingEnt = await this.getBindingPartialEntity();
2029
+ return this.repo.exists({
2030
+ where: { id, ...bindingEnt, ...cond }
2031
+ });
2032
+ }
2033
+ async operation(id, cb, extraOptions = {}) {
2034
+ const bindingEnt = await this.getBindingPartialEntity();
2035
+ const where = {
2036
+ id,
2037
+ ...bindingEnt,
2038
+ ...extraOptions.where || {}
2039
+ };
2040
+ const throw404 = () => {
2041
+ throw new BlankReturnMessageDto2(
2042
+ 404,
2043
+ `${this.entityName} ID ${id} not found.`
2044
+ ).toException();
2045
+ };
2046
+ if (!await this.repo.exists({ where })) {
2047
+ throw404();
2048
+ }
2049
+ const res = await this.repo.manager.transaction(async (tdb) => {
2050
+ const repo = tdb.getRepository(this.entityClass);
2051
+ const ent = await repo.findOne({
2052
+ lock: { mode: "pessimistic_write" },
2053
+ ...extraOptions,
2054
+ where
2055
+ });
2056
+ if (!ent) {
2057
+ throw404();
2058
+ }
2059
+ const initial = { ...ent };
2060
+ let changes = {};
2061
+ const entProxy = observeDiff(ent, (change) => {
2062
+ if (change.type === "delete") {
2063
+ if (initial[change.key] === null) {
2064
+ delete changes[change.key];
2065
+ } else {
2066
+ changes[change.key] = null;
2067
+ }
2068
+ } else {
2069
+ if (change.newValue !== initial[change.key]) {
2070
+ changes[change.key] = change.newValue;
2071
+ } else {
2072
+ delete changes[change.key];
2073
+ }
2074
+ }
2075
+ });
2076
+ const flush = async () => {
2077
+ if (Object.keys(changes).length) {
2078
+ const currentChanges = { ...changes };
2079
+ Object.assign(initial, changes);
2080
+ changes = {};
2081
+ await repo.update({ id }, currentChanges);
2082
+ }
2083
+ };
2084
+ const result = await cb(entProxy, { repo, flush });
2085
+ await flush();
2086
+ return result;
2087
+ });
2088
+ if (res == null) {
2089
+ return new BlankReturnMessageDto2(200, "success");
2090
+ } else {
2091
+ return new GenericReturnMessageDto(200, "success", res);
2092
+ }
1868
2093
  }
1869
2094
  async _loadFullTextIndex() {
1870
2095
  const fields = reflector.getArray(
@@ -1926,18 +2151,17 @@ import {
1926
2151
  Query
1927
2152
  } from "@nestjs/common";
1928
2153
  import {
1929
- BlankReturnMessageDto as BlankReturnMessageDto3,
1930
2154
  MergeMethodDecorators,
1931
2155
  PaginatedReturnMessageDto as PaginatedReturnMessageDto2,
1932
2156
  ReturnMessageDto as ReturnMessageDto2,
1933
2157
  getApiProperty as getApiProperty2,
1934
- DataPipe
2158
+ DataPipe,
2159
+ ApiTypeResponse,
2160
+ ApiBlankResponse,
2161
+ ApiError
1935
2162
  } from "nesties";
1936
2163
  import {
1937
- ApiBadRequestResponse,
1938
2164
  ApiBody,
1939
- ApiInternalServerErrorResponse,
1940
- ApiNotFoundResponse,
1941
2165
  ApiOkResponse,
1942
2166
  ApiOperation,
1943
2167
  ApiParam,
@@ -2115,7 +2339,132 @@ var _RestfulFactory = class _RestfulFactory {
2115
2339
  filterRelations(entityClass, options.relations);
2116
2340
  }
2117
2341
  }
2118
- getEntityClassName() {
2342
+ omitInput(...fields) {
2343
+ return new _RestfulFactory(
2344
+ this.entityClass,
2345
+ {
2346
+ ...this.options,
2347
+ fieldsToOmit: _5.uniq([...this.options.fieldsToOmit || [], ...fields])
2348
+ },
2349
+ this.__resolveVisited
2350
+ );
2351
+ }
2352
+ omitWrite(...fields) {
2353
+ return new _RestfulFactory(
2354
+ this.entityClass,
2355
+ {
2356
+ ...this.options,
2357
+ writeFieldsToOmit: _5.uniq([
2358
+ ...this.options.writeFieldsToOmit || [],
2359
+ ...fields
2360
+ ])
2361
+ },
2362
+ this.__resolveVisited
2363
+ );
2364
+ }
2365
+ omitCreate(...fields) {
2366
+ return new _RestfulFactory(
2367
+ this.entityClass,
2368
+ {
2369
+ ...this.options,
2370
+ createFieldsToOmit: _5.uniq([
2371
+ ...this.options.createFieldsToOmit || [],
2372
+ ...fields
2373
+ ])
2374
+ },
2375
+ this.__resolveVisited
2376
+ );
2377
+ }
2378
+ omitUpdate(...fields) {
2379
+ return new _RestfulFactory(
2380
+ this.entityClass,
2381
+ {
2382
+ ...this.options,
2383
+ updateFieldsToOmit: _5.uniq([
2384
+ ...this.options.updateFieldsToOmit || [],
2385
+ ...fields
2386
+ ])
2387
+ },
2388
+ this.__resolveVisited
2389
+ );
2390
+ }
2391
+ omitFindAll(...fields) {
2392
+ return new _RestfulFactory(
2393
+ this.entityClass,
2394
+ {
2395
+ ...this.options,
2396
+ findAllFieldsToOmit: _5.uniq([
2397
+ ...this.options.findAllFieldsToOmit || [],
2398
+ ...fields
2399
+ ])
2400
+ },
2401
+ this.__resolveVisited
2402
+ );
2403
+ }
2404
+ omitOutput(...fields) {
2405
+ return new _RestfulFactory(
2406
+ this.entityClass,
2407
+ {
2408
+ ...this.options,
2409
+ outputFieldsToOmit: _5.uniq([
2410
+ ...this.options.outputFieldsToOmit || [],
2411
+ ...fields
2412
+ ])
2413
+ },
2414
+ this.__resolveVisited
2415
+ );
2416
+ }
2417
+ pathPrefix(prefix) {
2418
+ return new _RestfulFactory(
2419
+ this.entityClass,
2420
+ {
2421
+ ...this.options,
2422
+ prefix
2423
+ },
2424
+ this.__resolveVisited
2425
+ );
2426
+ }
2427
+ keepEntityVersioningDates(enable = true) {
2428
+ return new _RestfulFactory(
2429
+ this.entityClass,
2430
+ {
2431
+ ...this.options,
2432
+ keepEntityVersioningDates: enable
2433
+ },
2434
+ this.__resolveVisited
2435
+ );
2436
+ }
2437
+ skipNonQueryableFields(enable = true) {
2438
+ return new _RestfulFactory(
2439
+ this.entityClass,
2440
+ {
2441
+ ...this.options,
2442
+ skipNonQueryableFields: enable
2443
+ },
2444
+ this.__resolveVisited
2445
+ );
2446
+ }
2447
+ renameEntityClass(name) {
2448
+ return new _RestfulFactory(
2449
+ this.entityClass,
2450
+ {
2451
+ ...this.options,
2452
+ entityClassName: name
2453
+ },
2454
+ this.__resolveVisited
2455
+ );
2456
+ }
2457
+ useRelations(...relations) {
2458
+ return new _RestfulFactory(
2459
+ this.entityClass,
2460
+ {
2461
+ ...this.options,
2462
+ relations: [...this.options.relations || [], ...relations]
2463
+ },
2464
+ this.__resolveVisited
2465
+ );
2466
+ }
2467
+ get entityClassName() {
2119
2468
  return this.options.entityClassName || this.entityClass.name;
2120
2469
  }
2121
2470
  get fieldsToOmit() {
@@ -2139,7 +2488,7 @@ var _RestfulFactory = class _RestfulFactory {
2139
2488
  get createDto() {
2140
2489
  return RenameClass(
2141
2490
  OmitTypeExclude(this.entityClass, this.fieldsInCreateToOmit),
2142
- `Create${this.entityClass.name}Dto`
2491
+ `Create${this.entityClassName}Dto`
2143
2492
  );
2144
2493
  }
2145
2494
  get fieldsInUpdateToOmit() {
@@ -2154,7 +2503,7 @@ var _RestfulFactory = class _RestfulFactory {
2154
2503
  get updateDto() {
2155
2504
  return RenameClass(
2156
2505
  PartialType(OmitTypeExclude(this.entityClass, this.fieldsInUpdateToOmit)),
2157
- `Update${this.entityClass.name}Dto`
2506
+ `Update${this.entityClassName}Dto`
2158
2507
  );
2159
2508
  }
2160
2509
  get importDto() {
@@ -2198,7 +2547,7 @@ var _RestfulFactory = class _RestfulFactory {
2198
2547
  if (this.options.skipNonQueryableFields) {
2199
2548
  cl = PickTypeExpose(cl, this.queryableFields);
2200
2549
  }
2201
- return RenameClass(cl, `Find${this.entityClass.name}Dto`);
2550
+ return RenameClass(cl, `Find${this.entityClassName}Dto`);
2202
2551
  }
2203
2552
  get findAllCursorPaginatedDto() {
2204
2553
  return RenameClass(
@@ -2206,7 +2555,7 @@ var _RestfulFactory = class _RestfulFactory {
2206
2555
  OmitTypeExclude(this.findAllDto, ["pageCount"]),
2207
2556
  CursorPaginationDto
2208
2557
  ),
2209
- `Find${this.entityClass.name}CursorPaginatedDto`
2558
+ `Find${this.entityClassName}CursorPaginatedDto`
2210
2559
  );
2211
2560
  }
2212
2561
  get entityResultDto() {
@@ -2249,7 +2598,7 @@ var _RestfulFactory = class _RestfulFactory {
2249
2598
  const relationFactory = new _RestfulFactory(
2250
2599
  relation.propertyClass,
2251
2600
  {
2252
- entityClassName: `${this.getEntityClassName()}${this.options.relations ? upperFirst(relation.propertyName) : relation.propertyClass.name}`,
2601
+ entityClassName: `${this.entityClassName}${this.options.relations ? upperFirst(relation.propertyName) : relation.propertyClass.name}`,
2253
2602
  relations: this.options.relations && getNextLevelRelations(
2254
2603
  this.options.relations.map(extractRelationName),
2255
2604
  relation.propertyName
@@ -2280,7 +2629,7 @@ var _RestfulFactory = class _RestfulFactory {
2280
2629
  }
2281
2630
  const res = RenameClass(
2282
2631
  resultDto,
2283
- `${this.getEntityClassName()}ResultDto`
2632
+ `${this.entityClassName}ResultDto`
2284
2633
  );
2285
2634
  const currentContainer = this.__resolveVisited.get(this.entityClass);
2286
2635
  if (currentContainer) {
@@ -2300,7 +2649,7 @@ var _RestfulFactory = class _RestfulFactory {
2300
2649
  (m) => !m.keepInCreate
2301
2650
  )
2302
2651
  ]),
2303
- `${this.getEntityClassName()}CreateResultDto`
2652
+ `${this.entityClassName}CreateResultDto`
2304
2653
  );
2305
2654
  }
2306
2655
  get entityReturnMessageDto() {
@@ -2342,15 +2691,12 @@ var _RestfulFactory = class _RestfulFactory {
2342
2691
  this.usePrefix(Post),
2343
2692
  HttpCode(200),
2344
2693
  ApiOperation({
2345
- summary: `Create a new ${this.getEntityClassName()}`,
2694
+ summary: `Create a new ${this.entityClassName}`,
2346
2695
  ...extras
2347
2696
  }),
2348
2697
  ApiBody({ type: this.createDto }),
2349
2698
  ApiOkResponse({ type: this.entityCreateReturnMessageDto }),
2350
- ApiBadRequestResponse({
2351
- type: BlankReturnMessageDto3,
2352
- description: `The ${this.getEntityClassName()} is not valid`
2353
- })
2699
+ ApiError(400, `The ${this.entityClassName} is not valid`)
2354
2700
  ]);
2355
2701
  }
2356
2702
  createParam() {
@@ -2360,15 +2706,15 @@ var _RestfulFactory = class _RestfulFactory {
2360
2706
  return MergeMethodDecorators([
2361
2707
  this.usePrefix(Get, ":id"),
2362
2708
  ApiOperation({
2363
- summary: `Find a ${this.getEntityClassName()} by id`,
2709
+ summary: `Find a ${this.entityClassName} by id`,
2364
2710
  ...extras
2365
2711
  }),
2366
2712
  ApiParam({ name: "id", type: this.idType, required: true }),
2367
2713
  ApiOkResponse({ type: this.entityReturnMessageDto }),
2368
- ApiNotFoundResponse({
2369
- type: BlankReturnMessageDto3,
2370
- description: `The ${this.getEntityClassName()} with the given id was not found`
2371
- })
2714
+ ApiError(
2715
+ 400,
2716
+ `The ${this.entityClassName} with the given id was not found`
2717
+ )
2372
2718
  ]);
2373
2719
  }
2374
2720
  idParam() {
@@ -2382,7 +2728,7 @@ var _RestfulFactory = class _RestfulFactory {
2382
2728
  return MergeMethodDecorators([
2383
2729
  this.usePrefix(Get),
2384
2730
  ApiOperation({
2385
- summary: `Find all ${this.getEntityClassName()}`,
2731
+ summary: `Find all ${this.entityClassName}`,
2386
2732
  ...extras
2387
2733
  }),
2388
2734
  ApiOkResponse({ type: this.entityArrayReturnMessageDto })
@@ -2392,7 +2738,7 @@ var _RestfulFactory = class _RestfulFactory {
2392
2738
  return MergeMethodDecorators([
2393
2739
  this.usePrefix(Get),
2394
2740
  ApiOperation({
2395
- summary: `Find all ${this.getEntityClassName()}`,
2741
+ summary: `Find all ${this.entityClassName}`,
2396
2742
  ...extras
2397
2743
  }),
2398
2744
  ApiOkResponse({ type: this.entityCursorPaginationReturnMessageDto })
@@ -2419,24 +2765,18 @@ var _RestfulFactory = class _RestfulFactory {
2419
2765
  this.usePrefix(Patch, ":id"),
2420
2766
  HttpCode(200),
2421
2767
  ApiOperation({
2422
- summary: `Update a ${this.getEntityClassName()} by id`,
2768
+ summary: `Update a ${this.entityClassName} by id`,
2423
2769
  ...extras
2424
2770
  }),
2425
2771
  ApiParam({ name: "id", type: this.idType, required: true }),
2426
2772
  ApiBody({ type: this.updateDto }),
2427
- ApiOkResponse({ type: BlankReturnMessageDto3 }),
2428
- ApiNotFoundResponse({
2429
- type: BlankReturnMessageDto3,
2430
- description: `The ${this.getEntityClassName()} with the given id was not found`
2431
- }),
2432
- ApiBadRequestResponse({
2433
- type: BlankReturnMessageDto3,
2434
- description: `The ${this.getEntityClassName()} is not valid`
2435
- }),
2436
- ApiInternalServerErrorResponse({
2437
- type: BlankReturnMessageDto3,
2438
- description: "Internal error"
2439
- })
2773
+ ApiBlankResponse(),
2774
+ ApiError(
2775
+ 404,
2776
+ `The ${this.entityClassName} with the given id was not found`
2777
+ ),
2778
+ ApiError(400, `The ${this.entityClassName} is not valid`),
2779
+ ApiError(500, "Internal error")
2440
2780
  ]);
2441
2781
  }
2442
2782
  updateParam() {
@@ -2447,35 +2787,44 @@ var _RestfulFactory = class _RestfulFactory {
2447
2787
  this.usePrefix(Delete, ":id"),
2448
2788
  HttpCode(200),
2449
2789
  ApiOperation({
2450
- summary: `Delete a ${this.getEntityClassName()} by id`,
2790
+ summary: `Delete a ${this.entityClassName} by id`,
2451
2791
  ...extras
2452
2792
  }),
2453
2793
  ApiParam({ name: "id", type: this.idType, required: true }),
2454
- ApiOkResponse({ type: BlankReturnMessageDto3 }),
2455
- ApiNotFoundResponse({
2456
- type: BlankReturnMessageDto3,
2457
- description: `The ${this.getEntityClassName()} with the given id was not found`
2458
- }),
2459
- ApiInternalServerErrorResponse({
2460
- type: BlankReturnMessageDto3,
2461
- description: "Internal error"
2462
- })
2794
+ ApiBlankResponse(),
2795
+ ApiError(
2796
+ 404,
2797
+ `The ${this.entityClassName} with the given id was not found`
2798
+ ),
2799
+ ApiError(500, "Internal error")
2463
2800
  ]);
2464
2801
  }
2465
2802
  import(extras = {}) {
2466
2803
  return MergeMethodDecorators([
2467
- Post("import"),
2804
+ this.usePrefix(Post, "import"),
2468
2805
  HttpCode(200),
2469
2806
  ApiOperation({
2470
- summary: `Import ${this.getEntityClassName()}`,
2807
+ summary: `Import ${this.entityClassName}`,
2471
2808
  ...extras
2472
2809
  }),
2473
2810
  ApiBody({ type: this.importDto }),
2474
2811
  ApiOkResponse({ type: this.importReturnMessageDto }),
2475
- ApiInternalServerErrorResponse({
2476
- type: BlankReturnMessageDto3,
2477
- description: "Internal error"
2478
- })
2812
+ ApiError(500, "Internal error")
2813
+ ]);
2814
+ }
2815
+ operation(operationName, options = {}) {
2816
+ return MergeMethodDecorators([
2817
+ this.usePrefix(Post, `:id/${operationName}`),
2818
+ HttpCode(200),
2819
+ ApiOperation({
2820
+ summary: `${upperFirst(operationName)} a ${this.entityClassName} by id`,
2821
+ ...options.operationExtras || {}
2822
+ }),
2823
+ options.returnType ? ApiTypeResponse(options.returnType) : ApiBlankResponse(),
2824
+ ApiError(
2825
+ 404,
2826
+ `The ${this.entityClassName} with the given id was not found`
2827
+ )
2479
2828
  ]);
2480
2829
  }
2481
2830
  baseController(routeOptions = {}) {
@@ -2589,7 +2938,7 @@ var _RestfulFactory = class _RestfulFactory {
2589
2938
  Object.defineProperty(cl.prototype, method, descriptor);
2590
2939
  });
2591
2940
  }
2592
- return RenameClass(cl, `${this.getEntityClassName()}Controller`);
2941
+ return RenameClass(cl, `${this.entityClassName}Controller`);
2593
2942
  }
2594
2943
  crudService(options = {}) {
2595
2944
  return CrudService(this.entityClass, {
@@ -2720,6 +3069,8 @@ var applyQueryMatchBooleanMySQL = createQueryCondition(
2720
3069
  }
2721
3070
  );
2722
3071
  export {
3072
+ BindingColumn,
3073
+ BindingValue,
2723
3074
  BlankCursorPaginationReturnMessageDto,
2724
3075
  BoolColumn,
2725
3076
  CrudBase,
@@ -2727,6 +3078,7 @@ export {
2727
3078
  CursorPaginationDto,
2728
3079
  CursorPaginationReturnMessageDto,
2729
3080
  DateColumn,
3081
+ DefaultBindingKey,
2730
3082
  EnumColumn,
2731
3083
  FloatColumn,
2732
3084
  GenericCursorPaginationReturnMessageDto,