deleteObjects method
Delete objects of this bot.
- {objects} is the list of objects that you want to delete. All objects must be the same type.
Implementation
Future<void> deleteObjects({
required List<BotObject> objects,
}) async {
try {
for (BotObject object in objects) {
if (object.id == null) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>()
.error
.add("[deleteObjects] : this object has no id");
return;
}
if (object.objectType.stringType !=
objects.first.objectType.stringType) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>()
.error
.add("[deleteObjects] : all objects must be the same type");
return;
}
object.belongToBot(_bot);
}
Uri url = Uri.parse(
"${GetIt.I<BotnoiClient>().endpoint}/developer/platform-api/object/${objects.first.objectType.stringType}");
http.Response response = await http.delete(
url,
headers: _getHeader,
body: jsonEncode({
"_id": objects.map((e) => e.id).toList(),
"bot_id": _bot.id,
}),
);
if (response.statusCode == 200 || response.statusCode == 204) {
GetIt.I<BotnoiClient>().finishedSuccessfully();
return;
}
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>()
.error
.add("[deleteObjects] : ${response.reasonPhrase ?? "ERROR"}");
} catch (e) {
GetIt.I<BotnoiClient>().finishedFailed();
GetIt.I<BotnoiClient>().error.add("[deleteObjects] : $e");
}
}