mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 14:30:35 +07:00
fix: gofmt && little fixes
This commit is contained in:
@@ -12,7 +12,7 @@ type Field struct {
|
||||
Medatada []Metadata
|
||||
}
|
||||
|
||||
var PRIMITIVE_TYPES = map[string]string{
|
||||
var PrimitiveTypes = map[string]string{
|
||||
"date": "date",
|
||||
"number": "number",
|
||||
"string": "string",
|
||||
@@ -38,15 +38,15 @@ var PRIMITIVE_TYPES = map[string]string{
|
||||
func (f *Field) GenerateType() string {
|
||||
result := " type: {\n"
|
||||
|
||||
keys := make([]string, 0, len(PRIMITIVE_TYPES))
|
||||
for k := range PRIMITIVE_TYPES {
|
||||
keys := make([]string, 0, len(PrimitiveTypes))
|
||||
for k := range PrimitiveTypes {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
if slices.Contains(keys, strings.ToLower(f.Type)) {
|
||||
result += fmt.Sprintf(` primitive: "%s",`, PRIMITIVE_TYPES[strings.ToLower(f.Type)])
|
||||
result += fmt.Sprintf(` primitive: "%s",`, PrimitiveTypes[strings.ToLower(f.Type)])
|
||||
} else {
|
||||
var field string = "[]"
|
||||
var field = "[]"
|
||||
for _, meta := range f.Medatada {
|
||||
if meta.Name == "field" {
|
||||
if len(meta.Values) > 0 {
|
||||
|
||||
@@ -2,6 +2,7 @@ package generation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"nto_cli/utils"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -20,11 +21,11 @@ import type { IService } from "%s"
|
||||
|
||||
export default class %sService implements IService<%s> {
|
||||
async read(id: number) {
|
||||
return await GetById(id)
|
||||
return await GetById(id) as %s
|
||||
}
|
||||
|
||||
async readAll() {
|
||||
return await GetAll() as %s
|
||||
return await GetAll() as %s[]
|
||||
}
|
||||
|
||||
async create(item: %s) {
|
||||
@@ -33,16 +34,18 @@ export default class %sService implements IService<%s> {
|
||||
|
||||
async delete(id: number) {
|
||||
return await Delete(id)
|
||||
}
|
||||
}
|
||||
|
||||
async update(item: %s) {
|
||||
await Update(item)
|
||||
}
|
||||
|
||||
async count() {
|
||||
return await Count()
|
||||
}
|
||||
}
|
||||
`, utils.GetServiceBindPath(structName), structName, utils.GetServiceStructType(structName), utils.GetServiceType(), structName, structName, structName, structName))
|
||||
`, utils.GetServiceBindPath(structName), structName, utils.GetServiceStructType(structName), utils.GetServiceType(), structName, structName, structName, structName, structName, structName))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatalf("Failed to write to file: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func FindFrontendPath() string {
|
||||
currentPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
log.Fatalf("Failed to find path for frontend: %s", err)
|
||||
}
|
||||
|
||||
var dirs []string
|
||||
|
||||
@@ -29,7 +29,7 @@ func GetStructList(filePath string) []string {
|
||||
}
|
||||
|
||||
if s.Err() != nil {
|
||||
log.Fatalf("")
|
||||
log.Fatalf("Unexpected scanner error: %s", err)
|
||||
}
|
||||
|
||||
return structNames
|
||||
|
||||
@@ -18,4 +18,4 @@ func GetServiceStructType(structName string) string {
|
||||
func GetServiceType() string {
|
||||
path := "../types/service.type.ts"
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ package utils
|
||||
import "strings"
|
||||
|
||||
func SplitBySingleSpace(input string) []string {
|
||||
parts := strings.Split(strings.TrimSpace(input), " ")
|
||||
var result []string
|
||||
for _, p := range parts {
|
||||
if p != "" {
|
||||
result = append(result, p)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
parts := strings.Split(strings.TrimSpace(input), " ")
|
||||
var result []string
|
||||
for _, p := range parts {
|
||||
if p != "" {
|
||||
result = append(result, p)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user