added system logs
parent
0a0c0317d2
commit
7879f2c1c0
|
@ -5,8 +5,11 @@ import (
|
|||
"encoding/json"
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/database"
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -36,11 +39,30 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo
|
|||
|
||||
if code == 401 {
|
||||
log.Error().Msgf("invex not authorized, code: %d", code)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 29,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: "invex not authorized"},
|
||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||
},
|
||||
})
|
||||
|
||||
return code, nil, err
|
||||
}
|
||||
|
||||
if code == 404 {
|
||||
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 29,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: "invex stock item not found"},
|
||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||
},
|
||||
})
|
||||
return code, nil, err
|
||||
}
|
||||
|
||||
|
@ -71,12 +93,14 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu
|
|||
return c.SendStatus(fiber.StatusInternalServerError)
|
||||
}
|
||||
|
||||
userId := c.Locals("userId").(string)
|
||||
|
||||
newEquipmentDocumentation := structs.EquipmentDocumentation{
|
||||
Id: uuid.New().String(),
|
||||
StockItemId: body.StockItemId,
|
||||
Type: body.Type,
|
||||
Title: body.Title,
|
||||
CreatedByUserId: c.Locals("userId").(string),
|
||||
CreatedByUserId: userId,
|
||||
}
|
||||
|
||||
if err := os.Mkdir(config.Cfg.FolderPaths.PublicStatic+"/equipmentdocumentation/"+newEquipmentDocumentation.Id, os.ModePerm); err != nil {
|
||||
|
@ -132,6 +156,19 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu
|
|||
|
||||
database.DB.Create(&newEquipmentDocumentation)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 27,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "equipmentDocumentationId", Value: newEquipmentDocumentation.Id},
|
||||
{Type: "stockItemId", Value: newEquipmentDocumentation.StockItemId},
|
||||
{Type: "type", Value: strconv.Itoa(int(body.Type))},
|
||||
{Type: "title", Value: body.Title},
|
||||
{Type: "description", Value: string(marshaledNotes)},
|
||||
},
|
||||
})
|
||||
|
||||
return c.JSON(fiber.Map{"message": "ok"})
|
||||
}
|
||||
|
||||
|
@ -154,6 +191,16 @@ func GetEquipmentDocumentations(stockItemId string, c *fiber.Ctx) error {
|
|||
}
|
||||
}
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 30,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: c.Locals("userId").(string)},
|
||||
{Type: "stockItemId", Value: stockItemId},
|
||||
{Type: "statusCode", Value: strconv.Itoa(statusCode)},
|
||||
},
|
||||
})
|
||||
|
||||
return c.JSON(structs.EquipmentDocumentationResponse{
|
||||
Status: statusCode,
|
||||
Documentations: documentations})
|
||||
|
@ -254,6 +301,18 @@ func EditEquipmentDocumentation(c *fiber.Ctx, body structs.EditEquipmentDocument
|
|||
Notes: string(marshaledNotes),
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 28,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: c.Locals("userId").(string)},
|
||||
{Type: "equipmentDocumentationId", Value: body.DocumentationId},
|
||||
{Type: "title", Value: body.Title},
|
||||
{Type: "type", Value: strconv.Itoa(int(body.Type))},
|
||||
{Type: "description", Value: string(marshaledNotes)},
|
||||
},
|
||||
})
|
||||
|
||||
return c.JSON(fiber.Map{"message": "ok"})
|
||||
}
|
||||
|
||||
|
|
|
@ -349,5 +349,57 @@
|
|||
"message": "%userId% hat versucht einen seiner Api-Schlüssel zu verwenden, hat aber keine Berechtigung mehr dazu"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 27,
|
||||
"languages": [
|
||||
{
|
||||
"lang": "en",
|
||||
"message": "%userId% has created the equipment document %equipmentDocumentationId% for the stock item %stockItemId% with the title %title% type %type% description %description%"
|
||||
},
|
||||
{
|
||||
"lang": "de",
|
||||
"message": "%userId% hat die Gerätedokumentation %equipmentDocumentationId% für das Lagerobjekt %stockItemId% mit der Beschreibung %description% erstellt"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 28,
|
||||
"languages": [
|
||||
{
|
||||
"lang": "en",
|
||||
"message": "%userId% has updated the equipment document %equipmentDocumentationId% to title %title% type %type% and description %description%"
|
||||
},
|
||||
{
|
||||
"lang": "de",
|
||||
"message": "%userId% hat die Gerätedokumentation %equipmentDocumentationId% zu Titel %title% Typ %type% und Beschreibung %description% aktualisiert"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 29,
|
||||
"languages": [
|
||||
{
|
||||
"lang": "en",
|
||||
"message": "InvexApiRequestClient err: %error% statusCode: %statusCode%"
|
||||
},
|
||||
{
|
||||
"lang": "de",
|
||||
"message": "InvexApiRequestClient err: %error% statusCode: %statusCode%"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 30,
|
||||
"languages": [
|
||||
{
|
||||
"lang": "en",
|
||||
"message": "%userId% has viewed equipment documentation of the stock item %stockItemId%. StatusCode: %statusCode%"
|
||||
},
|
||||
{
|
||||
"lang": "de",
|
||||
"message": "%userId% hat die Gerätedokumentation des Lagerobjekts %stockItemId% angesehen. StatusCode: %statusCode%"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue