| @@ 177-251 (lines=75) @@ | ||
| 174 | "description": row[5]} |
|
| 175 | resp.text = json.dumps(result) |
|
| 176 | ||
| 177 | @staticmethod |
|
| 178 | @user_logger |
|
| 179 | def on_delete(req, resp, id_): |
|
| 180 | admin_control(req) |
|
| 181 | if not id_.isdigit() or int(id_) <= 0: |
|
| 182 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 183 | description='API.INVALID_CONTACT_ID') |
|
| 184 | ||
| 185 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 186 | cursor = cnx.cursor() |
|
| 187 | ||
| 188 | cursor.execute(" SELECT name " |
|
| 189 | " FROM tbl_contacts " |
|
| 190 | " WHERE id = %s ", (id_,)) |
|
| 191 | if cursor.fetchone() is None: |
|
| 192 | cursor.close() |
|
| 193 | cnx.close() |
|
| 194 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 195 | description='API.CONTACT_NOT_FOUND') |
|
| 196 | ||
| 197 | # check relation with shopfloors |
|
| 198 | cursor.execute(" SELECT id " |
|
| 199 | " FROM tbl_shopfloors " |
|
| 200 | " WHERE contact_id = %s ", (id_,)) |
|
| 201 | rows_shopfloors = cursor.fetchall() |
|
| 202 | if rows_shopfloors is not None and len(rows_shopfloors) > 0: |
|
| 203 | cursor.close() |
|
| 204 | cnx.close() |
|
| 205 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 206 | title='API.BAD_REQUEST', |
|
| 207 | description='API.THERE_IS_RELATION_WITH_SHOPFLOORS') |
|
| 208 | ||
| 209 | # check relation with spaces |
|
| 210 | cursor.execute(" SELECT id " |
|
| 211 | " FROM tbl_spaces " |
|
| 212 | " WHERE contact_id = %s ", (id_,)) |
|
| 213 | rows_spaces = cursor.fetchall() |
|
| 214 | if rows_spaces is not None and len(rows_spaces) > 0: |
|
| 215 | cursor.close() |
|
| 216 | cnx.close() |
|
| 217 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 218 | title='API.BAD_REQUEST', |
|
| 219 | description='API.THERE_IS_RELATION_WITH_SPACES') |
|
| 220 | ||
| 221 | # check relation with stores |
|
| 222 | cursor.execute(" SELECT id " |
|
| 223 | " FROM tbl_stores " |
|
| 224 | " WHERE contact_id = %s ", (id_,)) |
|
| 225 | rows_stores = cursor.fetchall() |
|
| 226 | if rows_stores is not None and len(rows_stores) > 0: |
|
| 227 | cursor.close() |
|
| 228 | cnx.close() |
|
| 229 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 230 | title='API.BAD_REQUEST', |
|
| 231 | description='API.THERE_IS_RELATION_WITH_STORES') |
|
| 232 | ||
| 233 | # check relation with tenants |
|
| 234 | cursor.execute(" SELECT id " |
|
| 235 | " FROM tbl_tenants " |
|
| 236 | " WHERE contact_id = %s ", (id_,)) |
|
| 237 | rows_tenants = cursor.fetchall() |
|
| 238 | if rows_tenants is not None and len(rows_tenants) > 0: |
|
| 239 | cursor.close() |
|
| 240 | cnx.close() |
|
| 241 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 242 | title='API.BAD_REQUEST', |
|
| 243 | description='API.THERE_IS_RELATION_WITH_TENANTS') |
|
| 244 | ||
| 245 | cursor.execute(" DELETE FROM tbl_contacts WHERE id = %s ", (id_,)) |
|
| 246 | cnx.commit() |
|
| 247 | ||
| 248 | cursor.close() |
|
| 249 | cnx.close() |
|
| 250 | ||
| 251 | resp.status = falcon.HTTP_204 |
|
| 252 | ||
| 253 | @staticmethod |
|
| 254 | @user_logger |
|
| @@ 142-219 (lines=78) @@ | ||
| 139 | "description": row[2]} |
|
| 140 | resp.text = json.dumps(meta_result) |
|
| 141 | ||
| 142 | @staticmethod |
|
| 143 | def on_delete(req, resp, id_): |
|
| 144 | admin_control(req) |
|
| 145 | if not id_.isdigit() or int(id_) <= 0: |
|
| 146 | raise falcon.HTTPError(status=falcon.HTTP_400, title='API.BAD_REQUEST', |
|
| 147 | description='API.INVALID_WORKING_CALENDAR_ID') |
|
| 148 | ||
| 149 | cnx = mysql.connector.connect(**config.myems_system_db) |
|
| 150 | cursor = cnx.cursor() |
|
| 151 | ||
| 152 | cursor.execute(" SELECT id " |
|
| 153 | " FROM tbl_working_calendars " |
|
| 154 | " WHERE id = %s ", (id_,)) |
|
| 155 | if cursor.fetchone() is None: |
|
| 156 | cursor.close() |
|
| 157 | cnx.close() |
|
| 158 | raise falcon.HTTPError(status=falcon.HTTP_404, title='API.NOT_FOUND', |
|
| 159 | description='API.WORKING_CALENDAR_NOT_FOUND') |
|
| 160 | ||
| 161 | # check relation with space |
|
| 162 | cursor.execute(" SELECT id FROM tbl_spaces_working_calendars" |
|
| 163 | " WHERE working_calendar_id = %s ", (id_,)) |
|
| 164 | ||
| 165 | rows_non_working_days = cursor.fetchall() |
|
| 166 | if rows_non_working_days is not None and len(rows_non_working_days) > 0: |
|
| 167 | cursor.close() |
|
| 168 | cnx.close() |
|
| 169 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 170 | title='API.BAD_REQUEST', |
|
| 171 | description='API.THERE_IS_RELATION_WITH_SPACES') |
|
| 172 | ||
| 173 | # check relation with tenants |
|
| 174 | cursor.execute(" SELECT tenant_id " |
|
| 175 | " FROM tbl_tenants_working_calendars " |
|
| 176 | " WHERE working_calendar_id = %s ", (id_,)) |
|
| 177 | rows_tenants = cursor.fetchall() |
|
| 178 | if rows_tenants is not None and len(rows_tenants) > 0: |
|
| 179 | cursor.close() |
|
| 180 | cnx.close() |
|
| 181 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 182 | title='API.BAD_REQUEST', |
|
| 183 | description='API.THERE_IS_RELATION_WITH_TENANTS') |
|
| 184 | ||
| 185 | # check relation with stores |
|
| 186 | cursor.execute(" SELECT store_id " |
|
| 187 | " FROM tbl_stores_working_calendars " |
|
| 188 | " WHERE working_calendar_id = %s ", (id_,)) |
|
| 189 | rows_stores = cursor.fetchall() |
|
| 190 | if rows_stores is not None and len(rows_stores) > 0: |
|
| 191 | cursor.close() |
|
| 192 | cnx.close() |
|
| 193 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 194 | title='API.BAD_REQUEST', |
|
| 195 | description='API.THERE_IS_RELATION_WITH_STORES') |
|
| 196 | ||
| 197 | # check relation with shopfloors |
|
| 198 | cursor.execute(" SELECT shopfloor_id " |
|
| 199 | " FROM tbl_shopfloors_working_calendars " |
|
| 200 | " WHERE working_calendar_id = %s ", (id_,)) |
|
| 201 | rows_shopfloors = cursor.fetchall() |
|
| 202 | if rows_shopfloors is not None and len(rows_shopfloors) > 0: |
|
| 203 | cursor.close() |
|
| 204 | cnx.close() |
|
| 205 | raise falcon.HTTPError(status=falcon.HTTP_400, |
|
| 206 | title='API.BAD_REQUEST', |
|
| 207 | description='API.THERE_IS_RELATION_WITH_SHOPFLOORS') |
|
| 208 | ||
| 209 | cursor.execute(" DELETE FROM tbl_working_calendars_non_working_days " |
|
| 210 | " WHERE working_calendar_id = %s ", (id_,)) |
|
| 211 | cnx.commit() |
|
| 212 | ||
| 213 | cursor.execute(" DELETE FROM tbl_working_calendars WHERE id = %s ", (id_,)) |
|
| 214 | cnx.commit() |
|
| 215 | ||
| 216 | cursor.close() |
|
| 217 | cnx.close() |
|
| 218 | ||
| 219 | resp.status = falcon.HTTP_204 |
|
| 220 | ||
| 221 | @staticmethod |
|
| 222 | def on_put(req, resp, id_): |
|