fixed error with duplicate stringify operation in api routes

Co-authored-by: Spacelord <Spacelord09@users.noreply.github.com>
This commit is contained in:
Sören Oesterwind 2023-07-09 18:07:28 +02:00
parent 58a2d2ad19
commit 5524f14e1a
11 changed files with 15 additions and 23 deletions

View File

@ -17,7 +17,7 @@ function get(req: Request, res: Response) {
}) })
.then((item) => { .then((item) => {
if (item) { if (item) {
res.status(200).json(JSON.stringify(item)); res.status(200).json(item);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Category does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Category does not exist' });
} }

View File

@ -43,7 +43,7 @@ async function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Item does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Item does not exist' });
} }
@ -117,7 +117,7 @@ async function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify({ total: itemCountFiltered, totalNotFiltered: itemCountNotFiltered, items: items })); res.status(200).json({ total: itemCountFiltered, totalNotFiltered: itemCountNotFiltered, items: items });
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Item does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'Item does not exist' });
} }

View File

@ -19,7 +19,7 @@ function get(req: Request, res: Response) {
} }
}) })
.then((items) => { .then((items) => {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
}) })
.catch((err) => { .catch((err) => {
log.db.error(err); log.db.error(err);

View File

@ -21,7 +21,7 @@ function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' });
} }
@ -40,7 +40,7 @@ function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageLocation does not exist' });
} }

View File

@ -23,7 +23,7 @@ function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageUnit does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageUnit does not exist' });
} }
@ -43,7 +43,7 @@ function get(req: Request, res: Response) {
}) })
.then((items) => { .then((items) => {
if (items) { if (items) {
res.status(200).json(JSON.stringify(items)); res.status(200).json(items);
} else { } else {
res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageUnit does not exist' }); res.status(410).json({ errorcode: 'NOT_EXISTING', error: 'storageUnit does not exist' });
} }

View File

@ -2,9 +2,7 @@ function getDataForEdit(name) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: `/api/v1/categories?name=${name}`, url: `/api/v1/categories?name=${name}`,
success: function (data) { success: function (result) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal // Get elements inside the editCategoryModal
const modal_categoryName = document.getElementById('editCategoryModalName'); const modal_categoryName = document.getElementById('editCategoryModalName');
const modal_categoryDescription = document.getElementById('editCategoryModalDescription'); const modal_categoryDescription = document.getElementById('editCategoryModalDescription');

View File

@ -19,8 +19,7 @@ function getDataForEdit(id) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: `/api/v1/items?id=${id}`, url: `/api/v1/items?id=${id}`,
success: function (data) { success: function (result) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal // Get elements inside the editCategoryModal
const modal_itemName = document.getElementById('itemModifyModalName'); const modal_itemName = document.getElementById('itemModifyModalName');

View File

@ -68,8 +68,7 @@ function getDataForEdit(id) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: `/api/v1/storageUnits?id=${id}`, url: `/api/v1/storageUnits?id=${id}`,
success: function (data) { success: function (result) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal // Get elements inside the editCategoryModal
const modal_unitName = document.getElementById('storageUnitModalName'); const modal_unitName = document.getElementById('storageUnitModalName');
@ -107,8 +106,7 @@ function getDataForEditLoc(id) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: `/api/v1/storageLocations?id=${id}`, url: `/api/v1/storageLocations?id=${id}`,
success: function (data) { success: function (result) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal // Get elements inside the editCategoryModal
const modal_locationName = document.getElementById('storageLocationModalName'); const modal_locationName = document.getElementById('storageLocationModalName');

View File

@ -108,8 +108,7 @@ function preFillDeleteModalNxt(id, route, name, requestIdent='id') {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: `/api/v1/${route}?${requestIdent}=${id}`, url: `/api/v1/${route}?${requestIdent}=${id}`,
success: function (data) { success: function (result) {
const result = JSON.parse(data);
// Get elements inside the editCategoryModal // Get elements inside the editCategoryModal
const modal_categoryName = document.getElementById('deleteNamePlaceholder'); const modal_categoryName = document.getElementById('deleteNamePlaceholder');

View File

@ -23,8 +23,7 @@ function loadPageData() {
}, 1000); }, 1000);
} }
function dataResponseHandler(res) { function dataResponseHandler(json) {
json = JSON.parse(res);
// console.log(json) // console.log(json)
totalNotFiltered = json.totalNotFiltered; totalNotFiltered = json.totalNotFiltered;
total = json.total; total = json.total;

View File

@ -67,8 +67,7 @@ function handleSearchChange(e) {
$.ajax({ $.ajax({
type: 'get', type: 'get',
url: url, url: url,
success: function (data) { success: function (result) {
let result = JSON.parse(data);
let htmlResult = "" let htmlResult = ""
result.forEach(element => { result.forEach(element => {
console.log(element); console.log(element);