This commit is contained in:
parent
8b203908a0
commit
725945d95c
22 changed files with 381 additions and 135 deletions
|
|
@ -35,13 +35,10 @@ func ContactUpdateName(ctx context.Context, txn db.Ex, id int64, name string) er
|
|||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
|
||||
/*
|
||||
func ContactsFromAddress(ctx context.Context, address string) ([]model.Contact, error) {
|
||||
func ContactsFromOrganizationID(ctx context.Context, txn db.Ex, org_id int64) ([]model.Contact, error) {
|
||||
statement := table.Contact.SELECT(
|
||||
table.Contact.AllColumns,
|
||||
).FROM(table.Contact).
|
||||
WHERE(table.Contact.Source.EQ(postgres.String(address)).OR(
|
||||
table.Contact.Destination.EQ(postgres.String(address))))
|
||||
return db.ExecuteMany[model.Contact](ctx, statement)
|
||||
WHERE(table.Contact.OrganizationID.EQ(postgres.Int(org_id)))
|
||||
return db.ExecuteManyTx[model.Contact](ctx, txn, statement)
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
52
db/query/comms/contact_email.go
Normal file
52
db/query/comms/contact_email.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
package comms
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
//"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/enum"
|
||||
"github.com/Gleipnir-Technology/jet/postgres"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
|
||||
)
|
||||
|
||||
func ContactEmailInsert(ctx context.Context, txn db.Ex, m model.ContactEmail) (model.ContactEmail, error) {
|
||||
statement := table.ContactEmail.INSERT(table.ContactEmail.MutableColumns).
|
||||
MODEL(m).
|
||||
RETURNING(table.ContactEmail.AllColumns)
|
||||
return db.ExecuteOneTx[model.ContactEmail](ctx, txn, statement)
|
||||
}
|
||||
|
||||
func ContactEmailFromAddress(ctx context.Context, txn db.Ex, address string) (model.ContactEmail, error) {
|
||||
statement := table.ContactEmail.SELECT(
|
||||
table.ContactEmail.AllColumns,
|
||||
).FROM(table.ContactEmail).
|
||||
WHERE(table.ContactEmail.Address.EQ(postgres.String(address)))
|
||||
return db.ExecuteOneTx[model.ContactEmail](ctx, txn, statement)
|
||||
}
|
||||
func ContactEmailByContactIDs(ctx context.Context, txn db.Ex, contact_ids []int64) (result map[int64][]model.ContactEmail, err error) {
|
||||
sql_ids := make([]postgres.Expression, len(contact_ids))
|
||||
for i, contact_id := range contact_ids {
|
||||
sql_ids[i] = postgres.Int(contact_id)
|
||||
}
|
||||
statement := table.ContactEmail.SELECT(
|
||||
table.ContactEmail.AllColumns,
|
||||
).FROM(table.ContactEmail).
|
||||
WHERE(table.ContactEmail.ContactID.IN(sql_ids...))
|
||||
rows, err := db.ExecuteManyTx[model.ContactEmail](ctx, txn, statement)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("query by contact IDs: %w", err)
|
||||
}
|
||||
for _, contact_id := range contact_ids {
|
||||
result[contact_id] = make([]model.ContactEmail, 0)
|
||||
}
|
||||
for _, row := range rows {
|
||||
id := int64(row.ContactID)
|
||||
cur := result[id]
|
||||
cur = append(cur, row)
|
||||
result[id] = cur
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package comms
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
//"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
|
|
@ -46,14 +47,27 @@ func ContactPhoneUpdateStopMessageID(ctx context.Context, txn db.Ex, e164 string
|
|||
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
|
||||
return db.ExecuteNoneTx(ctx, txn, statement)
|
||||
}
|
||||
|
||||
/*
|
||||
func ContactPhonesFromAddress(ctx context.Context, address string) ([]model.ContactPhone, error) {
|
||||
func ContactPhoneByContactIDs(ctx context.Context, txn db.Ex, contact_ids []int64) (result map[int64][]model.ContactPhone, err error) {
|
||||
sql_ids := make([]postgres.Expression, len(contact_ids))
|
||||
for i, contact_id := range contact_ids {
|
||||
sql_ids[i] = postgres.Int(contact_id)
|
||||
}
|
||||
statement := table.ContactPhone.SELECT(
|
||||
table.ContactPhone.AllColumns,
|
||||
).FROM(table.ContactPhone).
|
||||
WHERE(table.ContactPhone.Source.EQ(postgres.String(address)).OR(
|
||||
table.ContactPhone.Destination.EQ(postgres.String(address))))
|
||||
return db.ExecuteMany[model.ContactPhone](ctx, statement)
|
||||
WHERE(table.ContactPhone.ContactID.IN(sql_ids...))
|
||||
rows, err := db.ExecuteManyTx[model.ContactPhone](ctx, txn, statement)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("query by contact IDs: %w", err)
|
||||
}
|
||||
for _, contact_id := range contact_ids {
|
||||
result[contact_id] = make([]model.ContactPhone, 0)
|
||||
}
|
||||
for _, row := range rows {
|
||||
id := int64(row.ContactID)
|
||||
cur := result[id]
|
||||
cur = append(cur, row)
|
||||
result[id] = cur
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
70
db/query/public/mailer.go
Normal file
70
db/query/public/mailer.go
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package public
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/Gleipnir-Technology/jet/postgres"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
)
|
||||
|
||||
func mailerBaseQuery() postgres.SelectStatement {
|
||||
return table.ComplianceReportRequest.SELECT(
|
||||
table.Address.AllColumns,
|
||||
table.ComplianceReportRequest.AllColumns,
|
||||
).FROM(
|
||||
table.ComplianceReportRequest,
|
||||
).FROM(
|
||||
table.ComplianceReportRequest.INNER_JOIN(
|
||||
table.ComplianceReportRequestMailer,
|
||||
table.ComplianceReportRequestMailer.ComplianceReportRequestID.EQ(
|
||||
table.ComplianceReportRequest.ID),
|
||||
),
|
||||
).FROM(
|
||||
table.ComplianceReportRequest.INNER_JOIN(
|
||||
table.Lead,
|
||||
table.Lead.ID.EQ(
|
||||
table.ComplianceReportRequest.LeadID,
|
||||
),
|
||||
),
|
||||
).FROM(
|
||||
table.Lead.INNER_JOIN(
|
||||
table.Site,
|
||||
table.Site.ID.EQ(
|
||||
table.Lead.SiteID,
|
||||
),
|
||||
),
|
||||
).FROM(
|
||||
table.Site.INNER_JOIN(
|
||||
table.Address,
|
||||
table.Address.ID.EQ(
|
||||
table.Site.AddressID,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
func MailerFromPublicID(ctx context.Context, txn db.Ex, org_id int64, id int64) (*types.Mailer, error) {
|
||||
statement := mailerBaseQuery().WHERE(
|
||||
table.ComplianceReportRequest.ID.EQ(postgres.Int(id)).AND(
|
||||
table.Site.OrganizationID.EQ(postgres.Int(org_id))),
|
||||
)
|
||||
row, err := db.ExecuteOneTx[types.Mailer](ctx, txn, statement)
|
||||
if err != nil {
|
||||
if errors.Is(err, db.ErrNoRows) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("query: %w", err)
|
||||
}
|
||||
return &row, nil
|
||||
}
|
||||
func MailersFromOrganizationID(ctx context.Context, txn db.Ex, org_id int64, limit int64) ([]types.Mailer, error) {
|
||||
statement := mailerBaseQuery().WHERE(
|
||||
table.Site.OrganizationID.EQ(postgres.Int(org_id)),
|
||||
).ORDER_BY(
|
||||
table.ComplianceReportRequest.Created,
|
||||
).LIMIT(limit)
|
||||
return db.ExecuteManyTx[types.Mailer](ctx, txn, statement)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue