forked from mirrors/homebox
chore: developer cleanup (#300)
* new PR tasks * add homebox to know words * formatting * bump deps * generate db models * ts errors * drop id * fix accessor * drop unused time field * change CI * add expected error * add type check * resolve serveral type errors * hoise in CI
This commit is contained in:
parent
88f9ff90d4
commit
bd321af29f
142 changed files with 817 additions and 1200 deletions
|
@ -14,9 +14,7 @@ import (
|
|||
"github.com/hay-kot/homebox/backend/pkgs/pathlib"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidDocExtension = errors.New("invalid document extension")
|
||||
)
|
||||
var ErrInvalidDocExtension = errors.New("invalid document extension")
|
||||
|
||||
type DocumentRepository struct {
|
||||
db *ent.Client
|
||||
|
@ -74,7 +72,7 @@ func (r *DocumentRepository) Create(ctx context.Context, gid uuid.UUID, doc Docu
|
|||
path := r.path(gid, ext)
|
||||
|
||||
parent := filepath.Dir(path)
|
||||
err := os.MkdirAll(parent, 0755)
|
||||
err := os.MkdirAll(parent, 0o755)
|
||||
if err != nil {
|
||||
return DocumentOut{}, err
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ func useDocs(t *testing.T, num int) []DocumentOut {
|
|||
t.Cleanup(func() {
|
||||
for _, id := range ids {
|
||||
err := tRepos.Docs.Delete(context.Background(), id)
|
||||
|
||||
if err != nil {
|
||||
assert.True(t, ent.IsNotFound(err))
|
||||
}
|
||||
|
|
|
@ -76,9 +76,7 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
var (
|
||||
mapToGroupErr = mapTErrFunc(mapToGroup)
|
||||
)
|
||||
var mapToGroupErr = mapTErrFunc(mapToGroup)
|
||||
|
||||
func mapToGroup(g *ent.Group) Group {
|
||||
return Group{
|
||||
|
@ -90,9 +88,7 @@ func mapToGroup(g *ent.Group) Group {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation)
|
||||
)
|
||||
var mapToGroupInvitationErr = mapTErrFunc(mapToGroupInvitation)
|
||||
|
||||
func mapToGroupInvitation(g *ent.GroupInvitationToken) GroupInvitation {
|
||||
return GroupInvitation{
|
||||
|
@ -118,7 +114,6 @@ func (r *GroupRepository) StatsLocationsByPurchasePrice(ctx context.Context, GID
|
|||
return sql.As(sql.Sum(t.C(item.FieldPurchasePrice)), "total")
|
||||
}).
|
||||
Scan(ctx, &v)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -145,7 +140,6 @@ func (r *GroupRepository) StatsLabelsByPurchasePrice(ctx context.Context, GID uu
|
|||
return sql.As(sql.Sum(itemTable.C(item.FieldPurchasePrice)), "total")
|
||||
}).
|
||||
Scan(ctx, &v)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -283,7 +277,6 @@ func (r *GroupRepository) InvitationCreate(ctx context.Context, groupID uuid.UUI
|
|||
SetExpiresAt(invite.ExpiresAt).
|
||||
SetUses(invite.Uses).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return GroupInvitation{}, err
|
||||
}
|
||||
|
|
|
@ -68,7 +68,6 @@ func (r *AttachmentRepo) Update(ctx context.Context, itemId uuid.UUID, typ attac
|
|||
itm, err := r.db.Attachment.UpdateOneID(itemId).
|
||||
SetType(typ).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -58,7 +58,6 @@ func TestAttachmentRepo_Create(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
got, err := tRepos.Attachments.Create(tt.args.ctx, tt.args.itemId, tt.args.docId, tt.args.typ)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("AttachmentRepo.Create() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
@ -119,7 +118,6 @@ func TestAttachmentRepo_Update(t *testing.T) {
|
|||
assert.Equal(t, typ, updated.Type)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAttachmentRepo_Delete(t *testing.T) {
|
||||
|
|
|
@ -45,7 +45,7 @@ type (
|
|||
TextValue string `json:"textValue"`
|
||||
NumberValue int `json:"numberValue"`
|
||||
BooleanValue bool `json:"booleanValue"`
|
||||
TimeValue time.Time `json:"timeValue,omitempty"`
|
||||
// TimeValue time.Time `json:"timeValue,omitempty"`
|
||||
}
|
||||
|
||||
ItemCreate struct {
|
||||
|
@ -150,9 +150,7 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
var (
|
||||
mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary)
|
||||
)
|
||||
var mapItemsSummaryErr = mapTEachErrFunc(mapItemSummary)
|
||||
|
||||
func mapItemSummary(item *ent.Item) ItemSummary {
|
||||
var location *LocationSummary
|
||||
|
@ -200,7 +198,7 @@ func mapFields(fields []*ent.ItemField) []ItemField {
|
|||
TextValue: f.TextValue,
|
||||
NumberValue: f.NumberValue,
|
||||
BooleanValue: f.BooleanValue,
|
||||
TimeValue: f.TimeValue,
|
||||
// TimeValue: f.TimeValue,
|
||||
}
|
||||
}
|
||||
return result
|
||||
|
@ -371,7 +369,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
|
|||
}
|
||||
|
||||
count, err := qb.Count(ctx)
|
||||
|
||||
if err != nil {
|
||||
return PaginationResult[ItemSummary]{}, err
|
||||
}
|
||||
|
@ -387,7 +384,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
|
|||
}
|
||||
|
||||
items, err := mapItemsSummaryErr(qb.All(ctx))
|
||||
|
||||
if err != nil {
|
||||
return PaginationResult[ItemSummary]{}, err
|
||||
}
|
||||
|
@ -398,7 +394,6 @@ func (e *ItemsRepository) QueryByGroup(ctx context.Context, gid uuid.UUID, q Ite
|
|||
Total: count,
|
||||
Items: items,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
// QueryByAssetID returns items by asset ID. If the item does not exist, an error is returned.
|
||||
|
@ -422,7 +417,6 @@ func (e *ItemsRepository) QueryByAssetID(ctx context.Context, gid uuid.UUID, ass
|
|||
WithLocation().
|
||||
All(ctx),
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return PaginationResult[ItemSummary]{}, err
|
||||
}
|
||||
|
@ -441,6 +435,7 @@ func (e *ItemsRepository) GetAll(ctx context.Context, gid uuid.UUID) ([]ItemOut,
|
|||
Where(item.HasGroupWith(group.ID(gid))).
|
||||
WithLabel().
|
||||
WithLocation().
|
||||
WithFields().
|
||||
All(ctx))
|
||||
}
|
||||
|
||||
|
@ -590,7 +585,7 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
|
|||
SetTextValue(f.TextValue).
|
||||
SetNumberValue(f.NumberValue).
|
||||
SetBooleanValue(f.BooleanValue).
|
||||
SetTimeValue(f.TimeValue).
|
||||
// SetTimeValue(f.TimeValue).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
return ItemOut{}, err
|
||||
|
@ -606,8 +601,8 @@ func (e *ItemsRepository) UpdateByGroup(ctx context.Context, GID uuid.UUID, data
|
|||
SetName(f.Name).
|
||||
SetTextValue(f.TextValue).
|
||||
SetNumberValue(f.NumberValue).
|
||||
SetBooleanValue(f.BooleanValue).
|
||||
SetTimeValue(f.TimeValue)
|
||||
SetBooleanValue(f.BooleanValue)
|
||||
// SetTimeValue(f.TimeValue)
|
||||
|
||||
_, err = opt.Save(ctx)
|
||||
if err != nil {
|
||||
|
@ -651,7 +646,6 @@ func (e *ItemsRepository) GetAllCustomFieldValues(ctx context.Context, GID uuid.
|
|||
Unique(true).
|
||||
Select(itemfield.FieldTextValue).
|
||||
Scan(ctx, &values)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get field values: %w", err)
|
||||
}
|
||||
|
@ -679,7 +673,6 @@ func (e *ItemsRepository) GetAllCustomFieldNames(ctx context.Context, GID uuid.U
|
|||
Unique(true).
|
||||
Select(itemfield.FieldName).
|
||||
Scan(ctx, &fields)
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get custom fields: %w", err)
|
||||
}
|
||||
|
|
|
@ -125,7 +125,6 @@ func TestItemsRepository_Create(t *testing.T) {
|
|||
// Cleanup - Also deletes item
|
||||
err = tRepos.Locations.Delete(context.Background(), location.ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
}
|
||||
|
||||
func TestItemsRepository_Create_Location(t *testing.T) {
|
||||
|
@ -222,7 +221,6 @@ func TestItemsRepository_Update_Labels(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestItemsRepository_Update(t *testing.T) {
|
||||
|
|
|
@ -100,7 +100,6 @@ func (r *LabelRepository) Create(ctx context.Context, groupdId uuid.UUID, data L
|
|||
SetColor(data.Color).
|
||||
SetGroupID(groupdId).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return LabelOut{}, err
|
||||
}
|
||||
|
|
|
@ -62,9 +62,7 @@ func mapLocationSummary(location *ent.Location) LocationSummary {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
mapLocationOutErr = mapTErrFunc(mapLocationOut)
|
||||
)
|
||||
var mapLocationOutErr = mapTErrFunc(mapLocationOut)
|
||||
|
||||
func mapLocationOut(location *ent.Location) LocationOut {
|
||||
var parent *LocationSummary
|
||||
|
@ -181,7 +179,6 @@ func (r *LocationRepository) Create(ctx context.Context, GID uuid.UUID, data Loc
|
|||
}
|
||||
|
||||
location, err := q.Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return LocationOut{}, err
|
||||
}
|
||||
|
@ -322,7 +319,7 @@ func (lr *LocationRepository) Tree(ctx context.Context, GID uuid.UUID, tq TreeQu
|
|||
}
|
||||
|
||||
func ConvertLocationsToTree(locations []FlatTreeItem) []TreeItem {
|
||||
var locationMap = make(map[uuid.UUID]*TreeItem, len(locations))
|
||||
locationMap := make(map[uuid.UUID]*TreeItem, len(locations))
|
||||
|
||||
var rootIds []uuid.UUID
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ func useLocations(t *testing.T, len int) []LocationOut {
|
|||
t.Cleanup(func() {
|
||||
for _, loc := range out {
|
||||
err := tRepos.Locations.Delete(context.Background(), loc.ID)
|
||||
|
||||
if err != nil {
|
||||
assert.True(t, ent.IsNotFound(err))
|
||||
}
|
||||
|
@ -74,7 +73,6 @@ func TestLocationRepositoryGetAllWithCount(t *testing.T) {
|
|||
assert.Equal(t, 1, loc.ItemCount)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestLocationRepository_Create(t *testing.T) {
|
||||
|
|
|
@ -93,7 +93,6 @@ func (r *MaintenanceEntryRepository) GetLog(ctx context.Context, itemID uuid.UUI
|
|||
Where(maintenanceentry.ItemID(itemID)).
|
||||
Order(ent.Desc(maintenanceentry.FieldDate)).
|
||||
All(ctx)
|
||||
|
||||
if err != nil {
|
||||
return MaintenanceLog{}, err
|
||||
}
|
||||
|
|
|
@ -61,7 +61,6 @@ func TestMaintenanceEntryRepository_GetLog(t *testing.T) {
|
|||
|
||||
// Get the log for the item
|
||||
log, err := tRepos.MaintEntry.GetLog(context.Background(), item.ID)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get maintenance log: %v", err)
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ func (r *TokenRepository) GetUserFromToken(ctx context.Context, token []byte) (U
|
|||
QueryUser().
|
||||
WithGroup().
|
||||
Only(ctx)
|
||||
|
||||
if err != nil {
|
||||
return UserOut{}, err
|
||||
}
|
||||
|
@ -59,7 +58,6 @@ func (r *TokenRepository) GetRoles(ctx context.Context, token string) (*set.Set[
|
|||
authtokens.Token(tokenHash),
|
||||
)).
|
||||
All(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -80,7 +78,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT
|
|||
SetUserID(createToken.UserID).
|
||||
SetExpiresAt(createToken.ExpiresAt).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return UserAuthToken{}, err
|
||||
}
|
||||
|
@ -90,7 +87,6 @@ func (r *TokenRepository) CreateToken(ctx context.Context, createToken UserAuthT
|
|||
SetRole(role).
|
||||
SetToken(dbToken).
|
||||
Save(ctx)
|
||||
|
||||
if err != nil {
|
||||
return UserAuthToken{}, err
|
||||
}
|
||||
|
@ -115,7 +111,6 @@ func (r *TokenRepository) DeleteToken(ctx context.Context, token []byte) error {
|
|||
// PurgeExpiredTokens removes all expired tokens from the database
|
||||
func (r *TokenRepository) PurgeExpiredTokens(ctx context.Context) (int, error) {
|
||||
tokensDeleted, err := r.db.AuthTokens.Delete().Where(authtokens.ExpiresAtLTE(time.Now())).Exec(ctx)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -123,7 +123,6 @@ func (e *UserRepository) DeleteAll(ctx context.Context) error {
|
|||
|
||||
func (e *UserRepository) GetSuperusers(ctx context.Context) ([]*ent.User, error) {
|
||||
users, err := e.db.User.Query().Where(user.IsSuperuser(true)).All(ctx)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -139,7 +139,6 @@ func TestUserRepo_Delete(t *testing.T) {
|
|||
|
||||
allUsers, _ = tRepos.Users.GetAll(ctx)
|
||||
assert.Equal(t, len(allUsers), 0)
|
||||
|
||||
}
|
||||
|
||||
func TestUserRepo_GetSuperusers(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue