From 01100a755572125d1aac72ef9473b055aca4998e Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 8 Oct 2025 19:11:34 +0300 Subject: [PATCH 01/24] data store initial --- .../dao/Settings/CountryEntity.entity | 35 ++++ .../dao/Settings/CountryEntity.ts | 7 + .../dao/Settings/CountryRepository.ts | 157 +++++------------- 3 files changed, 86 insertions(+), 113 deletions(-) create mode 100644 codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity create mode 100644 codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity new file mode 100644 index 0000000..c2dc301 --- /dev/null +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity @@ -0,0 +1,35 @@ +{ + "entity-mapping" : { + "class" : { + "entity-name" : "CountryEntity", + "table" : "CODBEX_COUNTRY", + "id" : { + "column" : "COUNTRY_ID", + "name" : "Id", + "type" : "long", + "generator" : { + "class" : "sequence" + } + }, + "property" : [ + { + "column" : "COUNTRY_NAME", + "name" : "Name", + "type" : "string" + }, { + "column" : "COUNTRY_CODE2", + "name" : "Code2", + "type" : "string" + }, { + "column" : "COUNTRY_CODE3", + "name" : "Code3", + "type" : "string" + }, { + "column" : "COUNTRY_NUMERIC", + "name" : "Numeric", + "type" : "string" + } + ] + } + } +} diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts new file mode 100644 index 0000000..cc73c58 --- /dev/null +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts @@ -0,0 +1,7 @@ +export interface CountryEntity { + readonly Id: number; + Name: string; + Code2: string; + Code3: string; + Numeric: string; +} \ No newline at end of file diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 16802eb..26dd9f8 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -1,26 +1,8 @@ import { sql, query } from "sdk/db"; import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -import { dao as daoApi } from "sdk/db"; - -export interface CountryEntity { - readonly Id: number; - Name: string; - Code2: string; - Code3: string; - Numeric: string; -} - -export interface CountryCreateEntity { - readonly Name: string; - readonly Code2: string; - readonly Code3: string; - readonly Numeric: string; -} - -export interface CountryUpdateEntity extends CountryCreateEntity { - readonly Id: number; -} +import { store } from "sdk/db"; +import { CountryEntity } from "./CountryEntity"; export interface CountryEntityOptions { $filter?: { @@ -99,88 +81,49 @@ export interface CountryUpdateEntityEvent extends CountryEntityEvent { export class CountryRepository { - private static readonly DEFINITION = { - table: "CODBEX_COUNTRY", - properties: [ - { - name: "Id", - column: "COUNTRY_ID", - type: "INTEGER", - id: true, - autoIncrement: true, - }, - { - name: "Name", - column: "COUNTRY_NAME", - type: "VARCHAR", - required: true - }, - { - name: "Code2", - column: "COUNTRY_CODE2", - type: "CHAR", - required: true - }, - { - name: "Code3", - column: "COUNTRY_CODE3", - type: "CHAR", - required: true - }, - { - name: "Numeric", - column: "COUNTRY_NUMERIC", - type: "CHAR", - required: true - } - ] - }; - - private readonly dao; - - constructor(dataSource = "DefaultDB") { - this.dao = daoApi.create(CountryRepository.DEFINITION, undefined, dataSource); - } + private static readonly TABLE = "CODBEX_COUNTRY"; public findAll(options: CountryEntityOptions = {}): CountryEntity[] { - let list = this.dao.list(options); - try { - let script = sql.getDialect().select().column("*").from('"' + CountryRepository.DEFINITION.table + '_LANG"').where('Language = ?').build(); - const resultSet = query.execute(script, [options.$language]); - if (resultSet !== null && resultSet[0] !== null) { - let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); - let maps = []; - for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i] = {}; - } - resultSet.forEach((r) => { + let list = store.list("CountryEntity", { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); + if (options.$language) { + try { + let script = sql.getDialect().select().column("*").from('"' + CountryRepository.TABLE + '_LANG"').where('Language = ?').build(); + const resultSet = query.execute(script, [options.$language]); + if (resultSet !== null && resultSet[0] !== null) { + let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); + let maps: any[] = []; for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i][r[translatedProperties[0]]] = r[translatedProperties[i + 1]]; + maps[i] = {}; } - }); - list.forEach((r) => { - for (let i = 0; i < translatedProperties.length - 2; i++) { - if (maps[i][r[translatedProperties[0]]]) { - r[translatedProperties[i + 1]] = maps[i][r[translatedProperties[0]]]; + resultSet.forEach((r) => { + for (let i = 0; i < translatedProperties.length - 2; i++) { + maps[i][r[translatedProperties[0]]] = r[translatedProperties[i + 1]]; + } + }); + list.forEach((r) => { + for (let i = 0; i < translatedProperties.length - 2; i++) { + if (maps[i][r[translatedProperties[0]]]) { + r[translatedProperties[i + 1]] = maps[i][r[translatedProperties[0]]]; + } } - } - }); + }); + } + } catch (Error) { + console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.TABLE); } - } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.DEFINITION.table); } return list; } public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { - const entity = this.dao.find(id); - if (entity) { + const entity = store.get("CountryEntity", id); + if (entity && options.$language) { try { - let script = sql.getDialect().select().column("*").from('"' + CountryRepository.DEFINITION.table + '_LANG"').where('Language = ?').where('Id = ?').build(); + let script = sql.getDialect().select().column("*").from('"' + CountryRepository.TABLE + '_LANG"').where('Language = ?').where('Id = ?').build(); const resultSet = query.execute(script, [options.$language, id]); let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); - let maps = []; + let maps: any[] = []; for (let i = 0; i < translatedProperties.length - 2; i++) { maps[i] = {}; } @@ -195,14 +138,14 @@ export class CountryRepository { } } } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.DEFINITION.table); + console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.TABLE); } } return entity ?? undefined; } - public create(entity: CountryCreateEntity): number { - const id = this.dao.insert(entity); + public create(entity: CountryEntity): number { + const id = store.save('CountryEntity', entity); this.triggerEvent({ operation: "create", table: "CODBEX_COUNTRY", @@ -216,7 +159,7 @@ export class CountryRepository { return id; } - public update(entity: CountryUpdateEntity): void { + public update(entity: CountryEntity): void { const previousEntity = this.findById(entity.Id); this.dao.update(entity); this.triggerEvent({ @@ -232,24 +175,24 @@ export class CountryRepository { }); } - public upsert(entity: CountryCreateEntity | CountryUpdateEntity): number { - const id = (entity as CountryUpdateEntity).Id; + public upsert(entity: CountryEntity): number { + const id = entity.Id; if (!id) { - return this.create(entity); + return store.save('CountryEntity', entity); } - const existingEntity = this.findById(id); + const existingEntity = store.get('CountryEntity', id); if (existingEntity) { - this.update(entity as CountryUpdateEntity); + this.update(entity); return id; } else { - return this.create(entity); + return store.save('CountryEntity', entity); } } public deleteById(id: number): void { - const entity = this.dao.find(id); - this.dao.remove(id); + const entity = store.get('CountryEntity', id); + store.remove('CountryEntity', id); this.triggerEvent({ operation: "delete", table: "CODBEX_COUNTRY", @@ -263,19 +206,7 @@ export class CountryRepository { } public count(options?: CountryEntityOptions): number { - return this.dao.count(options); - } - - public customDataCount(): number { - const resultSet = query.execute('SELECT COUNT(*) AS COUNT FROM "CODBEX__COUNTRY"'); - if (resultSet !== null && resultSet[0] !== null) { - if (resultSet[0].COUNT !== undefined && resultSet[0].COUNT !== null) { - return resultSet[0].COUNT; - } else if (resultSet[0].count !== undefined && resultSet[0].count !== null) { - return resultSet[0].count; - } - } - return 0; + return store.count('CountryEntity', options); } private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { @@ -285,7 +216,7 @@ export class CountryRepository { triggerExtension.trigger(data); } catch (error) { console.error(error); - } + } }); producer.topic("codbex-countries-Settings-Country").send(JSON.stringify(data)); } From 9e80245adfa1467ca6cca636f4fcfde184f28e27 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 8 Oct 2025 19:30:12 +0300 Subject: [PATCH 02/24] type checks fixes --- .../codbex-countries/dao/Settings/CountryRepository.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 26dd9f8..920e04c 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -71,7 +71,7 @@ export interface CountryEntityEvent { readonly key: { name: string; column: string; - value: number; + value: string | number; } } @@ -144,7 +144,7 @@ export class CountryRepository { return entity ?? undefined; } - public create(entity: CountryEntity): number { + public create(entity: CountryEntity): string | number { const id = store.save('CountryEntity', entity); this.triggerEvent({ operation: "create", @@ -161,7 +161,7 @@ export class CountryRepository { public update(entity: CountryEntity): void { const previousEntity = this.findById(entity.Id); - this.dao.update(entity); + store.update('CountryEntity', entity); this.triggerEvent({ operation: "update", table: "CODBEX_COUNTRY", @@ -175,7 +175,7 @@ export class CountryRepository { }); } - public upsert(entity: CountryEntity): number { + public upsert(entity: CountryEntity): string | number { const id = entity.Id; if (!id) { return store.save('CountryEntity', entity); @@ -206,7 +206,7 @@ export class CountryRepository { } public count(options?: CountryEntityOptions): number { - return store.count('CountryEntity', options); + return store.count('CountryEntity', { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); } private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { From a2c4aa96da8269c5cb7398c7c6249ca715998c1c Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 12:31:57 +0300 Subject: [PATCH 03/24] entity decorators applied --- .../dao/Settings/CountryEntity.entity.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts new file mode 100644 index 0000000..ffdbe81 --- /dev/null +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts @@ -0,0 +1,23 @@ + +@Entity("CountryEntity") +@Table("CODBEX_COUNTRY") +export class CountryEntity { + + @Id + @Generated("sequence") + @Column({ name: "COUNTRY_ID", type: "long" }) + public Id: number; + + @Column({ name: "COUNTRY_NAME", type: "string" }) + Name: string; + + @Column({ name: "COUNTRY_CODE2", type: "string" }) + Code2: string; + + @Column({ name: "COUNTRY_CODE3", type: "string" }) + Code3: string; + + @Column({ name: "COUNTRY_NUMERIC", type: "string" }) + Numeric: string; + +} \ No newline at end of file From ce3cfbe3ed3b7a838f0230ce88d719cddff2d031 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 12:56:49 +0300 Subject: [PATCH 04/24] delete old artefacts --- .../dao/Settings/CountryEntity.entity | 35 ------------------- .../dao/Settings/CountryEntity.ts | 7 ---- 2 files changed, 42 deletions(-) delete mode 100644 codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity delete mode 100644 codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity deleted file mode 100644 index c2dc301..0000000 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity +++ /dev/null @@ -1,35 +0,0 @@ -{ - "entity-mapping" : { - "class" : { - "entity-name" : "CountryEntity", - "table" : "CODBEX_COUNTRY", - "id" : { - "column" : "COUNTRY_ID", - "name" : "Id", - "type" : "long", - "generator" : { - "class" : "sequence" - } - }, - "property" : [ - { - "column" : "COUNTRY_NAME", - "name" : "Name", - "type" : "string" - }, { - "column" : "COUNTRY_CODE2", - "name" : "Code2", - "type" : "string" - }, { - "column" : "COUNTRY_CODE3", - "name" : "Code3", - "type" : "string" - }, { - "column" : "COUNTRY_NUMERIC", - "name" : "Numeric", - "type" : "string" - } - ] - } - } -} diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts deleted file mode 100644 index cc73c58..0000000 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface CountryEntity { - readonly Id: number; - Name: string; - Code2: string; - Code3: string; - Numeric: string; -} \ No newline at end of file From 1e2d76614c7899ba67f7a5aba4962a1e6fe5b79d Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 13:16:45 +0300 Subject: [PATCH 05/24] decorators added --- .../dao/Settings/CountryEntity.entity.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts index ffdbe81..3e542f0 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts @@ -1,3 +1,4 @@ +import { Entity, Table, Id, Generated, Column } from "sdk/data"; @Entity("CountryEntity") @Table("CODBEX_COUNTRY") @@ -6,18 +7,18 @@ export class CountryEntity { @Id @Generated("sequence") @Column({ name: "COUNTRY_ID", type: "long" }) - public Id: number; + public Id?: number; @Column({ name: "COUNTRY_NAME", type: "string" }) - Name: string; + public Name?: string; @Column({ name: "COUNTRY_CODE2", type: "string" }) - Code2: string; + public Code2?: string; @Column({ name: "COUNTRY_CODE3", type: "string" }) - Code3: string; + public Code3?: string; @Column({ name: "COUNTRY_NUMERIC", type: "string" }) - Numeric: string; + public Numeric?: string; } \ No newline at end of file From c70fcb9a1ab5bf73fcf65c7da2d1eec60a5b51b6 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 13:24:10 +0300 Subject: [PATCH 06/24] sdk/http/errors, sdk/http/utils, sdk/utils/converter adaptations --- .../api/Settings/CountryService.ts | 5 +- .../api/utils/ForbiddenError.ts | 8 --- .../codbex-countries/api/utils/HttpUtils.ts | 60 ------------------- .../api/utils/ValidationError.ts | 8 --- .../dao/Settings/CountryRepository.ts | 4 +- .../codbex-countries/dao/utils/EntityUtils.ts | 20 ------- 6 files changed, 4 insertions(+), 101 deletions(-) delete mode 100644 codbex-countries/gen/codbex-countries/api/utils/ForbiddenError.ts delete mode 100644 codbex-countries/gen/codbex-countries/api/utils/HttpUtils.ts delete mode 100644 codbex-countries/gen/codbex-countries/api/utils/ValidationError.ts delete mode 100644 codbex-countries/gen/codbex-countries/dao/utils/EntityUtils.ts diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts index 32dcb29..adc683f 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts @@ -2,9 +2,8 @@ import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http" import { Extensions } from "sdk/extensions" import { CountryRepository, CountryEntityOptions } from "../../dao/Settings/CountryRepository"; import { user } from "sdk/security" -import { ForbiddenError } from "../utils/ForbiddenError"; -import { ValidationError } from "../utils/ValidationError"; -import { HttpUtils } from "../utils/HttpUtils"; +import { ForbiddenError, ValidationError } from "sdk/http/errors"; +import { HttpUtils } from "sdk/http/utils"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); diff --git a/codbex-countries/gen/codbex-countries/api/utils/ForbiddenError.ts b/codbex-countries/gen/codbex-countries/api/utils/ForbiddenError.ts deleted file mode 100644 index 775ae84..0000000 --- a/codbex-countries/gen/codbex-countries/api/utils/ForbiddenError.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class ForbiddenError extends Error { - readonly name = "ForbiddenError"; - readonly stack = (new Error()).stack; - - constructor(message: string = "You don't have permission to access this resource") { - super(message); - } -} \ No newline at end of file diff --git a/codbex-countries/gen/codbex-countries/api/utils/HttpUtils.ts b/codbex-countries/gen/codbex-countries/api/utils/HttpUtils.ts deleted file mode 100644 index 80efced..0000000 --- a/codbex-countries/gen/codbex-countries/api/utils/HttpUtils.ts +++ /dev/null @@ -1,60 +0,0 @@ -import { response } from "sdk/http"; - -export class HttpUtils { - - // HTTP 200 - public static sendResponseOk(entity: any): void { - HttpUtils.sendResponse(200, entity); - } - - // HTTP 201 - public static sendResponseCreated(entity): void { - HttpUtils.sendResponse(201, entity); - } - - // HTTP 204 - public static sendResponseNoContent(): void { - HttpUtils.sendResponse(204); - } - - // HTTP 400 - public static sendResponseBadRequest(message): void { - HttpUtils.sendResponse(400, { - "code": 400, - "message": message - }); - } - - // HTTP 403 - public static sendForbiddenRequest(message): void { - HttpUtils.sendResponse(403, { - "code": 403, - "message": message - }); - } - - // HTTP 404 - public static sendResponseNotFound(message): void { - HttpUtils.sendResponse(404, { - "code": 404, - "message": message - }); - } - - // HTTP 500 - public static sendInternalServerError(message): void { - HttpUtils.sendResponse(500, { - "code": 500, - "message": message - }); - } - - // Generic - private static sendResponse(status: number, body?: any): void { - response.setContentType("application/json"); - response.setStatus(status); - if (body) { - response.println(JSON.stringify(body)); - } - } -} \ No newline at end of file diff --git a/codbex-countries/gen/codbex-countries/api/utils/ValidationError.ts b/codbex-countries/gen/codbex-countries/api/utils/ValidationError.ts deleted file mode 100644 index 9b894fa..0000000 --- a/codbex-countries/gen/codbex-countries/api/utils/ValidationError.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class ValidationError extends Error { - readonly name = "ValidationError"; - readonly stack = (new Error()).stack; - - constructor(message: string) { - super(message); - } -} \ No newline at end of file diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 920e04c..f318cc4 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -1,8 +1,8 @@ import { sql, query } from "sdk/db"; import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -import { store } from "sdk/db"; -import { CountryEntity } from "./CountryEntity"; +import { store } from "sdk/data"; +import { CountryEntity } from "./CountryEntity.entity"; export interface CountryEntityOptions { $filter?: { diff --git a/codbex-countries/gen/codbex-countries/dao/utils/EntityUtils.ts b/codbex-countries/gen/codbex-countries/dao/utils/EntityUtils.ts deleted file mode 100644 index 0f8815d..0000000 --- a/codbex-countries/gen/codbex-countries/dao/utils/EntityUtils.ts +++ /dev/null @@ -1,20 +0,0 @@ -export class EntityUtils { - - public static setDate(obj: any, property: string): void { - if (obj && obj[property]) { - obj[property] = new Date(obj[property]).getTime(); - } - } - - public static setLocalDate(obj: any, property: string): void { - if (obj && obj[property]) { - obj[property] = new Date(new Date(obj[property]).setHours(-(new Date().getTimezoneOffset() / 60), 0, 0, 0)).toISOString(); - } - } - - public static setBoolean(obj: any, property: string): void { - if (obj && obj[property] !== undefined) { - obj[property] = obj[property] ? true : false; - } - } -} \ No newline at end of file From d7c5a04f8e82c9c4a57bd306b415f460ee51b89e Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 13:27:25 +0300 Subject: [PATCH 07/24] controller naming convention --- .../{CountryService.ts => CountryController.controller.ts} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename codbex-countries/gen/codbex-countries/api/Settings/{CountryService.ts => CountryController.controller.ts} (97%) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts similarity index 97% rename from codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts rename to codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts index adc683f..16d876c 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts @@ -8,7 +8,7 @@ import { HttpUtils } from "sdk/http/utils"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); @Controller -class CountryService { +class CountryController { private readonly repository = new CountryRepository(); @@ -34,7 +34,7 @@ class CountryService { this.checkPermissions("write"); this.validateEntity(entity); entity.Id = this.repository.create(entity); - response.setHeader("Content-Location", "/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts/" + entity.Id); + response.setHeader("Content-Location", "/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts/" + entity.Id); response.setStatus(response.CREATED); return entity; } catch (error: any) { From ee9803a572cb76945b18f9b15d54e6a22200d727 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 14:03:23 +0300 Subject: [PATCH 08/24] *.entity.ts -> *Entity.ts --- .../{CountryController.controller.ts => CountryController.ts} | 0 .../Settings/{CountryEntity.entity.ts => CountryEntity.ts} | 2 +- .../gen/codbex-countries/dao/Settings/CountryRepository.ts | 4 ++-- 3 files changed, 3 insertions(+), 3 deletions(-) rename codbex-countries/gen/codbex-countries/api/Settings/{CountryController.controller.ts => CountryController.ts} (100%) rename codbex-countries/gen/codbex-countries/dao/Settings/{CountryEntity.entity.ts => CountryEntity.ts} (89%) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts similarity index 100% rename from codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts rename to codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts similarity index 89% rename from codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts rename to codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts index 3e542f0..74c7eab 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.entity.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts @@ -1,4 +1,4 @@ -import { Entity, Table, Id, Generated, Column } from "sdk/data"; +import { Entity, Table, Id, Generated, Column } from "sdk/db"; @Entity("CountryEntity") @Table("CODBEX_COUNTRY") diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index f318cc4..920e04c 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -1,8 +1,8 @@ import { sql, query } from "sdk/db"; import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -import { store } from "sdk/data"; -import { CountryEntity } from "./CountryEntity.entity"; +import { store } from "sdk/db"; +import { CountryEntity } from "./CountryEntity"; export interface CountryEntityOptions { $filter?: { From 75776d56c9937fe95d23302dd884b8cc3dfce6f1 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 14:31:38 +0300 Subject: [PATCH 09/24] translate step 1 --- .../dao/Settings/CountryRepository.ts | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 920e04c..2a4ca47 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -85,10 +85,16 @@ export class CountryRepository { public findAll(options: CountryEntityOptions = {}): CountryEntity[] { let list = store.list("CountryEntity", { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - if (options.$language) { + this.translateList(list, options.$language, CountryRepository.TABLE); + + return list; + } + + private translateList(list: any[], language: string | undefined, basetTable: string): any[] { + if (language) { try { - let script = sql.getDialect().select().column("*").from('"' + CountryRepository.TABLE + '_LANG"').where('Language = ?').build(); - const resultSet = query.execute(script, [options.$language]); + let script = sql.getDialect().select().column("*").from('"' + basetTable + '_LANG"').where('Language = ?').build(); + const resultSet = query.execute(script, [language]); if (resultSet !== null && resultSet[0] !== null) { let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); let maps: any[] = []; @@ -110,7 +116,7 @@ export class CountryRepository { }); } } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.TABLE); + console.error("Entity is marked as language dependent, but no language table present: " + basetTable); } } return list; @@ -118,10 +124,15 @@ export class CountryRepository { public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { const entity = store.get("CountryEntity", id); - if (entity && options.$language) { + this.translateEntity(entity, id, options.$language, CountryRepository.TABLE); + return entity ?? undefined; + } + + private translateEntity(entity: any, id: string | number, language: string | undefined, basetTable: string): any[] { + if (entity && language) { try { - let script = sql.getDialect().select().column("*").from('"' + CountryRepository.TABLE + '_LANG"').where('Language = ?').where('Id = ?').build(); - const resultSet = query.execute(script, [options.$language, id]); + let script = sql.getDialect().select().column("*").from('"' + basetTable + '_LANG"').where('Language = ?').where('Id = ?').build(); + const resultSet = query.execute(script, [language, id]); let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); let maps: any[] = []; for (let i = 0; i < translatedProperties.length - 2; i++) { @@ -138,10 +149,10 @@ export class CountryRepository { } } } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + CountryRepository.TABLE); + console.error("Entity is marked as language dependent, but no language table present: " + basetTable); } } - return entity ?? undefined; + return entity; } public create(entity: CountryEntity): string | number { From 1d699f2fc02a8f5e5087e92a40238a1e1aa9d504 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 14:52:00 +0300 Subject: [PATCH 10/24] translator 2 --- .../dao/Settings/CountryRepository.ts | 66 +------------------ 1 file changed, 3 insertions(+), 63 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 2a4ca47..a82fbc1 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -1,7 +1,7 @@ -import { sql, query } from "sdk/db"; import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; import { store } from "sdk/db"; +import { translator } from "sdk/db"; import { CountryEntity } from "./CountryEntity"; export interface CountryEntityOptions { @@ -85,76 +85,16 @@ export class CountryRepository { public findAll(options: CountryEntityOptions = {}): CountryEntity[] { let list = store.list("CountryEntity", { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - this.translateList(list, options.$language, CountryRepository.TABLE); - - return list; - } - - private translateList(list: any[], language: string | undefined, basetTable: string): any[] { - if (language) { - try { - let script = sql.getDialect().select().column("*").from('"' + basetTable + '_LANG"').where('Language = ?').build(); - const resultSet = query.execute(script, [language]); - if (resultSet !== null && resultSet[0] !== null) { - let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); - let maps: any[] = []; - for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i] = {}; - } - resultSet.forEach((r) => { - for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i][r[translatedProperties[0]]] = r[translatedProperties[i + 1]]; - } - }); - list.forEach((r) => { - for (let i = 0; i < translatedProperties.length - 2; i++) { - if (maps[i][r[translatedProperties[0]]]) { - r[translatedProperties[i + 1]] = maps[i][r[translatedProperties[0]]]; - } - } - - }); - } - } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + basetTable); - } - } + translator.translateList(list, options.$language, CountryRepository.TABLE); return list; } public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { const entity = store.get("CountryEntity", id); - this.translateEntity(entity, id, options.$language, CountryRepository.TABLE); + translator.translateEntity(entity, id, options.$language, CountryRepository.TABLE); return entity ?? undefined; } - private translateEntity(entity: any, id: string | number, language: string | undefined, basetTable: string): any[] { - if (entity && language) { - try { - let script = sql.getDialect().select().column("*").from('"' + basetTable + '_LANG"').where('Language = ?').where('Id = ?').build(); - const resultSet = query.execute(script, [language, id]); - let translatedProperties = Object.getOwnPropertyNames(resultSet[0]); - let maps: any[] = []; - for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i] = {}; - } - resultSet.forEach((r) => { - for (let i = 0; i < translatedProperties.length - 2; i++) { - maps[i][r[translatedProperties[0]]] = r[translatedProperties[i + 1]]; - } - }); - for (let i = 0; i < translatedProperties.length - 2; i++) { - if (maps[i][entity[translatedProperties[0]]]) { - entity[translatedProperties[i + 1]] = maps[i][entity[translatedProperties[0]]]; - } - } - } catch (Error) { - console.error("Entity is marked as language dependent, but no language table present: " + basetTable); - } - } - return entity; - } - public create(entity: CountryEntity): string | number { const id = store.save('CountryEntity', entity); this.triggerEvent({ From 9616da87ced8cc4594f667933e6fa3a9ba15a802 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 15:23:13 +0300 Subject: [PATCH 11/24] definition properties --- .../dao/Settings/CountryRepository.ts | 44 +++++++++---------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index a82fbc1..709dfdf 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -81,29 +81,27 @@ export interface CountryUpdateEntityEvent extends CountryEntityEvent { export class CountryRepository { - private static readonly TABLE = "CODBEX_COUNTRY"; - public findAll(options: CountryEntityOptions = {}): CountryEntity[] { - let list = store.list("CountryEntity", { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - translator.translateList(list, options.$language, CountryRepository.TABLE); + let list = store.list(CountryEntity.DEFINITION_ENTITY_NAME, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); + translator.translateList(list, options.$language, CountryEntity.DEFINITION_TABLE_NAME); return list; } public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { - const entity = store.get("CountryEntity", id); - translator.translateEntity(entity, id, options.$language, CountryRepository.TABLE); + const entity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); + translator.translateEntity(entity, id, options.$language, CountryEntity.DEFINITION_TABLE_NAME); return entity ?? undefined; } public create(entity: CountryEntity): string | number { - const id = store.save('CountryEntity', entity); + const id = store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); this.triggerEvent({ operation: "create", - table: "CODBEX_COUNTRY", + table: CountryEntity.DEFINITION_TABLE_NAME, entity: entity, key: { - name: "Id", - column: "COUNTRY_ID", + name: CountryEntity.DEFINITION_ID_NAME, + column: CountryEntity.DEFINITION_ID_COLUMN, value: id } }); @@ -112,15 +110,15 @@ export class CountryRepository { public update(entity: CountryEntity): void { const previousEntity = this.findById(entity.Id); - store.update('CountryEntity', entity); + store.update(CountryEntity.DEFINITION_ENTITY_NAME, entity); this.triggerEvent({ operation: "update", - table: "CODBEX_COUNTRY", + table: CountryEntity.DEFINITION_TABLE_NAME, entity: entity, previousEntity: previousEntity, key: { - name: "Id", - column: "COUNTRY_ID", + name: CountryEntity.DEFINITION_ID_NAME, + column: CountryEntity.DEFINITION_ID_COLUMN, value: entity.Id } }); @@ -129,35 +127,35 @@ export class CountryRepository { public upsert(entity: CountryEntity): string | number { const id = entity.Id; if (!id) { - return store.save('CountryEntity', entity); + return store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); } - const existingEntity = store.get('CountryEntity', id); + const existingEntity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); if (existingEntity) { this.update(entity); return id; } else { - return store.save('CountryEntity', entity); + return store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); } } public deleteById(id: number): void { - const entity = store.get('CountryEntity', id); - store.remove('CountryEntity', id); + const entity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); + store.remove(CountryEntity.DEFINITION_ENTITY_NAME, id); this.triggerEvent({ operation: "delete", - table: "CODBEX_COUNTRY", + table: CountryEntity.DEFINITION_TABLE_NAME, entity: entity, key: { - name: "Id", - column: "COUNTRY_ID", + name: CountryEntity.DEFINITION_ID_NAME, + column: CountryEntity.DEFINITION_ID_COLUMN, value: id } }); } public count(options?: CountryEntityOptions): number { - return store.count('CountryEntity', { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); + return store.count(CountryEntity.DEFINITION_ENTITY_NAME, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); } private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { From 84fbf8f0ca805592f73805555661ce6704eae641 Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 17:06:35 +0300 Subject: [PATCH 12/24] annotations fix --- .../dao/Settings/CountryEntity.ts | 12 +++--- .../dao/Settings/CountryRepository.ts | 42 +++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts index 74c7eab..2d0d8ab 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts @@ -4,21 +4,21 @@ import { Entity, Table, Id, Generated, Column } from "sdk/db"; @Table("CODBEX_COUNTRY") export class CountryEntity { - @Id + @Id() @Generated("sequence") @Column({ name: "COUNTRY_ID", type: "long" }) - public Id?: number; + public Id: number; @Column({ name: "COUNTRY_NAME", type: "string" }) - public Name?: string; + public Name: string; @Column({ name: "COUNTRY_CODE2", type: "string" }) - public Code2?: string; + public Code2: string; @Column({ name: "COUNTRY_CODE3", type: "string" }) - public Code3?: string; + public Code3: string; @Column({ name: "COUNTRY_NUMERIC", type: "string" }) - public Numeric?: string; + public Numeric: string; } \ No newline at end of file diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts index 709dfdf..701afe8 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts @@ -82,26 +82,26 @@ export interface CountryUpdateEntityEvent extends CountryEntityEvent { export class CountryRepository { public findAll(options: CountryEntityOptions = {}): CountryEntity[] { - let list = store.list(CountryEntity.DEFINITION_ENTITY_NAME, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - translator.translateList(list, options.$language, CountryEntity.DEFINITION_TABLE_NAME); + let list = store.list(CountryEntity.$entity_name, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); + translator.translateList(list, options.$language, CountryEntity.$table_name); return list; } public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { - const entity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); - translator.translateEntity(entity, id, options.$language, CountryEntity.DEFINITION_TABLE_NAME); + const entity = store.get(CountryEntity.$entity_name, id); + translator.translateEntity(entity, id, options.$language, CountryEntity.$table_name); return entity ?? undefined; } public create(entity: CountryEntity): string | number { - const id = store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); + const id = store.save(CountryEntity.$entity_name, entity); this.triggerEvent({ operation: "create", - table: CountryEntity.DEFINITION_TABLE_NAME, + table: CountryEntity.$table_name, entity: entity, key: { - name: CountryEntity.DEFINITION_ID_NAME, - column: CountryEntity.DEFINITION_ID_COLUMN, + name: CountryEntity.$id_name, + column: CountryEntity.$id_column, value: id } }); @@ -110,15 +110,15 @@ export class CountryRepository { public update(entity: CountryEntity): void { const previousEntity = this.findById(entity.Id); - store.update(CountryEntity.DEFINITION_ENTITY_NAME, entity); + store.update(CountryEntity.$entity_name, entity); this.triggerEvent({ operation: "update", - table: CountryEntity.DEFINITION_TABLE_NAME, + table: CountryEntity.$table_name, entity: entity, previousEntity: previousEntity, key: { - name: CountryEntity.DEFINITION_ID_NAME, - column: CountryEntity.DEFINITION_ID_COLUMN, + name: CountryEntity.$id_name, + column: CountryEntity.$id_column, value: entity.Id } }); @@ -127,35 +127,35 @@ export class CountryRepository { public upsert(entity: CountryEntity): string | number { const id = entity.Id; if (!id) { - return store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); + return store.save(CountryEntity.$entity_name, entity); } - const existingEntity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); + const existingEntity = store.get(CountryEntity.$entity_name, id); if (existingEntity) { this.update(entity); return id; } else { - return store.save(CountryEntity.DEFINITION_ENTITY_NAME, entity); + return store.save(CountryEntity.$entity_name, entity); } } public deleteById(id: number): void { - const entity = store.get(CountryEntity.DEFINITION_ENTITY_NAME, id); - store.remove(CountryEntity.DEFINITION_ENTITY_NAME, id); + const entity = store.get(CountryEntity.$entity_name, id); + store.remove(CountryEntity.$entity_name, id); this.triggerEvent({ operation: "delete", - table: CountryEntity.DEFINITION_TABLE_NAME, + table: CountryEntity.$table_name, entity: entity, key: { - name: CountryEntity.DEFINITION_ID_NAME, - column: CountryEntity.DEFINITION_ID_COLUMN, + name: CountryEntity.$id_name, + column: CountryEntity.$id_column, value: id } }); } public count(options?: CountryEntityOptions): number { - return store.count(CountryEntity.DEFINITION_ENTITY_NAME, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); + return store.count(CountryEntity.$entity_name, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); } private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { From 542f15c0ace0f43b9fdf2fa7efa5ebeb47e5ff2f Mon Sep 17 00:00:00 2001 From: delchev Date: Wed, 15 Oct 2025 23:38:48 +0300 Subject: [PATCH 13/24] need instantiation to finalize the decorators parsing --- .../gen/codbex-countries/dao/Settings/CountryEntity.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts index 2d0d8ab..d0d9a02 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts +++ b/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts @@ -21,4 +21,6 @@ export class CountryEntity { @Column({ name: "COUNTRY_NUMERIC", type: "string" }) public Numeric: string; -} \ No newline at end of file +} + +(new CountryEntity()); \ No newline at end of file From e5ecfeb0e8c285e140012313c086657d76bdbdfa Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 09:01:38 +0300 Subject: [PATCH 14/24] dao -> data --- .../codbex-countries/api/Settings/CountryController.ts | 2 +- .../{dao => data}/Settings/Country.extensionpoint | 0 .../{dao => data}/Settings/CountryEntity.ts | 10 +++++----- .../{dao => data}/Settings/CountryRepository.ts | 0 4 files changed, 6 insertions(+), 6 deletions(-) rename codbex-countries/gen/codbex-countries/{dao => data}/Settings/Country.extensionpoint (100%) rename codbex-countries/gen/codbex-countries/{dao => data}/Settings/CountryEntity.ts (78%) rename codbex-countries/gen/codbex-countries/{dao => data}/Settings/CountryRepository.ts (100%) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index 16d876c..1fb7f94 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -1,6 +1,6 @@ import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http" import { Extensions } from "sdk/extensions" -import { CountryRepository, CountryEntityOptions } from "../../dao/Settings/CountryRepository"; +import { CountryRepository, CountryEntityOptions } from "../../data/Settings/CountryRepository"; import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; import { HttpUtils } from "sdk/http/utils"; diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/Country.extensionpoint b/codbex-countries/gen/codbex-countries/data/Settings/Country.extensionpoint similarity index 100% rename from codbex-countries/gen/codbex-countries/dao/Settings/Country.extensionpoint rename to codbex-countries/gen/codbex-countries/data/Settings/Country.extensionpoint diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts similarity index 78% rename from codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts rename to codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts index d0d9a02..dd19c39 100644 --- a/codbex-countries/gen/codbex-countries/dao/Settings/CountryEntity.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts @@ -7,19 +7,19 @@ export class CountryEntity { @Id() @Generated("sequence") @Column({ name: "COUNTRY_ID", type: "long" }) - public Id: number; + public Id!: number; @Column({ name: "COUNTRY_NAME", type: "string" }) - public Name: string; + public Name!: string; @Column({ name: "COUNTRY_CODE2", type: "string" }) - public Code2: string; + public Code2!: string; @Column({ name: "COUNTRY_CODE3", type: "string" }) - public Code3: string; + public Code3!: string; @Column({ name: "COUNTRY_NUMERIC", type: "string" }) - public Numeric: string; + public Numeric!: string; } diff --git a/codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts similarity index 100% rename from codbex-countries/gen/codbex-countries/dao/Settings/CountryRepository.ts rename to codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts From 76c317252459c5f03a42d07a9e60b78e29e21a77 Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 09:18:55 +0300 Subject: [PATCH 15/24] typesafe controller --- .../api/Settings/CountryController.ts | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index 1fb7f94..c6e2c34 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -1,9 +1,10 @@ import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http" import { Extensions } from "sdk/extensions" -import { CountryRepository, CountryEntityOptions } from "../../data/Settings/CountryRepository"; import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; import { HttpUtils } from "sdk/http/utils"; +import { CountryEntity } from "../../data/Settings/CountryEntity"; +import { CountryRepository, CountryEntityOptions } from "../../data/Settings/CountryRepository"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); @@ -13,7 +14,7 @@ class CountryController { private readonly repository = new CountryRepository(); @Get("/") - public getAll(_: any, ctx: any) { + public getAll(_: CountryEntity, ctx: any): CountryEntity[] { try { this.checkPermissions("read"); const options: CountryEntityOptions = { @@ -26,40 +27,44 @@ class CountryController { } catch (error: any) { this.handleError(error); } + return []; } @Post("/") - public create(entity: any) { + public create(entity: CountryEntity): CountryEntity { try { this.checkPermissions("write"); this.validateEntity(entity); - entity.Id = this.repository.create(entity); + entity.Id = this.repository.create(entity) as number; response.setHeader("Content-Location", "/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts/" + entity.Id); response.setStatus(response.CREATED); return entity; } catch (error: any) { this.handleError(error); } + return new CountryEntity(); } @Get("/count") - public count() { + public count(): number { try { this.checkPermissions("read"); - return { count: this.repository.count() }; + return this.repository.count(); } catch (error: any) { this.handleError(error); } + return -1; } @Post("/count") - public countWithFilter(filter: any) { + public countWithFilter(filter: any): number { try { this.checkPermissions("read"); - return { count: this.repository.count(filter) }; + return this.repository.count(filter); } catch (error: any) { this.handleError(error); } + return -1; } @Post("/search") @@ -73,7 +78,7 @@ class CountryController { } @Get("/:id") - public getById(_: any, ctx: any) { + public getById(_: any, ctx: any): CountryEntity { try { this.checkPermissions("read"); const id = parseInt(ctx.pathParameters.id); @@ -89,10 +94,11 @@ class CountryController { } catch (error: any) { this.handleError(error); } + return new CountryEntity(); } @Put("/:id") - public update(entity: any, ctx: any) { + public update(entity: CountryEntity, ctx: any): CountryEntity { try { this.checkPermissions("write"); entity.Id = ctx.pathParameters.id; @@ -102,6 +108,7 @@ class CountryController { } catch (error: any) { this.handleError(error); } + return new CountryEntity(); } @Delete("/:id") @@ -140,7 +147,7 @@ class CountryController { } } - private validateEntity(entity: any): void { + private validateEntity(entity: CountryEntity): void { if (entity.Name?.length > 255) { throw new ValidationError(`The 'Name' exceeds the maximum length of [255] characters`); } From e8319b3a1b2b38870636c6250d416aa6ac916350 Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 09:33:25 +0300 Subject: [PATCH 16/24] (CountryEntity as EntityConstructor) --- .../data/Settings/CountryEntity.ts | 10 ++--- .../data/Settings/CountryRepository.ts | 43 ++++++++++--------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts index dd19c39..7a74d52 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts @@ -7,19 +7,19 @@ export class CountryEntity { @Id() @Generated("sequence") @Column({ name: "COUNTRY_ID", type: "long" }) - public Id!: number; + public Id?: number; @Column({ name: "COUNTRY_NAME", type: "string" }) - public Name!: string; + public Name?: string; @Column({ name: "COUNTRY_CODE2", type: "string" }) - public Code2!: string; + public Code2?: string; @Column({ name: "COUNTRY_CODE3", type: "string" }) - public Code3!: string; + public Code3?: string; @Column({ name: "COUNTRY_NUMERIC", type: "string" }) - public Numeric!: string; + public Numeric?: string; } diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts index 701afe8..58961d4 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts @@ -2,6 +2,7 @@ import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; import { store } from "sdk/db"; import { translator } from "sdk/db"; +import { EntityConstructor } from "sdk/db"; import { CountryEntity } from "./CountryEntity"; export interface CountryEntityOptions { @@ -82,26 +83,26 @@ export interface CountryUpdateEntityEvent extends CountryEntityEvent { export class CountryRepository { public findAll(options: CountryEntityOptions = {}): CountryEntity[] { - let list = store.list(CountryEntity.$entity_name, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - translator.translateList(list, options.$language, CountryEntity.$table_name); + let list = store.list((CountryEntity as EntityConstructor).$entity_name, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); + translator.translateList(list, options.$language, (CountryEntity as EntityConstructor).$table_name); return list; } public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { - const entity = store.get(CountryEntity.$entity_name, id); - translator.translateEntity(entity, id, options.$language, CountryEntity.$table_name); + const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); + translator.translateEntity(entity, id, options.$language, (CountryEntity as EntityConstructor).$table_name); return entity ?? undefined; } public create(entity: CountryEntity): string | number { - const id = store.save(CountryEntity.$entity_name, entity); + const id = store.save((CountryEntity as EntityConstructor).$entity_name, entity); this.triggerEvent({ operation: "create", - table: CountryEntity.$table_name, + table: (CountryEntity as EntityConstructor).$table_name, entity: entity, key: { - name: CountryEntity.$id_name, - column: CountryEntity.$id_column, + name: (CountryEntity as EntityConstructor).$id_name, + column: (CountryEntity as EntityConstructor).$id_column, value: id } }); @@ -110,15 +111,15 @@ export class CountryRepository { public update(entity: CountryEntity): void { const previousEntity = this.findById(entity.Id); - store.update(CountryEntity.$entity_name, entity); + store.update((CountryEntity as EntityConstructor).$entity_name, entity); this.triggerEvent({ operation: "update", - table: CountryEntity.$table_name, + table: (CountryEntity as EntityConstructor).$table_name, entity: entity, previousEntity: previousEntity, key: { - name: CountryEntity.$id_name, - column: CountryEntity.$id_column, + name: (CountryEntity as EntityConstructor).$id_name, + column: (CountryEntity as EntityConstructor).$id_column, value: entity.Id } }); @@ -127,35 +128,35 @@ export class CountryRepository { public upsert(entity: CountryEntity): string | number { const id = entity.Id; if (!id) { - return store.save(CountryEntity.$entity_name, entity); + return store.save((CountryEntity as EntityConstructor).$entity_name, entity); } - const existingEntity = store.get(CountryEntity.$entity_name, id); + const existingEntity = store.get((CountryEntity as EntityConstructor).$entity_name, id); if (existingEntity) { this.update(entity); return id; } else { - return store.save(CountryEntity.$entity_name, entity); + return store.save((CountryEntity as EntityConstructor).$entity_name, entity); } } public deleteById(id: number): void { - const entity = store.get(CountryEntity.$entity_name, id); - store.remove(CountryEntity.$entity_name, id); + const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); + store.remove((CountryEntity as EntityConstructor).$entity_name, id); this.triggerEvent({ operation: "delete", - table: CountryEntity.$table_name, + table: (CountryEntity as EntityConstructor).$table_name, entity: entity, key: { - name: CountryEntity.$id_name, - column: CountryEntity.$id_column, + name: (CountryEntity as EntityConstructor).$id_name, + column: (CountryEntity as EntityConstructor).$id_column, value: id } }); } public count(options?: CountryEntityOptions): number { - return store.count(CountryEntity.$entity_name, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); + return store.count((CountryEntity as EntityConstructor).$entity_name, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); } private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { From b9b3be923a68a2ce82e8126126976401e68ea444 Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 13:30:05 +0300 Subject: [PATCH 17/24] filter adapted --- .../api/Settings/CountryController.ts | 29 +++--- .../data/Settings/CountryRepository.ts | 88 +++---------------- .../ui/Settings/Country/controller.js | 36 ++++---- .../Country/dialog-filter/controller.js | 43 +++++---- .../Country/dialog-window/controller.js | 2 +- 5 files changed, 71 insertions(+), 127 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index c6e2c34..ac74af1 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -3,8 +3,9 @@ import { Extensions } from "sdk/extensions" import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; import { HttpUtils } from "sdk/http/utils"; +import { Options } from "sdk/db"; import { CountryEntity } from "../../data/Settings/CountryEntity"; -import { CountryRepository, CountryEntityOptions } from "../../data/Settings/CountryRepository"; +import { CountryRepository } from "../../data/Settings/CountryRepository"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); @@ -17,10 +18,10 @@ class CountryController { public getAll(_: CountryEntity, ctx: any): CountryEntity[] { try { this.checkPermissions("read"); - const options: CountryEntityOptions = { - $limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined, - $offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined, - $language: request.getLocale().slice(0, 2) + const options: Options = { + limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : 20, + offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : 0, + language: request.getLocale().slice(0, 2) }; return this.repository.findAll(options); @@ -36,7 +37,7 @@ class CountryController { this.checkPermissions("write"); this.validateEntity(entity); entity.Id = this.repository.create(entity) as number; - response.setHeader("Content-Location", "/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.controller.ts/" + entity.Id); + response.setHeader("Content-Location", "/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/" + entity.Id); response.setStatus(response.CREATED); return entity; } catch (error: any) { @@ -60,7 +61,7 @@ class CountryController { public countWithFilter(filter: any): number { try { this.checkPermissions("read"); - return this.repository.count(filter); + return this.repository.count(filter.$filter); } catch (error: any) { this.handleError(error); } @@ -71,7 +72,7 @@ class CountryController { public search(filter: any) { try { this.checkPermissions("read"); - return this.repository.findAll(filter); + return this.repository.findAll(filter.$filter); } catch (error: any) { this.handleError(error); } @@ -82,8 +83,8 @@ class CountryController { try { this.checkPermissions("read"); const id = parseInt(ctx.pathParameters.id); - const options: CountryEntityOptions = { - $language: request.getLocale().slice(0, 2) + const options: Options = { + language: request.getLocale().slice(0, 2) }; const entity = this.repository.findById(id, options); if (entity) { @@ -148,16 +149,16 @@ class CountryController { } private validateEntity(entity: CountryEntity): void { - if (entity.Name?.length > 255) { + if (entity.Name!.length > 255) { throw new ValidationError(`The 'Name' exceeds the maximum length of [255] characters`); } - if (entity.Code2?.length > 2) { + if (entity.Code2!.length > 2) { throw new ValidationError(`The 'Code2' exceeds the maximum length of [2] characters`); } - if (entity.Code3?.length > 3) { + if (entity.Code3!.length > 3) { throw new ValidationError(`The 'Code3' exceeds the maximum length of [3] characters`); } - if (entity.Numeric?.length > 3) { + if (entity.Numeric!.length > 3) { throw new ValidationError(`The 'Numeric' exceeds the maximum length of [3] characters`); } for (const next of validationModules) { diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts index 58961d4..bd5efba 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts @@ -1,70 +1,10 @@ import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -import { store } from "sdk/db"; +import { store, Options } from "sdk/db"; import { translator } from "sdk/db"; import { EntityConstructor } from "sdk/db"; import { CountryEntity } from "./CountryEntity"; -export interface CountryEntityOptions { - $filter?: { - equals?: { - Id?: number | number[]; - Name?: string | string[]; - Code2?: string | string[]; - Code3?: string | string[]; - Numeric?: string | string[]; - }; - notEquals?: { - Id?: number | number[]; - Name?: string | string[]; - Code2?: string | string[]; - Code3?: string | string[]; - Numeric?: string | string[]; - }; - contains?: { - Id?: number; - Name?: string; - Code2?: string; - Code3?: string; - Numeric?: string; - }; - greaterThan?: { - Id?: number; - Name?: string; - Code2?: string; - Code3?: string; - Numeric?: string; - }; - greaterThanOrEqual?: { - Id?: number; - Name?: string; - Code2?: string; - Code3?: string; - Numeric?: string; - }; - lessThan?: { - Id?: number; - Name?: string; - Code2?: string; - Code3?: string; - Numeric?: string; - }; - lessThanOrEqual?: { - Id?: number; - Name?: string; - Code2?: string; - Code3?: string; - Numeric?: string; - }; - }, - $select?: (keyof CountryEntity)[], - $sort?: string | (keyof CountryEntity)[], - $order?: 'ASC' | 'DESC', - $offset?: number, - $limit?: number, - $language?: string -} - export interface CountryEntityEvent { readonly operation: 'create' | 'update' | 'delete'; readonly table: string; @@ -74,23 +14,22 @@ export interface CountryEntityEvent { column: string; value: string | number; } -} - -export interface CountryUpdateEntityEvent extends CountryEntityEvent { - readonly previousEntity: CountryEntity; + readonly previousEntity?: CountryEntity; } export class CountryRepository { - public findAll(options: CountryEntityOptions = {}): CountryEntity[] { - let list = store.list((CountryEntity as EntityConstructor).$entity_name, { 'conditions': [], 'limit': options.$limit || 20, 'offset': options.$offset || 0 }); - translator.translateList(list, options.$language, (CountryEntity as EntityConstructor).$table_name); + public findAll(options: Options = {}): CountryEntity[] { + console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> findAll:" + JSON.stringify(options)); + let list = store.list((CountryEntity as EntityConstructor).$entity_name, options); + translator.translateList(list, options.language, (CountryEntity as EntityConstructor).$table_name); return list; } - public findById(id: number, options: CountryEntityOptions = {}): CountryEntity | undefined { + public findById(id: number, options: Options = {}): CountryEntity | undefined { + console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> findById:" + JSON.stringify(options)); const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - translator.translateEntity(entity, id, options.$language, (CountryEntity as EntityConstructor).$table_name); + translator.translateEntity(entity, id, options.language, (CountryEntity as EntityConstructor).$table_name); return entity ?? undefined; } @@ -110,7 +49,7 @@ export class CountryRepository { } public update(entity: CountryEntity): void { - const previousEntity = this.findById(entity.Id); + const previousEntity = this.findById(entity.Id as number); store.update((CountryEntity as EntityConstructor).$entity_name, entity); this.triggerEvent({ operation: "update", @@ -155,11 +94,12 @@ export class CountryRepository { }); } - public count(options?: CountryEntityOptions): number { - return store.count((CountryEntity as EntityConstructor).$entity_name, { 'conditions': [], 'limit': options?.$limit || 20, 'offset': options?.$offset || 0 }); + public count(options?: Options): number { + console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> count:" + JSON.stringify(options)); + return store.count((CountryEntity as EntityConstructor).$entity_name, options); } - private async triggerEvent(data: CountryEntityEvent | CountryUpdateEntityEvent) { + private async triggerEvent(data: CountryEntityEvent) { const triggerExtensions = await extensions.loadExtensionModules("codbex-countries-Settings-Country", ["trigger"]); triggerExtensions.forEach(triggerExtension => { try { diff --git a/codbex-countries/gen/codbex-countries/ui/Settings/Country/controller.js b/codbex-countries/gen/codbex-countries/ui/Settings/Country/controller.js index 9fe208d..a20190a 100644 --- a/codbex-countries/gen/codbex-countries/ui/Settings/Country/controller.js +++ b/codbex-countries/gen/codbex-countries/ui/Settings/Country/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts'; + EntityServiceProvider.baseUrl = '/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts'; }]) .controller('PageController', ($scope, EntityService, Extensions, LocaleService, ButtonStates) => { const Dialogs = new DialogHub(); @@ -31,7 +31,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer $scope.triggerPageAction = (action) => { Dialogs.showWindow({ hasHeader: true, - title: LocaleService.t(action.translation.key, action.translation.options, action.label), + title: LocaleService.t(action.translation.key, action.translation.options, action.label), path: action.path, maxWidth: action.maxWidth, maxHeight: action.maxHeight, @@ -42,7 +42,7 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer $scope.triggerEntityAction = (action) => { Dialogs.showWindow({ hasHeader: true, - title: LocaleService.t(action.translation.key, action.translation.options, action.label), + title: LocaleService.t(action.translation.key, action.translation.options, action.label), path: action.path, params: { id: $scope.entity.Id @@ -60,18 +60,24 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntitySer resetPagination(); //-----------------Events-------------------// - Dialogs.addMessageListener({ topic: 'codbex-countries.Settings.Country.entityCreated', handler: () => { - $scope.loadPage($scope.dataPage, $scope.filter); - }}); - Dialogs.addMessageListener({ topic: 'codbex-countries.Settings.Country.entityUpdated', handler: () => { - $scope.loadPage($scope.dataPage, $scope.filter); - }}); - Dialogs.addMessageListener({ topic: 'codbex-countries.Settings.Country.entitySearch', handler: (data) => { - resetPagination(); - $scope.filter = data.filter; - $scope.filterEntity = data.entity; - $scope.loadPage($scope.dataPage, $scope.filter); - }}); + Dialogs.addMessageListener({ + topic: 'codbex-countries.Settings.Country.entityCreated', handler: () => { + $scope.loadPage($scope.dataPage, $scope.filter); + } + }); + Dialogs.addMessageListener({ + topic: 'codbex-countries.Settings.Country.entityUpdated', handler: () => { + $scope.loadPage($scope.dataPage, $scope.filter); + } + }); + Dialogs.addMessageListener({ + topic: 'codbex-countries.Settings.Country.entitySearch', handler: (data) => { + resetPagination(); + $scope.filter = data.filter; + $scope.filterEntity = data.entity; + $scope.loadPage($scope.dataPage, $scope.filter); + } + }); //-----------------Events-------------------// $scope.loadPage = (pageNumber, filter) => { diff --git a/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-filter/controller.js b/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-filter/controller.js index 674363f..919fa88 100644 --- a/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-filter/controller.js +++ b/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-filter/controller.js @@ -21,41 +21,38 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale']).controlle let entity = $scope.entity; const filter = { $filter: { - equals: { - }, - notEquals: { - }, - contains: { - }, - greaterThan: { - }, - greaterThanOrEqual: { - }, - lessThan: { - }, - lessThanOrEqual: { - } + conditions: [], + sorts: [], + limit: 20, + offset: 0 }, }; if (entity.Id !== undefined) { - filter.$filter.equals.Id = entity.Id; + const condition = { propertyName: "Id", operator: "EQ", value: entity.Id }; + filter.$filter.conditions.push(condition); } if (entity.Name) { - filter.$filter.contains.Name = entity.Name; + const condition = { propertyName: "Name", operator: "EQ", value: entity.Name }; + filter.$filter.conditions.push(condition); } if (entity.Code2) { - filter.$filter.contains.Code2 = entity.Code2; + const condition = { propertyName: "Code2", operator: "EQ", value: entity.Code2 }; + filter.$filter.conditions.push(condition); } if (entity.Code3) { - filter.$filter.contains.Code3 = entity.Code3; + const condition = { propertyName: "Code3", operator: "EQ", value: entity.Code3 }; + filter.$filter.conditions.push(condition); } if (entity.Numeric) { - filter.$filter.contains.Numeric = entity.Numeric; + const condition = { propertyName: "Numeric", operator: "EQ", value: entity.Numeric }; + filter.$filter.conditions.push(condition); } - Dialogs.postMessage({ topic: 'codbex-countries.Settings.Country.entitySearch', data: { - entity: entity, - filter: filter - }}); + Dialogs.postMessage({ + topic: 'codbex-countries.Settings.Country.entitySearch', data: { + entity: entity, + filter: filter + } + }); $scope.cancel(); }; diff --git a/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-window/controller.js b/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-window/controller.js index 279998c..00774f6 100644 --- a/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-window/controller.js +++ b/codbex-countries/gen/codbex-countries/ui/Settings/Country/dialog-window/controller.js @@ -1,6 +1,6 @@ angular.module('page', ['blimpKit', 'platformView', 'platformLocale', 'EntityService']) .config(['EntityServiceProvider', (EntityServiceProvider) => { - EntityServiceProvider.baseUrl = '/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts'; + EntityServiceProvider.baseUrl = '/services/ts/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts'; }]) .controller('PageController', ($scope, $http, ViewParameters, LocaleService, EntityService) => { const Dialogs = new DialogHub(); From 2711ab233d92dd32be5ae25e3cbcbc9ee116b9f1 Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 13:33:47 +0300 Subject: [PATCH 18/24] cleanup --- .../gen/codbex-countries/data/Settings/CountryRepository.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts index bd5efba..89ef032 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts @@ -20,14 +20,12 @@ export interface CountryEntityEvent { export class CountryRepository { public findAll(options: Options = {}): CountryEntity[] { - console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> findAll:" + JSON.stringify(options)); let list = store.list((CountryEntity as EntityConstructor).$entity_name, options); translator.translateList(list, options.language, (CountryEntity as EntityConstructor).$table_name); return list; } public findById(id: number, options: Options = {}): CountryEntity | undefined { - console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> findById:" + JSON.stringify(options)); const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); translator.translateEntity(entity, id, options.language, (CountryEntity as EntityConstructor).$table_name); return entity ?? undefined; @@ -95,7 +93,6 @@ export class CountryRepository { } public count(options?: Options): number { - console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>> count:" + JSON.stringify(options)); return store.count((CountryEntity as EntityConstructor).$entity_name, options); } From 217c6622c7ddad028f81385e3cafa1469cc0001e Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 15:52:49 +0300 Subject: [PATCH 19/24] generic repository --- .../data/Settings/CountryRepository.ts | 174 +++++++++--------- .../data/Settings/Repository.ts | 120 ++++++++++++ 2 files changed, 210 insertions(+), 84 deletions(-) create mode 100644 codbex-countries/gen/codbex-countries/data/Settings/Repository.ts diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts index 89ef032..8fedcfc 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts @@ -1,102 +1,108 @@ import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -import { store, Options } from "sdk/db"; -import { translator } from "sdk/db"; -import { EntityConstructor } from "sdk/db"; +// import { store, Options } from "sdk/db"; +// import { translator } from "sdk/db"; +// import { EntityConstructor } from "sdk/db"; import { CountryEntity } from "./CountryEntity"; +import { Repository, EntityEvent } from "./Repository"; +import { store, translator, Options, EntityConstructor } from "sdk/db"; -export interface CountryEntityEvent { - readonly operation: 'create' | 'update' | 'delete'; - readonly table: string; - readonly entity: Partial; - readonly key: { - name: string; - column: string; - value: string | number; - } - readonly previousEntity?: CountryEntity; -} +// export interface CountryEntityEvent { +// readonly operation: 'create' | 'update' | 'delete'; +// readonly table: string; +// readonly entity: Partial; +// readonly key: { +// name: string; +// column: string; +// value: string | number; +// } +// readonly previousEntity?: CountryEntity; +// } -export class CountryRepository { +export class CountryRepository extends Repository { - public findAll(options: Options = {}): CountryEntity[] { - let list = store.list((CountryEntity as EntityConstructor).$entity_name, options); - translator.translateList(list, options.language, (CountryEntity as EntityConstructor).$table_name); - return list; + constructor() { + super((CountryEntity as EntityConstructor)); } - public findById(id: number, options: Options = {}): CountryEntity | undefined { - const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - translator.translateEntity(entity, id, options.language, (CountryEntity as EntityConstructor).$table_name); - return entity ?? undefined; - } + // public findAll(options: Options = {}): CountryEntity[] { + // let list = store.list((CountryEntity as EntityConstructor).$entity_name, options); + // translator.translateList(list, options.language, (CountryEntity as EntityConstructor).$table_name); + // return list; + // } - public create(entity: CountryEntity): string | number { - const id = store.save((CountryEntity as EntityConstructor).$entity_name, entity); - this.triggerEvent({ - operation: "create", - table: (CountryEntity as EntityConstructor).$table_name, - entity: entity, - key: { - name: (CountryEntity as EntityConstructor).$id_name, - column: (CountryEntity as EntityConstructor).$id_column, - value: id - } - }); - return id; - } + // public findById(id: number, options: Options = {}): CountryEntity | undefined { + // const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); + // translator.translateEntity(entity, id, options.language, (CountryEntity as EntityConstructor).$table_name); + // return entity ?? undefined; + // } - public update(entity: CountryEntity): void { - const previousEntity = this.findById(entity.Id as number); - store.update((CountryEntity as EntityConstructor).$entity_name, entity); - this.triggerEvent({ - operation: "update", - table: (CountryEntity as EntityConstructor).$table_name, - entity: entity, - previousEntity: previousEntity, - key: { - name: (CountryEntity as EntityConstructor).$id_name, - column: (CountryEntity as EntityConstructor).$id_column, - value: entity.Id - } - }); - } + // public create(entity: CountryEntity): string | number { + // const id = store.save((CountryEntity as EntityConstructor).$entity_name, entity); + // this.triggerEvent({ + // operation: "create", + // table: (CountryEntity as EntityConstructor).$table_name, + // entity: entity, + // key: { + // name: (CountryEntity as EntityConstructor).$id_name, + // column: (CountryEntity as EntityConstructor).$id_column, + // value: id + // } + // }); + // return id; + // } - public upsert(entity: CountryEntity): string | number { - const id = entity.Id; - if (!id) { - return store.save((CountryEntity as EntityConstructor).$entity_name, entity); - } + // public update(entity: CountryEntity): void { + // const previousEntity = this.findById(entity.Id as number); + // store.update((CountryEntity as EntityConstructor).$entity_name, entity); + // this.triggerEvent({ + // operation: "update", + // table: (CountryEntity as EntityConstructor).$table_name, + // entity: entity, + // previousEntity: previousEntity, + // key: { + // name: (CountryEntity as EntityConstructor).$id_name, + // column: (CountryEntity as EntityConstructor).$id_column, + // value: entity.Id as number | string + // } + // }); + // } - const existingEntity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - if (existingEntity) { - this.update(entity); - return id; - } else { - return store.save((CountryEntity as EntityConstructor).$entity_name, entity); - } - } + // public upsert(entity: CountryEntity): string | number { + // const id = entity.Id; + // if (!id) { + // return store.save((CountryEntity as EntityConstructor).$entity_name, entity); + // } - public deleteById(id: number): void { - const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - store.remove((CountryEntity as EntityConstructor).$entity_name, id); - this.triggerEvent({ - operation: "delete", - table: (CountryEntity as EntityConstructor).$table_name, - entity: entity, - key: { - name: (CountryEntity as EntityConstructor).$id_name, - column: (CountryEntity as EntityConstructor).$id_column, - value: id - } - }); - } + // const existingEntity = store.get((CountryEntity as EntityConstructor).$entity_name, id); + // if (existingEntity) { + // this.update(entity); + // return id; + // } else { + // return store.save((CountryEntity as EntityConstructor).$entity_name, entity); + // } + // } - public count(options?: Options): number { - return store.count((CountryEntity as EntityConstructor).$entity_name, options); - } + // public deleteById(id: number): void { + // const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); + // store.remove((CountryEntity as EntityConstructor).$entity_name, id); + // this.triggerEvent({ + // operation: "delete", + // table: (CountryEntity as EntityConstructor).$table_name, + // entity: entity, + // key: { + // name: (CountryEntity as EntityConstructor).$id_name, + // column: (CountryEntity as EntityConstructor).$id_column, + // value: id + // } + // }); + // } + + // public count(options?: Options): number { + // return store.count((CountryEntity as EntityConstructor).$entity_name, options); + // } - private async triggerEvent(data: CountryEntityEvent) { + protected async triggerEvent(data: EntityEvent) { const triggerExtensions = await extensions.loadExtensionModules("codbex-countries-Settings-Country", ["trigger"]); triggerExtensions.forEach(triggerExtension => { try { diff --git a/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts b/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts new file mode 100644 index 0000000..d4fbab1 --- /dev/null +++ b/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts @@ -0,0 +1,120 @@ +import { store, translator, Options, EntityConstructor } from "sdk/db"; + +export interface EntityEvent { + readonly operation: 'create' | 'update' | 'delete'; + readonly table: string; + readonly entity: Partial; + readonly key: { + name: string; + column: string; + value: string | number; + } + readonly previousEntity?: T; +} + +export abstract class Repository> { + + private entityConstructor: EntityConstructor; + + constructor(entityConstructor: EntityConstructor) { + this.entityConstructor = entityConstructor; + } + + protected getEntityName(): string { + return this.entityConstructor.$entity_name; + } + + protected getTableName(): string { + return this.entityConstructor.$table_name; + } + + protected getIdName(): string { + return this.entityConstructor.$id_name; + } + + protected getIdColumn(): string { + return this.entityConstructor.$id_column; + } + + public findAll(options: Options = {}): T[] { + let list = store.list(this.getEntityName(), options); + translator.translateList(list, options.language, this.getTableName()); + return list; + } + + public findById(id: number, options: Options = {}): T | undefined { + const entity = store.get(this.getEntityName(), id); + translator.translateEntity(entity, id, options.language, this.getTableName()); + return entity ?? undefined; + } + + public create(entity: T): string | number { + const id = store.save(this.getEntityName(), entity); + this.triggerEvent({ + operation: "create", + table: this.getTableName(), + entity: entity, + key: { + name: this.getIdName(), + column: this.getIdColumn(), + value: id + } + }); + return id; + } + + public update(entity: T): void { + const previousEntity = this.findById(entity[this.getIdName()]); + store.update(this.getEntityName(), entity); + this.triggerEvent({ + operation: "update", + table: this.getTableName(), + entity: entity, + previousEntity: previousEntity, + key: { + name: this.getIdName(), + column: this.getIdColumn(), + value: entity[this.getIdName()] + } + }); + } + + public upsert(entity: T): string | number { + const id = entity[this.getIdName()]; + if (!id) { + return store.save(this.getEntityName(), entity); + } + + const existingEntity = store.get(this.getEntityName(), id); + if (existingEntity) { + this.update(entity); + return id; + } else { + return store.save(this.getEntityName(), entity); + } + } + + public deleteById(id: number): void { + const entity = store.get(this.getEntityName(), id); + store.remove(this.getEntityName(), id); + this.triggerEvent({ + operation: "delete", + table: this.getTableName(), + entity: entity, + key: { + name: this.getIdName(), + column: this.getIdColumn(), + value: id + } + }); + } + + public count(options?: Options): number { + return store.count(this.getEntityName(), options); + } + + protected async triggerEvent(_data: EntityEvent) { + } + + +} \ No newline at end of file From 519ac2c49ea0083ac49644fb474f8e28f730c502 Mon Sep 17 00:00:00 2001 From: delchev Date: Thu, 16 Oct 2025 15:57:59 +0300 Subject: [PATCH 20/24] applied generic repository --- .../data/Settings/CountryRepository.ts | 95 +------------- .../data/Settings/Repository.ts | 120 ------------------ 2 files changed, 1 insertion(+), 214 deletions(-) delete mode 100644 codbex-countries/gen/codbex-countries/data/Settings/Repository.ts diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts index 8fedcfc..dcd4ca2 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryRepository.ts @@ -1,23 +1,7 @@ import { producer } from "sdk/messaging"; import { extensions } from "sdk/extensions"; -// import { store, Options } from "sdk/db"; -// import { translator } from "sdk/db"; -// import { EntityConstructor } from "sdk/db"; import { CountryEntity } from "./CountryEntity"; -import { Repository, EntityEvent } from "./Repository"; -import { store, translator, Options, EntityConstructor } from "sdk/db"; - -// export interface CountryEntityEvent { -// readonly operation: 'create' | 'update' | 'delete'; -// readonly table: string; -// readonly entity: Partial; -// readonly key: { -// name: string; -// column: string; -// value: string | number; -// } -// readonly previousEntity?: CountryEntity; -// } +import { Repository, EntityEvent, EntityConstructor } from "sdk/db"; export class CountryRepository extends Repository { @@ -25,83 +9,6 @@ export class CountryRepository extends Repository { super((CountryEntity as EntityConstructor)); } - // public findAll(options: Options = {}): CountryEntity[] { - // let list = store.list((CountryEntity as EntityConstructor).$entity_name, options); - // translator.translateList(list, options.language, (CountryEntity as EntityConstructor).$table_name); - // return list; - // } - - // public findById(id: number, options: Options = {}): CountryEntity | undefined { - // const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - // translator.translateEntity(entity, id, options.language, (CountryEntity as EntityConstructor).$table_name); - // return entity ?? undefined; - // } - - // public create(entity: CountryEntity): string | number { - // const id = store.save((CountryEntity as EntityConstructor).$entity_name, entity); - // this.triggerEvent({ - // operation: "create", - // table: (CountryEntity as EntityConstructor).$table_name, - // entity: entity, - // key: { - // name: (CountryEntity as EntityConstructor).$id_name, - // column: (CountryEntity as EntityConstructor).$id_column, - // value: id - // } - // }); - // return id; - // } - - // public update(entity: CountryEntity): void { - // const previousEntity = this.findById(entity.Id as number); - // store.update((CountryEntity as EntityConstructor).$entity_name, entity); - // this.triggerEvent({ - // operation: "update", - // table: (CountryEntity as EntityConstructor).$table_name, - // entity: entity, - // previousEntity: previousEntity, - // key: { - // name: (CountryEntity as EntityConstructor).$id_name, - // column: (CountryEntity as EntityConstructor).$id_column, - // value: entity.Id as number | string - // } - // }); - // } - - // public upsert(entity: CountryEntity): string | number { - // const id = entity.Id; - // if (!id) { - // return store.save((CountryEntity as EntityConstructor).$entity_name, entity); - // } - - // const existingEntity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - // if (existingEntity) { - // this.update(entity); - // return id; - // } else { - // return store.save((CountryEntity as EntityConstructor).$entity_name, entity); - // } - // } - - // public deleteById(id: number): void { - // const entity = store.get((CountryEntity as EntityConstructor).$entity_name, id); - // store.remove((CountryEntity as EntityConstructor).$entity_name, id); - // this.triggerEvent({ - // operation: "delete", - // table: (CountryEntity as EntityConstructor).$table_name, - // entity: entity, - // key: { - // name: (CountryEntity as EntityConstructor).$id_name, - // column: (CountryEntity as EntityConstructor).$id_column, - // value: id - // } - // }); - // } - - // public count(options?: Options): number { - // return store.count((CountryEntity as EntityConstructor).$entity_name, options); - // } - protected async triggerEvent(data: EntityEvent) { const triggerExtensions = await extensions.loadExtensionModules("codbex-countries-Settings-Country", ["trigger"]); triggerExtensions.forEach(triggerExtension => { diff --git a/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts b/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts deleted file mode 100644 index d4fbab1..0000000 --- a/codbex-countries/gen/codbex-countries/data/Settings/Repository.ts +++ /dev/null @@ -1,120 +0,0 @@ -import { store, translator, Options, EntityConstructor } from "sdk/db"; - -export interface EntityEvent { - readonly operation: 'create' | 'update' | 'delete'; - readonly table: string; - readonly entity: Partial; - readonly key: { - name: string; - column: string; - value: string | number; - } - readonly previousEntity?: T; -} - -export abstract class Repository> { - - private entityConstructor: EntityConstructor; - - constructor(entityConstructor: EntityConstructor) { - this.entityConstructor = entityConstructor; - } - - protected getEntityName(): string { - return this.entityConstructor.$entity_name; - } - - protected getTableName(): string { - return this.entityConstructor.$table_name; - } - - protected getIdName(): string { - return this.entityConstructor.$id_name; - } - - protected getIdColumn(): string { - return this.entityConstructor.$id_column; - } - - public findAll(options: Options = {}): T[] { - let list = store.list(this.getEntityName(), options); - translator.translateList(list, options.language, this.getTableName()); - return list; - } - - public findById(id: number, options: Options = {}): T | undefined { - const entity = store.get(this.getEntityName(), id); - translator.translateEntity(entity, id, options.language, this.getTableName()); - return entity ?? undefined; - } - - public create(entity: T): string | number { - const id = store.save(this.getEntityName(), entity); - this.triggerEvent({ - operation: "create", - table: this.getTableName(), - entity: entity, - key: { - name: this.getIdName(), - column: this.getIdColumn(), - value: id - } - }); - return id; - } - - public update(entity: T): void { - const previousEntity = this.findById(entity[this.getIdName()]); - store.update(this.getEntityName(), entity); - this.triggerEvent({ - operation: "update", - table: this.getTableName(), - entity: entity, - previousEntity: previousEntity, - key: { - name: this.getIdName(), - column: this.getIdColumn(), - value: entity[this.getIdName()] - } - }); - } - - public upsert(entity: T): string | number { - const id = entity[this.getIdName()]; - if (!id) { - return store.save(this.getEntityName(), entity); - } - - const existingEntity = store.get(this.getEntityName(), id); - if (existingEntity) { - this.update(entity); - return id; - } else { - return store.save(this.getEntityName(), entity); - } - } - - public deleteById(id: number): void { - const entity = store.get(this.getEntityName(), id); - store.remove(this.getEntityName(), id); - this.triggerEvent({ - operation: "delete", - table: this.getTableName(), - entity: entity, - key: { - name: this.getIdName(), - column: this.getIdColumn(), - value: id - } - }); - } - - public count(options?: Options): number { - return store.count(this.getEntityName(), options); - } - - protected async triggerEvent(_data: EntityEvent) { - } - - -} \ No newline at end of file From c60ede08f96bbd5e018e24f85fe983b1fbf88a57 Mon Sep 17 00:00:00 2001 From: delchev Date: Fri, 17 Oct 2025 23:36:57 +0300 Subject: [PATCH 21/24] openapi fixes --- .../codbex-countries/api/Settings/CountryController.ts | 4 ++-- .../gen/codbex-countries/codbex-countries.openapi | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index ac74af1..0e6d325 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -4,7 +4,7 @@ import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; import { HttpUtils } from "sdk/http/utils"; import { Options } from "sdk/db"; -import { CountryEntity } from "../../data/Settings/CountryEntity"; +import { CountryEntity } from "/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity"; import { CountryRepository } from "../../data/Settings/CountryRepository"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); @@ -79,7 +79,7 @@ class CountryController { } @Get("/:id") - public getById(_: any, ctx: any): CountryEntity { + public getById(id: number, ctx: any): CountryEntity[] { try { this.checkPermissions("read"); const id = parseInt(ctx.pathParameters.id); diff --git a/codbex-countries/gen/codbex-countries/codbex-countries.openapi b/codbex-countries/gen/codbex-countries/codbex-countries.openapi index bc6e00b..c658004 100644 --- a/codbex-countries/gen/codbex-countries/codbex-countries.openapi +++ b/codbex-countries/gen/codbex-countries/codbex-countries.openapi @@ -11,7 +11,7 @@ servers: tags: - name: Settings paths: - /codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts: + /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts: get: summary: List Country parameters: @@ -95,7 +95,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts/{id}: + /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/{id}: get: summary: Get Country by Id parameters: @@ -214,7 +214,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts/count: + /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/count: get: summary: Count the number of Country tags: @@ -330,7 +330,7 @@ paths: application/json: schema: $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryService.ts/search: + /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/search: post: summary: Search Country by CountryFilterOptions tags: From 360fe7d430fcfca0ec65001b5acce728e5d9a278 Mon Sep 17 00:00:00 2001 From: delchev Date: Sat, 18 Oct 2025 10:23:17 +0300 Subject: [PATCH 22/24] relative again --- .../gen/codbex-countries/api/Settings/CountryController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index 0e6d325..d31c96e 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -4,7 +4,7 @@ import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; import { HttpUtils } from "sdk/http/utils"; import { Options } from "sdk/db"; -import { CountryEntity } from "/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity"; +import { CountryEntity } from "../../data/Settings/CountryEntity"; import { CountryRepository } from "../../data/Settings/CountryRepository"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); From d6e7aadd57c3d0c8c736c98b7c773891c63b47c0 Mon Sep 17 00:00:00 2001 From: delchev Date: Sat, 18 Oct 2025 17:47:02 +0300 Subject: [PATCH 23/24] documentation decorators --- .../gen/codbex-countries/api/Settings/CountryController.ts | 5 ++++- .../gen/codbex-countries/data/Settings/CountryEntity.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts index d31c96e..f9b479a 100644 --- a/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts +++ b/codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http" +import { Controller, Get, Post, Put, Delete, Documentation, request, response } from "sdk/http" import { Extensions } from "sdk/extensions" import { user } from "sdk/security" import { ForbiddenError, ValidationError } from "sdk/http/errors"; @@ -10,11 +10,13 @@ import { CountryRepository } from "../../data/Settings/CountryRepository"; const validationModules = await Extensions.loadExtensionModules("codbex-countries-Settings-Country", ["validate"]); @Controller +@Documentation("My CountryController") class CountryController { private readonly repository = new CountryRepository(); @Get("/") + @Documentation("My Get All") public getAll(_: CountryEntity, ctx: any): CountryEntity[] { try { this.checkPermissions("read"); @@ -32,6 +34,7 @@ class CountryController { } @Post("/") + @Documentation("My Create") public create(entity: CountryEntity): CountryEntity { try { this.checkPermissions("write"); diff --git a/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts index 7a74d52..6835ffa 100644 --- a/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts +++ b/codbex-countries/gen/codbex-countries/data/Settings/CountryEntity.ts @@ -1,15 +1,18 @@ -import { Entity, Table, Id, Generated, Column } from "sdk/db"; +import { Entity, Table, Id, Generated, Column, Documentation } from "sdk/db"; @Entity("CountryEntity") @Table("CODBEX_COUNTRY") +@Documentation("My CountryEntity") export class CountryEntity { @Id() @Generated("sequence") @Column({ name: "COUNTRY_ID", type: "long" }) + @Documentation("My Id") public Id?: number; @Column({ name: "COUNTRY_NAME", type: "string" }) + @Documentation("My Name") public Name?: string; @Column({ name: "COUNTRY_CODE2", type: "string" }) From 9ae523673632d56a2d4658e57ba064b605862dbe Mon Sep 17 00:00:00 2001 From: delchev Date: Sat, 18 Oct 2025 17:47:47 +0300 Subject: [PATCH 24/24] delete openapi file as not needed anymore --- .../codbex-countries/codbex-countries.openapi | 699 ------------------ 1 file changed, 699 deletions(-) delete mode 100644 codbex-countries/gen/codbex-countries/codbex-countries.openapi diff --git a/codbex-countries/gen/codbex-countries/codbex-countries.openapi b/codbex-countries/gen/codbex-countries/codbex-countries.openapi deleted file mode 100644 index c658004..0000000 --- a/codbex-countries/gen/codbex-countries/codbex-countries.openapi +++ /dev/null @@ -1,699 +0,0 @@ -openapi: 3.0.3 -info: - title: Countries Management Module - OpenAPI 3.0 - version: 1.0.0 - description: Managing countries data -externalDocs: - description: Find out more about Eclipse Dirigible - url: https://dirigible.io -servers: - - url: /services/ts -tags: - - name: Settings -paths: - /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts: - get: - summary: List Country - parameters: - - in: query - name: $limit - description: The number of records to be returned _(both `$limit` and `$offset` should be provided)_. - required: false - allowReserved: true - schema: - type: integer - allowEmptyValue: true - - in: query - name: $offset - description: The number of records to skip _(both `$limit` and `$offset` should be provided)_. - required: false - allowReserved: true - schema: - type: integer - allowEmptyValue: true - tags: - - Settings - responses: - 200: - description: Successful Request - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Country' - 400: - description: Bad Request Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - post: - summary: Create Country - tags: - - Settings - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Country' - required: true - responses: - 201: - description: Successful Request - content: - application/json: - schema: - $ref: '#/components/schemas/Country' - 400: - description: Bad Request Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/{id}: - get: - summary: Get Country by Id - parameters: - - in: path - name: id - description: The Id of the entity. - required: true - schema: - type: string - tags: - - Settings - responses: - 200: - description: Successful Request - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Country' - 404: - description: Entity Not Found - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - put: - summary: Update Country by Id - parameters: - - in: path - name: id - description: The Id of the entity. - required: true - schema: - type: string - tags: - - Settings - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/Country' - required: true - responses: - 200: - description: Successful Request - content: - application/json: - schema: - $ref: '#/components/schemas/Country' - 400: - description: Bad Request Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 404: - description: Entity Not Found - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - delete: - summary: Delete Country by Id - parameters: - - in: path - name: id - description: The Id of the entity. - required: true - schema: - type: string - tags: - - Settings - responses: - 204: - description: Successful Request - 404: - description: Entity Not Found - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/count: - get: - summary: Count the number of Country - tags: - - Settings - responses: - 200: - description: Successful Request - content: - application/json: - schema: - type: integer - example: 100 - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - post: - summary: Count the number of Country by CountryFilterOptions - tags: - - Settings - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CountryFilterOptions' - examples: - countWithMultipleCriteria: - summary: Count with multiple criteria - value: - $filter: - notEquals: - Id: 33 - contains: - Name: "abcd" - Code2: "abcd" - Code3: "abcd" - Numeric: "abcd" - greaterThan: - Id: 0 - lessThanOrEqual: - Id: 100 - countWithEquals: - summary: Count with Equals - value: - $filter: - equals: - Id: 0 - countWithNotEquals: - summary: Count with Not Equals - value: - $filter: - notEquals: - Id: 0 - countWithContains: - summary: Count with Contains - value: - $filter: - contains: - Name: "abcd" - Code2: "abcd" - Code3: "abcd" - Numeric: "abcd" - countWithGreaterThan: - summary: Count with Greater Than - value: - $filter: - greaterThan: - Id: 0 - countWithGreaterThanOrEqual: - summary: Count with Greater Than Or Equal - value: - $filter: - greaterThanOrEqual: - Id: 0 - countWithLessThan: - summary: Count with Less Than - value: - $filter: - lessThan: - Id: 0 - countWithLessThanOrEqual: - summary: Count with Less Than Or Equal - value: - $filter: - lessThanOrEqual: - Id: 0 - required: true - responses: - 200: - description: Successful Request - content: - application/json: - schema: - type: integer - example: 100 - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - /codbex-countries/gen/codbex-countries/api/Settings/CountryController.ts/search: - post: - summary: Search Country by CountryFilterOptions - tags: - - Settings - requestBody: - content: - application/json: - schema: - $ref: '#/components/schemas/CountryFilterOptions' - examples: - searchWithMultipleCriteria: - summary: Search with multiple criteria - value: - $filter: - notEquals: - Id: 33 - contains: - Name: "abcd" - Code2: "abcd" - Code3: "abcd" - Numeric: "abcd" - greaterThan: - Id: 0 - lessThanOrEqual: - Id: 100 - searchWithEquals: - summary: Search with Equals - value: - $filter: - equals: - Id: 0 - searchWithNotEquals: - summary: Search with Not Equals - value: - $filter: - notEquals: - Id: 0 - searchWithContains: - summary: Search with Contains - value: - $filter: - contains: - Name: "abcd" - Code2: "abcd" - Code3: "abcd" - Numeric: "abcd" - searchWithGreaterThan: - summary: Search with Greater Than - value: - $filter: - greaterThan: - Id: 0 - searchWithGreaterThanOrEqual: - summary: Search with Greater Than Or Equal - value: - $filter: - greaterThanOrEqual: - Id: 0 - searchWithLessThan: - summary: Search with Less Than - value: - $filter: - lessThan: - Id: 0 - searchWithLessThanOrEqual: - summary: Search with Less Than Or Equal - value: - $filter: - lessThanOrEqual: - Id: 0 - required: true - responses: - 200: - description: Successful Request - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/Country' - 403: - description: Forbidden Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' - 500: - description: Internal Server Error - content: - application/json: - schema: - $ref: '#/components/schemas/Error' -components: - schemas: - Country: - type: object - required: - properties: - Id: - type: integer - format: int32 - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - CountryFilterOptions: - type: object - properties: - $filter: - type: object - properties: - equals: - type: object - properties: - Id: - oneOf: - - type: integer - format: int32 - - type: array - items: - type: integer - format: int32 - Name: - oneOf: - - type: string - minLength: 0 - maxLength: 255 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 255 - Code2: - oneOf: - - type: string - minLength: 0 - maxLength: 2 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 2 - Code3: - oneOf: - - type: string - minLength: 0 - maxLength: 3 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 3 - Numeric: - oneOf: - - type: string - minLength: 0 - maxLength: 3 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 3 - notEquals: - type: object - properties: - Id: - oneOf: - - type: integer - format: int32 - - type: array - items: - type: integer - format: int32 - Name: - oneOf: - - type: string - minLength: 0 - maxLength: 255 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 255 - Code2: - oneOf: - - type: string - minLength: 0 - maxLength: 2 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 2 - Code3: - oneOf: - - type: string - minLength: 0 - maxLength: 3 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 3 - Numeric: - oneOf: - - type: string - minLength: 0 - maxLength: 3 - - type: array - items: - type: string - format: double - minLength: 0 - maxLength: 3 - contains: - type: object - properties: - Id: - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - greaterThan: - type: object - properties: - Id: - type: integer - format: int32 - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - greaterThanOrEqual: - type: object - properties: - Id: - type: integer - format: int32 - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - lessThan: - type: object - properties: - Id: - type: integer - format: int32 - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - lessThanOrEqual: - type: object - properties: - Id: - type: integer - format: int32 - Name: - type: string - minLength: 0 - maxLength: 255 - Code2: - type: string - minLength: 0 - maxLength: 2 - Code3: - type: string - minLength: 0 - maxLength: 3 - Numeric: - type: string - minLength: 0 - maxLength: 3 - $select: - type: array - example: ["Id", "Name", "Code2", "Code3", "Numeric"] - items: - type: string - $sort: - - type: string - example: "Id,Name,Code2,Code3,Numeric" - $order: - type: string - enum: ["asc", "desc"] - example: "asc" - $offset: - type: integer - example: 0 - $limit: - type: integer - example: 10 - Error: - type: object - properties: - code: - type: integer - message: - type: string \ No newline at end of file