feat: add invoice and alternative_componen management functionality
This commit is contained in:
78
internal/mapper/invoice_mapper.go
Normal file
78
internal/mapper/invoice_mapper.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package mapper
|
||||
|
||||
import (
|
||||
"wm-backend/internal/models"
|
||||
db "wm-backend/sqlc_gen"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
func timestampToTime(t pgtype.Timestamptz) string {
|
||||
if !t.Valid {
|
||||
return ""
|
||||
}
|
||||
return t.Time.String()
|
||||
}
|
||||
|
||||
func ToDomainInvoice(r db.Invoice) *models.Invoice {
|
||||
return &models.Invoice{
|
||||
ID: r.ID,
|
||||
InvoiceCode: r.InvoiceCode,
|
||||
Type: string(r.Type),
|
||||
Status: string(r.Status),
|
||||
InvoiceConfigID: r.InvoiceConfigID.Int64,
|
||||
TotalItems: r.TotalItems,
|
||||
Note: r.Note.String,
|
||||
CreatedBy: r.CreatedBy.String,
|
||||
ApprovedBy: r.ApprovedBy.String,
|
||||
CompletedAt: r.CompletedAt.Time,
|
||||
CreatedAt: r.CreatedAt,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
Metadata: r.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
func ToModelInvoice(r *models.Invoice) *db.CreateInvoiceParams {
|
||||
return &db.CreateInvoiceParams{
|
||||
Type: db.InvoiceTypeEnum(r.Type),
|
||||
Status: db.InvoiceStatusEnum(r.Status),
|
||||
InvoiceConfigID: pgtype.Int8{
|
||||
Int64: r.InvoiceConfigID,
|
||||
Valid: r.InvoiceConfigID != 0,
|
||||
},
|
||||
TotalItems: r.TotalItems,
|
||||
Note: pgtype.Text{
|
||||
String: r.Note,
|
||||
Valid: r.Note != "",
|
||||
},
|
||||
CreatedBy: pgtype.Text{
|
||||
String: r.CreatedBy,
|
||||
Valid: r.CreatedBy != "",
|
||||
},
|
||||
ApprovedBy: pgtype.Text{
|
||||
String: r.ApprovedBy,
|
||||
Valid: r.ApprovedBy != "",
|
||||
},
|
||||
CreatedAt: r.CreatedAt,
|
||||
Metadata: r.Metadata,
|
||||
}
|
||||
}
|
||||
|
||||
func ToUpdateModelInvoice(r *models.Invoice) *db.UpdateInvoiceParams {
|
||||
return &db.UpdateInvoiceParams{
|
||||
Type: db.InvoiceTypeEnum(r.Type),
|
||||
Status: db.InvoiceStatusEnum(r.Status),
|
||||
InvoiceConfigID: pgtype.Int8{
|
||||
Int64: r.InvoiceConfigID,
|
||||
Valid: r.InvoiceConfigID != 0,
|
||||
},
|
||||
TotalItems: r.TotalItems,
|
||||
Note: pgtype.Text{
|
||||
String: r.Note,
|
||||
Valid: r.Note != "",
|
||||
},
|
||||
Metadata: r.Metadata,
|
||||
UpdatedAt: r.UpdatedAt,
|
||||
ID: r.ID,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user