diff --git a/admin/app/translations.js b/admin/app/translations.js index 79c9b8ea..4c2844e1 100644 --- a/admin/app/translations.js +++ b/admin/app/translations.js @@ -852,6 +852,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', @@ -1851,6 +1852,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', @@ -2848,6 +2850,7 @@ function config($translateProvider) { METER_NAME_IS_ALREADY_IN_USE: 'Meter Name Is Already In Use', METER_NOT_FOUND: 'Meter Not Found', METER_OF_VARIABLE_NOT_FOUND: 'Meter Of Variable Not Found', + METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS: 'Meter Cannot Have More Than One ENERGY_VALUE Points', METER_POINT_RELATION_EXISTS: 'Meter Point Relation Exists', METER_POINT_RELATION_NOT_FOUND: 'Meter Point Relation Not Found', NOT_FOUND: 'Not Found', diff --git a/myems-api/core/meter.py b/myems-api/core/meter.py index a57ce560..17f4fbd2 100644 --- a/myems-api/core/meter.py +++ b/myems-api/core/meter.py @@ -913,7 +913,6 @@ class MeterPointCollection: description='API.INVALID_METER_ID') new_values = json.loads(raw_json) - cnx = mysql.connector.connect(**config.myems_system_db) cursor = cnx.cursor() @@ -925,15 +924,26 @@ class MeterPointCollection: cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.METER_NOT_FOUND') - - cursor.execute(" SELECT name " + cursor.execute(" SELECT name, object_type " " FROM tbl_points " " WHERE id = %s ", (new_values['data']['point_id'],)) - if cursor.fetchone() is None: + row = cursor.fetchone() + if row is None: cursor.close() cnx.disconnect() raise falcon.HTTPError(falcon.HTTP_404, title='API.NOT_FOUND', description='API.POINT_NOT_FOUND') + elif row[1] == 'ENERGY_VALUE': + query = (" SELECT p.id " + " FROM tbl_meters_points mp, tbl_points p " + " WHERE mp.meter_id = %s AND mp.point_id = p.id AND p.object_type = 'ENERGY_VALUE' ") + cursor.execute(query, (id_,)) + rows_points = cursor.fetchall() + if rows_points is not None and len(rows_points) > 0: + cursor.close() + cnx.disconnect() + raise falcon.HTTPError(falcon.HTTP_404, title='API.BAD_REQUEST', + description='API.METER_CANNOT_HAVE_MORE_THAN_ONE_ENERGY_VALUE_POINTS') query = (" SELECT id " " FROM tbl_meters_points "