Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions codbex-products/codbex-products.edm

Large diffs are not rendered by default.

81 changes: 51 additions & 30 deletions codbex-products/codbex-products.gen
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"ProductPackaging",
"ProductImage",
"CampaignEntry",
"ProductLeaflet",
"ProductDocument",
"Product-details",
"Product-details",
"Product-details",
Expand Down Expand Up @@ -3379,7 +3379,7 @@
"properties": [
{
"dataAutoIncrement": true,
"dataName": "PRODUCTLEAFLET_ID",
"dataName": "PRODUCTDOCUMENT_ID",
"dataNullable": true,
"dataPrimaryKey": true,
"dataType": "INTEGER",
Expand All @@ -3401,21 +3401,19 @@
"inputRule": ""
},
{
"dataName": "PRODUCTLEAFLET_TITLE",
"dataName": "PRODUCTDOCUMENT_PRODUCT",
"dataNullable": true,
"dataType": "INTEGER",
"description": "",
"name": "Title",
"name": "Product",
"relationshipCardinality": "1_n",
"relationshipName": "ProductLeaflet_Product",
"relationshipName": "ProductDocument_Product",
"relationshipType": "COMPOSITION",
"tooltip": "",
"widgetDropDownKey": "Id",
"widgetDropDownValue": "Name",
"widgetIsMajor": false,
"widgetLength": "20",
"widgetSize": "",
"widgetType": "DROPDOWN",
"widgetType": "TEXTBOX",
"relationshipEntityName": "Product",
"relationshipEntityPerspectiveName": "Products",
"relationshipEntityPerspectiveLabel": "Entities",
Expand All @@ -3425,64 +3423,88 @@
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Title",
"widgetDropdownUrl": "/services/ts/codbex-products/gen/codbex-products/api/Products/ProductService.ts",
"widgetLabel": "Product",
"widgetDropdownUrl": "",
"dataTypeJava": "int",
"dataTypeTypescript": "number",
"inputRule": ""
},
{
"dataLength": "500",
"dataName": "PRODUCTLEAFLET_LEAFLETLINK",
"dataLength": "100",
"dataName": "PRODUCTDOCUMENT_NAME",
"dataNullable": true,
"dataType": "VARCHAR",
"description": "",
"name": "LeafletLink",
"isRequiredProperty": true,
"name": "Name",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "500",
"widgetLength": "100",
"widgetSize": "",
"widgetType": "TEXTBOX",
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isCalculatedProperty": false,
"widgetLabel": "Name",
"widgetDropdownUrl": "",
"dataTypeJava": "string",
"dataTypeTypescript": "string",
"minLength": 0,
"maxLength": 100,
"inputRule": ""
},
{
"dataLength": "300",
"dataName": "PRODUCTDOCUMENT_LINK",
"dataNullable": true,
"dataType": "VARCHAR",
"description": "",
"isRequiredProperty": true,
"name": "Link",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "300",
"widgetSize": "",
"widgetType": "URL",
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "LeafletLink",
"widgetLabel": "Link",
"widgetDropdownUrl": "",
"dataTypeJava": "string",
"dataTypeTypescript": "string",
"minLength": 0,
"maxLength": 500,
"maxLength": 300,
"inputRule": ""
}
],
"caption": "Manage entity ProductLeaflet",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"CODBEX_PRODUCTLEAFLET\"",
"dataName": "PRODUCTLEAFLET",
"caption": "Manage entity ProductDocument",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"CODBEX_PRODUCTDOCUMENT\"",
"dataName": "PRODUCTDOCUMENT",
"dataQuery": "",
"description": "Manage entity ProductLeaflet",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"description": "Manage entity ProductDocument",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
"menuIndex": "100",
"menuKey": "productleaflet",
"menuLabel": "ProductLeaflet",
"menuKey": "productdocument",
"menuLabel": "ProductDocument",
"multilingual": "false",
"name": "ProductLeaflet",
"name": "ProductDocument",
"perspectiveHeader": "",
"perspectiveIcon": "/services/web/resources/unicons/cube.svg",
"perspectiveLabel": "Products",
"perspectiveName": "Products",
"perspectiveNavId": "products-navigation-group",
"perspectiveOrder": "100",
"perspectiveRole": "",
"title": "ProductLeaflet",
"tooltip": "ProductLeaflet",
"title": "ProductDocument",
"tooltip": "ProductDocument",
"type": "DEPENDENT",
"dataSource": "DefaultDB",
"referencedProjections": [],
Expand All @@ -3491,8 +3513,7 @@
],
"primaryKeysString": "Id",
"masterEntity": "Product",
"masterEntityId": "Title",
"hasDropdowns": true
"masterEntityId": "Product"
}
]
}
55 changes: 33 additions & 22 deletions codbex-products/codbex-products.model
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@
"properties": [
{
"dataAutoIncrement": "true",
"dataName": "PRODUCTLEAFLET_ID",
"dataName": "PRODUCTDOCUMENT_ID",
"dataNullable": "true",
"dataPrimaryKey": "true",
"dataType": "INTEGER",
Expand All @@ -1534,64 +1534,75 @@
"widgetType": "TEXTBOX"
},
{
"dataName": "PRODUCTLEAFLET_TITLE",
"dataName": "PRODUCTDOCUMENT_PRODUCT",
"dataNullable": "true",
"dataType": "INTEGER",
"description": "",
"name": "Title",
"name": "Product",
"relationshipCardinality": "1_n",
"relationshipName": "ProductLeaflet_Product",
"relationshipName": "ProductDocument_Product",
"relationshipType": "COMPOSITION",
"tooltip": "",
"widgetDropDownKey": "Id",
"widgetDropDownValue": "Name",
"widgetIsMajor": "true",
"widgetLength": "20",
"widgetSize": "",
"widgetType": "DROPDOWN",
"widgetType": "TEXTBOX",
"relationshipEntityName": "Product",
"relationshipEntityPerspectiveName": "Products",
"relationshipEntityPerspectiveLabel": "Entities"
},
{
"dataLength": "500",
"dataName": "PRODUCTLEAFLET_LEAFLETLINK",
"dataLength": "100",
"dataName": "PRODUCTDOCUMENT_NAME",
"dataNullable": "true",
"dataType": "VARCHAR",
"description": "",
"name": "LeafletLink",
"isRequiredProperty": "true",
"name": "Name",
"tooltip": "",
"widgetIsMajor": "true",
"widgetLength": "500",
"widgetLength": "100",
"widgetSize": "",
"widgetType": "TEXTBOX"
},
{
"dataLength": "300",
"dataName": "PRODUCTDOCUMENT_LINK",
"dataNullable": "true",
"dataType": "VARCHAR",
"description": "",
"isRequiredProperty": "true",
"name": "Link",
"tooltip": "",
"widgetIsMajor": "true",
"widgetLength": "300",
"widgetSize": "",
"widgetType": "URL"
}
],
"caption": "Manage entity ProductLeaflet",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"${tablePrefix}PRODUCTLEAFLET\"",
"dataName": "PRODUCTLEAFLET",
"caption": "Manage entity ProductDocument",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"${tablePrefix}PRODUCTDOCUMENT\"",
"dataName": "PRODUCTDOCUMENT",
"dataQuery": "",
"description": "Manage entity ProductLeaflet",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"description": "Manage entity ProductDocument",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
"menuIndex": "100",
"menuKey": "productleaflet",
"menuLabel": "ProductLeaflet",
"menuKey": "productdocument",
"menuLabel": "ProductDocument",
"multilingual": "false",
"name": "ProductLeaflet",
"name": "ProductDocument",
"perspectiveHeader": "",
"perspectiveIcon": "/services/web/resources/unicons/cube.svg",
"perspectiveLabel": "Products",
"perspectiveName": "Products",
"perspectiveNavId": "products-navigation-group",
"perspectiveOrder": "100",
"perspectiveRole": "",
"title": "ProductLeaflet",
"tooltip": "ProductLeaflet",
"title": "ProductDocument",
"tooltip": "ProductDocument",
"type": "DEPENDENT"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { ProductLeafletRepository, ProductLeafletEntityOptions } from "../../dao/Products/ProductLeafletRepository";
import { ProductDocumentRepository, ProductDocumentEntityOptions } from "../../dao/Products/ProductDocumentRepository";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

const validationModules = await Extensions.loadExtensionModules("codbex-products-Products-ProductLeaflet", ["validate"]);
const validationModules = await Extensions.loadExtensionModules("codbex-products-Products-ProductDocument", ["validate"]);

@Controller
class ProductLeafletService {
class ProductDocumentService {

private readonly repository = new ProductLeafletRepository();
private readonly repository = new ProductDocumentRepository();

@Get("/")
public getAll(_: any, ctx: any) {
try {
const options: ProductLeafletEntityOptions = {
const options: ProductDocumentEntityOptions = {
$limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : undefined,
$offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : undefined,
$language: request.getLocale().slice(0, 2)
};

let Title = parseInt(ctx.queryParameters.Title);
Title = isNaN(Title) ? ctx.queryParameters.Title : Title;
let Product = parseInt(ctx.queryParameters.Product);
Product = isNaN(Product) ? ctx.queryParameters.Product : Product;

if (Title !== undefined) {
if (Product !== undefined) {
options.$filter = {
equals: {
Title: Title
Product: Product
}
};
}
Expand All @@ -42,7 +42,7 @@ class ProductLeafletService {
try {
this.validateEntity(entity);
entity.Id = this.repository.create(entity);
response.setHeader("Content-Location", "/services/ts/codbex-products/gen/codbex-products/api/Products/ProductLeafletService.ts/" + entity.Id);
response.setHeader("Content-Location", "/services/ts/codbex-products/gen/codbex-products/api/Products/ProductDocumentService.ts/" + entity.Id);
response.setStatus(response.CREATED);
return entity;
} catch (error: any) {
Expand Down Expand Up @@ -81,14 +81,14 @@ class ProductLeafletService {
public getById(_: any, ctx: any) {
try {
const id = parseInt(ctx.pathParameters.id);
const options: ProductLeafletEntityOptions = {
const options: ProductDocumentEntityOptions = {
$language: request.getLocale().slice(0, 2)
};
const entity = this.repository.findById(id, options);
if (entity) {
return entity;
} else {
HttpUtils.sendResponseNotFound("ProductLeaflet not found");
HttpUtils.sendResponseNotFound("ProductDocument not found");
}
} catch (error: any) {
this.handleError(error);
Expand Down Expand Up @@ -116,7 +116,7 @@ class ProductLeafletService {
this.repository.deleteById(id);
HttpUtils.sendResponseNoContent();
} else {
HttpUtils.sendResponseNotFound("ProductLeaflet not found");
HttpUtils.sendResponseNotFound("ProductDocument not found");
}
} catch (error: any) {
this.handleError(error);
Expand All @@ -134,8 +134,17 @@ class ProductLeafletService {
}

private validateEntity(entity: any): void {
if (entity.LeafletLink?.length > 500) {
throw new ValidationError(`The 'LeafletLink' exceeds the maximum length of [500] characters`);
if (entity.Name === null || entity.Name === undefined) {
throw new ValidationError(`The 'Name' property is required, provide a valid value`);
}
if (entity.Name?.length > 100) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [100] characters`);
}
if (entity.Link === null || entity.Link === undefined) {
throw new ValidationError(`The 'Link' property is required, provide a valid value`);
}
if (entity.Link?.length > 300) {
throw new ValidationError(`The 'Link' exceeds the maximum length of [300] characters`);
}
for (const next of validationModules) {
next.validate(entity);
Expand Down
Loading