Add trust center access requests
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
3
pkg/coredata/migrations/20250820T091053Z.sql
Normal file
3
pkg/coredata/migrations/20250820T091053Z.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
ALTER TABLE trust_center_accesses ADD COLUMN active BOOLEAN NOT NULL DEFAULT TRUE;
|
||||
|
||||
ALTER TABLE trust_center_accesses ALTER COLUMN active DROP DEFAULT;
|
||||
@@ -33,6 +33,7 @@ type (
|
||||
TrustCenterID gid.GID `db:"trust_center_id"`
|
||||
Email string `db:"email"`
|
||||
Name string `db:"name"`
|
||||
Active bool `db:"active"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
@@ -62,6 +63,7 @@ SELECT
|
||||
trust_center_id,
|
||||
email,
|
||||
name,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
@@ -106,6 +108,7 @@ SELECT
|
||||
trust_center_id,
|
||||
email,
|
||||
name,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
@@ -152,6 +155,7 @@ INSERT INTO trust_center_accesses (
|
||||
trust_center_id,
|
||||
email,
|
||||
name,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
) VALUES (
|
||||
@@ -160,6 +164,7 @@ INSERT INTO trust_center_accesses (
|
||||
@trust_center_id,
|
||||
@email,
|
||||
@name,
|
||||
@active,
|
||||
@created_at,
|
||||
@updated_at
|
||||
)
|
||||
@@ -171,6 +176,7 @@ INSERT INTO trust_center_accesses (
|
||||
"trust_center_id": tca.TrustCenterID,
|
||||
"email": tca.Email,
|
||||
"name": tca.Name,
|
||||
"active": tca.Active,
|
||||
"created_at": tca.CreatedAt,
|
||||
"updated_at": tca.UpdatedAt,
|
||||
}
|
||||
@@ -183,6 +189,39 @@ INSERT INTO trust_center_accesses (
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tca *TrustCenterAccess) Update(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope Scoper,
|
||||
) error {
|
||||
q := `
|
||||
UPDATE trust_center_accesses SET
|
||||
name = @name,
|
||||
active = @active,
|
||||
updated_at = @updated_at
|
||||
WHERE
|
||||
%s
|
||||
AND id = @id
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||
|
||||
args := pgx.StrictNamedArgs{
|
||||
"id": tca.ID,
|
||||
"name": tca.Name,
|
||||
"active": tca.Active,
|
||||
"updated_at": tca.UpdatedAt,
|
||||
}
|
||||
maps.Copy(args, scope.SQLArguments())
|
||||
|
||||
_, err := conn.Exec(ctx, q, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot update trust center access: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tca *TrustCenterAccess) Delete(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
@@ -224,6 +263,7 @@ SELECT
|
||||
trust_center_id,
|
||||
email,
|
||||
name,
|
||||
active,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
|
||||
Reference in New Issue
Block a user