This in a pretty huge change. At a high level we're adding the concept of a 'contact' which is a person or organization that has zero or more contact methods (email, phone). This ended up cascading a number of changes, including critically to the publicreprt schema. In the end it seemed safer to get to the point where I'm confident we aren't using any of the old fields for storing reporter information (though I haven't deleted the columns yet) so I removed the code for defining those columns. At this point I think it's not possible for me to regenerate the bob schema due to the interdependencies between my various schemas, so the migration is well-and-truly happening.
42 lines
1.8 KiB
Go
42 lines
1.8 KiB
Go
package public
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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/public/model"
|
|
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/table"
|
|
)
|
|
|
|
func CommunicationInsert(ctx context.Context, txn db.Ex, m model.Communication) (model.Communication, error) {
|
|
statement := table.Communication.INSERT(table.Communication.MutableColumns).
|
|
MODEL(m).
|
|
RETURNING(table.Communication.AllColumns)
|
|
return db.ExecuteOneTx[model.Communication](ctx, txn, statement)
|
|
}
|
|
func CommunicationFromID(ctx context.Context, txn db.Ex, comm_id int64) (model.Communication, error) {
|
|
statement := table.Communication.SELECT(
|
|
table.Communication.AllColumns,
|
|
).FROM(table.Communication).
|
|
WHERE(table.Communication.ID.EQ(postgres.Int(comm_id)))
|
|
return db.ExecuteOneTx[model.Communication](ctx, txn, statement)
|
|
}
|
|
func CommunicationsFromOrganization(ctx context.Context, txn db.Ex, org_id int64) ([]model.Communication, error) {
|
|
statement := table.Communication.SELECT(
|
|
table.Communication.AllColumns,
|
|
).FROM(table.Communication).
|
|
WHERE(table.Communication.OrganizationID.EQ(postgres.Int(org_id))).
|
|
ORDER_BY(table.Communication.Created.DESC())
|
|
return db.ExecuteManyTx[model.Communication](ctx, txn, statement)
|
|
}
|
|
func CommunicationSetStatus(ctx context.Context, txn db.Ex, org_id int64, comm_id int64, status model.Communicationstatus) error {
|
|
statement := table.Communication.UPDATE().
|
|
SET(
|
|
table.Communication.Status.SET(postgres.NewEnumValue(status.String())),
|
|
).
|
|
WHERE(table.Communication.OrganizationID.EQ(postgres.Int(org_id)).AND(
|
|
table.Communication.ID.EQ(postgres.Int(comm_id))))
|
|
return db.ExecuteNoneTx(ctx, txn, statement)
|
|
}
|