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
269 changes: 131 additions & 138 deletions codbex-payments/codbex-payments.edm

Large diffs are not rendered by default.

917 changes: 561 additions & 356 deletions codbex-payments/codbex-payments.gen

Large diffs are not rendered by default.

376 changes: 212 additions & 164 deletions codbex-payments/codbex-payments.model

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions codbex-payments/data/payment-types.csv

This file was deleted.

15 changes: 0 additions & 15 deletions codbex-payments/data/payments.csvim

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import { Controller, Get, Post, Put, Delete, Documentation, request, response } from '@aerokit/sdk/http'
import { HttpUtils } from "@aerokit/sdk/http/utils";
import { ValidationError } from '@aerokit/sdk/http/errors'
import { ForbiddenError } from '@aerokit/sdk/http/errors'
import { user } from '@aerokit/sdk/security'
import { Options } from '@aerokit/sdk/db'
import { Extensions } from "@aerokit/sdk/extensions"
import { Injected, Inject } from '@aerokit/sdk/component'
import { PaymentStatusRepository } from '../../data/Settings/PaymentStatusRepository'
import { PaymentStatusEntity } from '../../data/Settings/PaymentStatusEntity'
import { PaymentDirectionRepository } from '../../data/Settings/PaymentDirectionRepository'
import { PaymentDirectionEntity } from '../../data/Settings/PaymentDirectionEntity'

const validationModules = await Extensions.loadExtensionModules('codbex-payments-Settings-PaymentStatus', ['validate']);
const validationModules = await Extensions.loadExtensionModules('codbex-payments-Settings-PaymentDirection', ['validate']);

@Controller
@Documentation('codbex-payments - PaymentStatus Controller')
@Documentation('codbex-payments - PaymentDirection Controller')
@Injected()
class PaymentStatusController {
class PaymentDirectionController {

@Inject('PaymentStatusRepository')
private readonly repository!: PaymentStatusRepository;
@Inject('PaymentDirectionRepository')
private readonly repository!: PaymentDirectionRepository;

@Get('/')
@Documentation('Get All PaymentStatus')
public getAll(_: any, ctx: any): PaymentStatusEntity[] {
@Documentation('Get All PaymentDirection')
public getAll(_: any, ctx: any): PaymentDirectionEntity[] {
try {
this.checkPermissions('read');
const options: Options = {
limit: ctx.queryParameters["$limit"] ? parseInt(ctx.queryParameters["$limit"]) : 20,
offset: ctx.queryParameters["$offset"] ? parseInt(ctx.queryParameters["$offset"]) : 0,
Expand All @@ -38,13 +35,12 @@ class PaymentStatusController {
}

@Post('/')
@Documentation('Create PaymentStatus')
public create(entity: PaymentStatusEntity): PaymentStatusEntity {
@Documentation('Create PaymentDirection')
public create(entity: PaymentDirectionEntity): PaymentDirectionEntity {
try {
this.checkPermissions('write');
this.validateEntity(entity);
entity.Id = this.repository.create(entity) as any;
response.setHeader('Content-Location', '/services/ts/codbex-payments/gen/codbex-payments/api/Settings/PaymentStatusService.ts/' + entity.Id);
response.setHeader('Content-Location', '/services/ts/codbex-payments/gen/codbex-payments/api/Settings/PaymentDirectionService.ts/' + entity.Id);
response.setStatus(response.CREATED);
return entity;
} catch (error: any) {
Expand All @@ -54,10 +50,9 @@ class PaymentStatusController {
}

@Get('/count')
@Documentation('Count PaymentStatus')
@Documentation('Count PaymentDirection')
public count(): { count: number } {
try {
this.checkPermissions('read');
return { count: this.repository.count() };
} catch (error: any) {
this.handleError(error);
Expand All @@ -66,10 +61,9 @@ class PaymentStatusController {
}

@Post('/count')
@Documentation('Count PaymentStatus with filter')
@Documentation('Count PaymentDirection with filter')
public countWithFilter(filter: any): { count: number } {
try {
this.checkPermissions('read');
return { count: this.repository.count(filter) };
} catch (error: any) {
this.handleError(error);
Expand All @@ -78,10 +72,9 @@ class PaymentStatusController {
}

@Post('/search')
@Documentation('Search PaymentStatus')
public search(filter: any): PaymentStatusEntity[] {
@Documentation('Search PaymentDirection')
public search(filter: any): PaymentDirectionEntity[] {
try {
this.checkPermissions('read');
return this.repository.findAll(filter);
} catch (error: any) {
this.handleError(error);
Expand All @@ -90,10 +83,9 @@ class PaymentStatusController {
}

@Get('/:id')
@Documentation('Get PaymentStatus by id')
public getById(_: any, ctx: any): PaymentStatusEntity {
@Documentation('Get PaymentDirection by id')
public getById(_: any, ctx: any): PaymentDirectionEntity {
try {
this.checkPermissions('read');
const id = parseInt(ctx.pathParameters.id);
const options: Options = {
language: request.getLocale().slice(0, 2)
Expand All @@ -102,7 +94,7 @@ class PaymentStatusController {
if (entity) {
return entity;
} else {
HttpUtils.sendResponseNotFound('PaymentStatus not found');
HttpUtils.sendResponseNotFound('PaymentDirection not found');
}
} catch (error: any) {
this.handleError(error);
Expand All @@ -111,10 +103,9 @@ class PaymentStatusController {
}

@Put('/:id')
@Documentation('Update PaymentStatus by id')
public update(entity: PaymentStatusEntity, ctx: any): PaymentStatusEntity {
@Documentation('Update PaymentDirection by id')
public update(entity: PaymentDirectionEntity, ctx: any): PaymentDirectionEntity {
try {
this.checkPermissions('write');
const id = parseInt(ctx.pathParameters.id);
entity.Id = id;
this.validateEntity(entity);
Expand All @@ -127,17 +118,16 @@ class PaymentStatusController {
}

@Delete('/:id')
@Documentation('Delete PaymentStatus by id')
@Documentation('Delete PaymentDirection by id')
public deleteById(_: any, ctx: any): void {
try {
this.checkPermissions('write');
const id = parseInt(ctx.pathParameters.id);
const entity = this.repository.findById(id);
if (entity) {
this.repository.deleteById(id);
HttpUtils.sendResponseNoContent();
} else {
HttpUtils.sendResponseNotFound('PaymentStatus not found');
HttpUtils.sendResponseNotFound('PaymentDirection not found');
}
} catch (error: any) {
this.handleError(error);
Expand All @@ -154,16 +144,10 @@ class PaymentStatusController {
}
}

private checkPermissions(operationType: string) {
if (operationType === 'read' && !(user.isInRole('codbex-payments.Settings.PaymentStatusReadOnly') || user.isInRole('codbex-payments.Settings.PaymentStatusFullAccess'))) {
throw new ForbiddenError();
}
if (operationType === 'write' && !user.isInRole('codbex-payments.Settings.PaymentStatusFullAccess')) {
throw new ForbiddenError();
}
}

private validateEntity(entity: any): void {
if (entity.Name === null || entity.Name === undefined) {
throw new ValidationError(`The 'Name' property is required, provide a valid value`);
}
if (entity.Name?.length > 20) {
throw new ValidationError(`The 'Name' exceeds the maximum length of [20] characters`);
}
Expand Down

This file was deleted.

Loading