This commit is contained in:
2021-06-03 20:28:07 +00:00
parent 659e9ef291
commit 13958cf35d
7 changed files with 14 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ Here are all the API level error codes that can be returned by the API server:
| 2010 | Object not found - API could not find the object requested |
| 2020 | PUT Id mismatch - object Id does not match route Id |
| 2030 | Invalid operation - operation could not be completed, not valid, details in message property |
| 2040 | Not enough inventory - too few parts in stock to complete operation |
| 2200 | Validation error - general issue with object overall not valid, specifics in "details" property |
| 2201 | Validation error - Field is required but is empty or null |
| 2202 | Validation error - Field length exceeded. The limit will be returned in the `message` property of the validation error |

View File

@@ -19,6 +19,7 @@ namespace AyaNova.Biz
NOT_FOUND = 2010,
PUT_ID_MISMATCH = 2020,
INVALID_OPERATION = 2030,
INSUFFICIENT_INVENTORY = 2040,
VALIDATION_FAILED = 2200,
VALIDATION_REQUIRED = 2201,
VALIDATION_LENGTH_EXCEEDED = 2202,

View File

@@ -4,12 +4,9 @@ using Microsoft.EntityFrameworkCore;
using System.Linq;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Microsoft.EntityFrameworkCore.Storage;
namespace AyaNova.Biz
{
@@ -237,14 +234,18 @@ namespace AyaNova.Biz
return;
}
//Balance must not be negative
if (proposedObj.Balance < 0 )
//Balance must not be negative
//return the current balance
if (proposedObj.Balance < 0)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Balance", "Transaction would result in a negative balance (not enough inventory to process this transaction)");
string currentBalance = "0";
if (proposedObj.LastBalance != null)
currentBalance = proposedObj.LastBalance.ToString();
AddError(ApiErrorCode.INSUFFICIENT_INVENTORY, "Balance", $"available:{currentBalance}");
return;
}
//date is newer than last entry date?
if (proposedObj.LastEntryDate != null && proposedObj.LastEntryDate > proposedObj.EntryDate)
{

View File

@@ -1727,6 +1727,7 @@
"ErrorAPI2010": "Objekt nicht gefunden",
"ErrorAPI2020": "Die Routen-ID stimmt nicht mit der Objectid überein",
"ErrorAPI2030": "Ungültiger Vorgang",
"ErrorAPI2040": "Nicht genügend Inventar",
"ErrorAPI2200": "Validierungsfehler",
"ErrorAPI2201": "Fehlendes Pflichtfeld",
"ErrorAPI2202": "Maximale Länge überschritten",

View File

@@ -1727,6 +1727,7 @@
"ErrorAPI2010": "Object not found",
"ErrorAPI2020": "Route id doesn't match object id",
"ErrorAPI2030": "Invalid operation",
"ErrorAPI2040": "Not enough inventory",
"ErrorAPI2200": "Validation error",
"ErrorAPI2201": "Required field",
"ErrorAPI2202": "Length exceeded",

View File

@@ -1727,6 +1727,7 @@
"ErrorAPI2010": "Objeto no encontrado",
"ErrorAPI2020": "La ID de ruta no coincide con la ID de objeto",
"ErrorAPI2030": "Operación no válida",
"ErrorAPI2040": "No hay suficiente inventario",
"ErrorAPI2200": "Error de validación",
"ErrorAPI2201": "Campo requerido",
"ErrorAPI2202": "Longitud excedida",

View File

@@ -1727,6 +1727,7 @@
"ErrorAPI2010": "Objet introuvable",
"ErrorAPI2020": "L'ID de route ne correspond pas à l'ID d'objet",
"ErrorAPI2030": "Opération non valide",
"ErrorAPI2040": "Pas assez d'inventaire",
"ErrorAPI2200": "Erreur de validation",
"ErrorAPI2201": "Champ obligatoire",
"ErrorAPI2202": "Longueur maximale dépassée",