MG-2354 - Fix Bootstrap Config state change (#2356)

Signed-off-by: nyagamunene <stevenyaga2014@gmail.com>
This commit is contained in:
Steve Munene
2024-07-25 17:15:55 +03:00
committed by GitHub
parent 0e3dbf6e38
commit c3e7159cb7
+7 -4
View File
@@ -460,8 +460,10 @@ func (cr configRepository) RemoveChannel(ctx context.Context, id string) error {
}
func (cr configRepository) ConnectThing(ctx context.Context, channelID, thingID string) error {
q := `UPDATE configs SET state = $1 WHERE EXISTS (
SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
q := `UPDATE configs SET state = $1
WHERE magistrala_thing = $2
AND EXISTS (SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
result, err := cr.db.ExecContext(ctx, q, bootstrap.Active, thingID, channelID)
if err != nil {
return errors.Wrap(errConnectThing, err)
@@ -473,8 +475,9 @@ func (cr configRepository) ConnectThing(ctx context.Context, channelID, thingID
}
func (cr configRepository) DisconnectThing(ctx context.Context, channelID, thingID string) error {
q := `UPDATE configs SET state = $1 WHERE EXISTS (
SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
q := `UPDATE configs SET state = $1
WHERE magistrala_thing = $2
AND EXISTS (SELECT 1 FROM connections WHERE config_id = $2 AND channel_id = $3)`
_, err := cr.db.ExecContext(ctx, q, bootstrap.Inactive, thingID, channelID)
if err != nil {
return errors.Wrap(errDisconnectThing, err)