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
11 changes: 9 additions & 2 deletions codbex-products/codbex-products.edm

Large diffs are not rendered by default.

122 changes: 121 additions & 1 deletion codbex-products/codbex-products.gen
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"ProductPackaging",
"ProductImage",
"CampaignEntry",
"ProductLeaflet",
"Product-details",
"Product-details",
"Product-details",
Expand Down Expand Up @@ -1789,7 +1790,7 @@
"inputRule": ""
},
{
"dataLength": "2000",
"dataLength": "3000",
"dataName": "PRODUCTATTRIBUTE_VALUE",
"dataNullable": true,
"dataType": "VARCHAR",
Expand Down Expand Up @@ -3373,6 +3374,125 @@
"masterEntity": "Product",
"masterEntityId": "Product",
"hasDropdowns": true
},
{
"properties": [
{
"dataAutoIncrement": true,
"dataName": "PRODUCTLEAFLET_ID",
"dataNullable": true,
"dataPrimaryKey": true,
"dataType": "INTEGER",
"description": "",
"name": "Id",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "20",
"widgetSize": "",
"widgetType": "TEXTBOX",
"dataNotNull": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Id",
"widgetDropdownUrl": "",
"dataTypeJava": "int",
"dataTypeTypescript": "number",
"inputRule": ""
},
{
"dataName": "PRODUCTLEAFLET_TITLE",
"dataNullable": true,
"dataType": "INTEGER",
"description": "",
"name": "Title",
"relationshipCardinality": "1_n",
"relationshipName": "ProductLeaflet_Product",
"relationshipType": "COMPOSITION",
"tooltip": "",
"widgetDropDownKey": "Id",
"widgetDropDownValue": "Name",
"widgetIsMajor": false,
"widgetLength": "20",
"widgetSize": "",
"widgetType": "DROPDOWN",
"relationshipEntityName": "Product",
"relationshipEntityPerspectiveName": "Products",
"relationshipEntityPerspectiveLabel": "Entities",
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "Title",
"widgetDropdownUrl": "/services/ts/codbex-products/gen/codbex-products/api/Products/ProductService.ts",
"dataTypeJava": "int",
"dataTypeTypescript": "number",
"inputRule": ""
},
{
"dataLength": "500",
"dataName": "PRODUCTLEAFLET_LEAFLETLINK",
"dataNullable": true,
"dataType": "VARCHAR",
"description": "",
"name": "LeafletLink",
"tooltip": "",
"widgetIsMajor": true,
"widgetLength": "500",
"widgetSize": "",
"widgetType": "URL",
"dataNotNull": false,
"dataAutoIncrement": false,
"dataPrimaryKey": false,
"dataUnique": false,
"isRequiredProperty": false,
"isCalculatedProperty": false,
"widgetLabel": "LeafletLink",
"widgetDropdownUrl": "",
"dataTypeJava": "string",
"dataTypeTypescript": "string",
"minLength": 0,
"maxLength": 500,
"inputRule": ""
}
],
"caption": "Manage entity ProductLeaflet",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"CODBEX_PRODUCTLEAFLET\"",
"dataName": "PRODUCTLEAFLET",
"dataQuery": "",
"description": "Manage entity ProductLeaflet",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
"menuIndex": "100",
"menuKey": "productleaflet",
"menuLabel": "ProductLeaflet",
"multilingual": "false",
"name": "ProductLeaflet",
"perspectiveHeader": "",
"perspectiveIcon": "/services/web/resources/unicons/cube.svg",
"perspectiveLabel": "Products",
"perspectiveName": "Products",
"perspectiveNavId": "products-navigation-group",
"perspectiveOrder": "100",
"perspectiveRole": "",
"title": "ProductLeaflet",
"tooltip": "ProductLeaflet",
"type": "DEPENDENT",
"dataSource": "DefaultDB",
"referencedProjections": [],
"primaryKeys": [
"Id"
],
"primaryKeysString": "Id",
"masterEntity": "Product",
"masterEntityId": "Title",
"hasDropdowns": true
}
]
}
79 changes: 78 additions & 1 deletion codbex-products/codbex-products.model
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
"widgetType": "TEXTBOX"
},
{
"dataLength": "2000",
"dataLength": "3000",
"dataName": "PRODUCTATTRIBUTE_VALUE",
"dataNullable": "true",
"dataType": "VARCHAR",
Expand Down Expand Up @@ -1516,6 +1516,83 @@
"title": "CampaignEntry",
"tooltip": "CampaignEntry",
"type": "DEPENDENT"
},
{
"properties": [
{
"dataAutoIncrement": "true",
"dataName": "PRODUCTLEAFLET_ID",
"dataNullable": "true",
"dataPrimaryKey": "true",
"dataType": "INTEGER",
"description": "",
"name": "Id",
"tooltip": "",
"widgetIsMajor": "true",
"widgetLength": "20",
"widgetSize": "",
"widgetType": "TEXTBOX"
},
{
"dataName": "PRODUCTLEAFLET_TITLE",
"dataNullable": "true",
"dataType": "INTEGER",
"description": "",
"name": "Title",
"relationshipCardinality": "1_n",
"relationshipName": "ProductLeaflet_Product",
"relationshipType": "COMPOSITION",
"tooltip": "",
"widgetDropDownKey": "Id",
"widgetDropDownValue": "Name",
"widgetIsMajor": "true",
"widgetLength": "20",
"widgetSize": "",
"widgetType": "DROPDOWN",
"relationshipEntityName": "Product",
"relationshipEntityPerspectiveName": "Products",
"relationshipEntityPerspectiveLabel": "Entities"
},
{
"dataLength": "500",
"dataName": "PRODUCTLEAFLET_LEAFLETLINK",
"dataNullable": "true",
"dataType": "VARCHAR",
"description": "",
"name": "LeafletLink",
"tooltip": "",
"widgetIsMajor": "true",
"widgetLength": "500",
"widgetSize": "",
"widgetType": "URL"
}
],
"caption": "Manage entity ProductLeaflet",
"dataCount": "SELECT COUNT(*) AS COUNT FROM \"${tablePrefix}PRODUCTLEAFLET\"",
"dataName": "PRODUCTLEAFLET",
"dataQuery": "",
"description": "Manage entity ProductLeaflet",
"feedPassword": "YWRtaW4=",
"feedUsername": "YWRtaW4=",
"generateDefaultRoles": "false",
"generateReport": "false",
"icon": "/services/web/resources/unicons/file.svg",
"layoutType": "MANAGE_DETAILS",
"menuIndex": "100",
"menuKey": "productleaflet",
"menuLabel": "ProductLeaflet",
"multilingual": "false",
"name": "ProductLeaflet",
"perspectiveHeader": "",
"perspectiveIcon": "/services/web/resources/unicons/cube.svg",
"perspectiveLabel": "Products",
"perspectiveName": "Products",
"perspectiveNavId": "products-navigation-group",
"perspectiveOrder": "100",
"perspectiveRole": "",
"title": "ProductLeaflet",
"tooltip": "ProductLeaflet",
"type": "DEPENDENT"
}
],
"perspectives": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ class ProductAttributeService {
if (entity.Name?.length > 200) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [200] characters`);
}
if (entity.Value?.length > 2000) {
throw new ValidationError(`The 'Value' exceeds the maximum length of [2000] characters`);
if (entity.Value?.length > 3000) {
throw new ValidationError(`The 'Value' exceeds the maximum length of [3000] characters`);
}
for (const next of validationModules) {
next.validate(entity);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import { Controller, Get, Post, Put, Delete, request, response } from "sdk/http"
import { Extensions } from "sdk/extensions"
import { ProductLeafletRepository, ProductLeafletEntityOptions } from "../../dao/Products/ProductLeafletRepository";
import { ValidationError } from "../utils/ValidationError";
import { HttpUtils } from "../utils/HttpUtils";

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

@Controller
class ProductLeafletService {

private readonly repository = new ProductLeafletRepository();

@Get("/")
public getAll(_: any, ctx: any) {
try {
const options: ProductLeafletEntityOptions = {
$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;

if (Title !== undefined) {
options.$filter = {
equals: {
Title: Title
}
};
}

return this.repository.findAll(options);
} catch (error: any) {
this.handleError(error);
}
}

@Post("/")
public create(entity: any) {
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.setStatus(response.CREATED);
return entity;
} catch (error: any) {
this.handleError(error);
}
}

@Get("/count")
public count() {
try {
return { count: this.repository.count() };
} catch (error: any) {
this.handleError(error);
}
}

@Post("/count")
public countWithFilter(filter: any) {
try {
return { count: this.repository.count(filter) };
} catch (error: any) {
this.handleError(error);
}
}

@Post("/search")
public search(filter: any) {
try {
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
}
}

@Get("/:id")
public getById(_: any, ctx: any) {
try {
const id = parseInt(ctx.pathParameters.id);
const options: ProductLeafletEntityOptions = {
$language: request.getLocale().slice(0, 2)
};
const entity = this.repository.findById(id, options);
if (entity) {
return entity;
} else {
HttpUtils.sendResponseNotFound("ProductLeaflet not found");
}
} catch (error: any) {
this.handleError(error);
}
}

@Put("/:id")
public update(entity: any, ctx: any) {
try {
entity.Id = ctx.pathParameters.id;
this.validateEntity(entity);
this.repository.update(entity);
return entity;
} catch (error: any) {
this.handleError(error);
}
}

@Delete("/:id")
public deleteById(_: any, ctx: any) {
try {
const id = ctx.pathParameters.id;
const entity = this.repository.findById(id);
if (entity) {
this.repository.deleteById(id);
HttpUtils.sendResponseNoContent();
} else {
HttpUtils.sendResponseNotFound("ProductLeaflet not found");
}
} catch (error: any) {
this.handleError(error);
}
}

private handleError(error: any) {
if (error.name === "ForbiddenError") {
HttpUtils.sendForbiddenRequest(error.message);
} else if (error.name === "ValidationError") {
HttpUtils.sendResponseBadRequest(error.message);
} else {
HttpUtils.sendInternalServerError(error.message);
}
}

private validateEntity(entity: any): void {
if (entity.LeafletLink?.length > 500) {
throw new ValidationError(`The 'LeafletLink' exceeds the maximum length of [500] characters`);
}
for (const next of validationModules) {
next.validate(entity);
}
}

}
Loading